Hello Guys,
I came across a situation where I tried to throw a custom (more user-friendly) validation message when a required field in a service is missing. And the service definition was written with auto-attributes, something like this: <auto-attributes include="pk" mode="IN" optional="false"/> And I found myself stuck as I wanted to throw a custom message on a specific field among the PKs of the entity. I want you to suggest me a way to set validate message in such situation like we set on a single attribute like: <attribute name="shippingContactMechId" type="String" mode="IN" optional="false"> <type-validate> <fail-property resource="OrderUiLabels" property="checkhelper.select_shipping_destination"/> </type-validate> </attribute> IMO, we can think of doing something like the exclude field inside the auto-attributes to define the validate messages on the fields. <auto-attributes include="pk" mode="IN" optional="true"> <exclude field-name=""/> </auto-attributes> Something like this: <auto-attributes include="pk" mode="IN" optional="true"> <validation-message field-name="shippingContactMechId" resource="OrderUiLabels" property="checkhelper.select_shipping_destination"/> </auto-attributes> Please share your thoughts. :) -- Thanks and Regards, Devanshu Vyas |
Devanshu,
You can simply try to use override to override the default behavior of auto-attribute. For example; if you are working on PartyContanctMech and you want partyId and contactMechId should return custom error message if empty. Then use the following practice to do that; <auto-attributes include="pk" mode="IN" optional="false"/> <override name="partyId" optional="false"> <type-validate> <fail-message message="party id is required field." /> </type-validate> </override> Override tag intended to override the default behavior set in the auto-attributes. Simply using it suggested and implemented at service defintion level. HTH! Rishi Solanki Manager, Enterprise Software Development HotWax Systems Pvt. Ltd. Direct: +91-9893287847 http://www.hotwaxsystems.com On Thu, Oct 13, 2016 at 11:14 AM, Devanshu Vyas <[hidden email]> wrote: > Hello Guys, > > I came across a situation where I tried to throw a custom > (more user-friendly) validation message when a required field in a service > is missing. And the service definition was written with auto-attributes, > something like this: > > <auto-attributes include="pk" mode="IN" optional="false"/> > > And I found myself stuck as I wanted to throw a custom message on a > specific field among the PKs of the entity. > > I want you to suggest me a way to set validate message in such situation > like we set on a single attribute like: > > <attribute name="shippingContactMechId" type="String" mode="IN" > optional="false"> > <type-validate> > <fail-property resource="OrderUiLabels" > property="checkhelper.select_shipping_destination"/> > </type-validate> > </attribute> > > IMO, we can think of doing something like the exclude field inside the > auto-attributes to define the validate messages on the fields. > > <auto-attributes include="pk" mode="IN" optional="true"> > <exclude field-name=""/> > </auto-attributes> > > Something like this: > > <auto-attributes include="pk" mode="IN" optional="true"> > <validation-message field-name="shippingContactMechId" > resource="OrderUiLabels" > property="checkhelper.select_shipping_destination"/> > </auto-attributes> > > Please share your thoughts. :) > > -- > Thanks and Regards, > Devanshu Vyas > |
Applying same to your example;
<auto-attributes include="pk" mode="IN" optional="false"/> <override name="shippingContactMechId" optional="false"> <type-validate> <fail-property resource="OrderUiLabels" property="checkhelper.select_shipping_destination" /> </type-validate> </override> Rishi Solanki Manager, Enterprise Software Development HotWax Systems Pvt. Ltd. Direct: +91-9893287847 http://www.hotwaxsystems.com On Thu, Oct 13, 2016 at 1:46 PM, Rishi Solanki <[hidden email]> wrote: > Devanshu, > > You can simply try to use override to override the default behavior of > auto-attribute. For example; if you are working on PartyContanctMech and > you want partyId and contactMechId should return custom error message if > empty. Then use the following practice to do that; > > <auto-attributes include="pk" mode="IN" optional="false"/> > <override name="partyId" optional="false"> > <type-validate> > <fail-message message="party id is required field." /> > </type-validate> > </override> > > > Override tag intended to override the default behavior set in the > auto-attributes. Simply using it suggested and implemented at service > defintion level. > > > HTH! > > > > Rishi Solanki > Manager, Enterprise Software Development > HotWax Systems Pvt. Ltd. > Direct: +91-9893287847 > http://www.hotwaxsystems.com > > On Thu, Oct 13, 2016 at 11:14 AM, Devanshu Vyas <[hidden email] > > wrote: > >> Hello Guys, >> >> I came across a situation where I tried to throw a custom >> (more user-friendly) validation message when a required field in a service >> is missing. And the service definition was written with auto-attributes, >> something like this: >> >> <auto-attributes include="pk" mode="IN" optional="false"/> >> >> And I found myself stuck as I wanted to throw a custom message on a >> specific field among the PKs of the entity. >> >> I want you to suggest me a way to set validate message in such situation >> like we set on a single attribute like: >> >> <attribute name="shippingContactMechId" type="String" mode="IN" >> optional="false"> >> <type-validate> >> <fail-property resource="OrderUiLabels" >> property="checkhelper.select_shipping_destination"/> >> </type-validate> >> </attribute> >> >> IMO, we can think of doing something like the exclude field inside the >> auto-attributes to define the validate messages on the fields. >> >> <auto-attributes include="pk" mode="IN" optional="true"> >> <exclude field-name=""/> >> </auto-attributes> >> >> Something like this: >> >> <auto-attributes include="pk" mode="IN" optional="true"> >> <validation-message field-name="shippingContactMechId" >> resource="OrderUiLabels" >> property="checkhelper.select_shipping_destination"/> >> </auto-attributes> >> >> Please share your thoughts. :) >> >> -- >> Thanks and Regards, >> Devanshu Vyas >> > > |
I did think about this few years ago.
It's nice to put a dedicate message, and it's more powerfull to put a default rule to resolve the label with a pattern like : Default file for Service error message : component/config/ServiceErrorLabels.xml pattern : ServiceValidation.IN.${service-name}.${service-attribute} And maybe use a default pattern if not found for a dedicate service pattern : ServiceValidation.IN.common.${service-attribute} The advantage, keep service definition light, and offer the possibility to surcharge if needed with the <type-validate> <fail-property> Nicolas Le 13/10/2016 à 10:21, Rishi Solanki a écrit : > Applying same to your example; > > <auto-attributes include="pk" mode="IN" optional="false"/> > <override name="shippingContactMechId" optional="false"> > <type-validate> > <fail-property resource="OrderUiLabels" > property="checkhelper.select_shipping_destination" /> > </type-validate> > </override> > > > > > Rishi Solanki > Manager, Enterprise Software Development > HotWax Systems Pvt. Ltd. > Direct: +91-9893287847 > http://www.hotwaxsystems.com > > On Thu, Oct 13, 2016 at 1:46 PM, Rishi Solanki <[hidden email]> > wrote: > >> Devanshu, >> >> You can simply try to use override to override the default behavior of >> auto-attribute. For example; if you are working on PartyContanctMech and >> you want partyId and contactMechId should return custom error message if >> empty. Then use the following practice to do that; >> >> <auto-attributes include="pk" mode="IN" optional="false"/> >> <override name="partyId" optional="false"> >> <type-validate> >> <fail-message message="party id is required field." /> >> </type-validate> >> </override> >> >> >> Override tag intended to override the default behavior set in the >> auto-attributes. Simply using it suggested and implemented at service >> defintion level. >> >> >> HTH! >> >> >> >> Rishi Solanki >> Manager, Enterprise Software Development >> HotWax Systems Pvt. Ltd. >> Direct: +91-9893287847 >> http://www.hotwaxsystems.com >> >> On Thu, Oct 13, 2016 at 11:14 AM, Devanshu Vyas <[hidden email] >>> wrote: >>> Hello Guys, >>> >>> I came across a situation where I tried to throw a custom >>> (more user-friendly) validation message when a required field in a service >>> is missing. And the service definition was written with auto-attributes, >>> something like this: >>> >>> <auto-attributes include="pk" mode="IN" optional="false"/> >>> >>> And I found myself stuck as I wanted to throw a custom message on a >>> specific field among the PKs of the entity. >>> >>> I want you to suggest me a way to set validate message in such situation >>> like we set on a single attribute like: >>> >>> <attribute name="shippingContactMechId" type="String" mode="IN" >>> optional="false"> >>> <type-validate> >>> <fail-property resource="OrderUiLabels" >>> property="checkhelper.select_shipping_destination"/> >>> </type-validate> >>> </attribute> >>> >>> IMO, we can think of doing something like the exclude field inside the >>> auto-attributes to define the validate messages on the fields. >>> >>> <auto-attributes include="pk" mode="IN" optional="true"> >>> <exclude field-name=""/> >>> </auto-attributes> >>> >>> Something like this: >>> >>> <auto-attributes include="pk" mode="IN" optional="true"> >>> <validation-message field-name="shippingContactMechId" >>> resource="OrderUiLabels" >>> property="checkhelper.select_shipping_destination"/> >>> </auto-attributes> >>> >>> Please share your thoughts. :) >>> >>> -- >>> Thanks and Regards, >>> Devanshu Vyas >>> >> |
Free forum by Nabble | Edit this page |