Re: Validation using annotations with two execute methods are applied always
What about switching validateAnnotatedMethodOnly? This is going to be default in 2.5 probably https://struts.apache.org/docs/validations-annotation.html (mobile) 17 gru 2015 23:29 "JOSE L MARTINEZ-AVIAL" napisał(a): > Hello, > I'm using Struts 2.3.24.1. I have an action that has two execute > methods, and it is used by two actions, as follows: > > class="com.xxx.EasyEnrollmentCreateClient" method="createUserForClient"> > class="com.xxx.EasyEnrollmentCreateClient" method="createUserForParty"> > > > Each method has its own validations, defined by annotations at the method > level. > > @Validations(requiredStrings = { > @RequiredStringValidator(fieldName="idLanguage", key = > "validation-error.mandatory", messageParams={"getText('idLanguage')"}), > @RequiredStringValidator(fieldName="idCompany", key = > "validation-error.mandatory", messageParams={"getText('idCompany')"}), > @RequiredStringValidator(fieldName="idParty", key = > "validation-error.mandatory", messageParams={"getText('idParty')"})}) > public String createUserForParty() throws Exception { > > > > @Validations(requiredStrings = { > @RequiredStringValidator(fieldName="idLanguage", key = > "validation-error.mandatory", messageParams={"getText('idLanguage')"}), > @RequiredStringValidator(fieldName="idCompany", key = > "validation-error.mandatory", messageParams={"getText('idCompany')"}), > @RequiredStringValidator(fieldName="idCustomer", key = > "validation-error.mandatory", messageParams={"getText('idCustomer')"})}) > public String createUserForClient() throws Exception { > > > The issue is that both sets of validations are always executed, no matter > which action has been called. And I see in the response that when > idLanguage or idCompany are missing, the error appears twice, since it is > requited in both actions. > > What am I doing wrong? > > Regards > > JL >
Re: Validation using annotations with two execute methods are applied always
You might be better off splitting the two actions into two different classes. As far as I know that's the only way to address the issue. If you have shared logic or fields, you can always put those in a superclass. On Thu, Dec 17, 2015 at 3:28 PM, JOSE L MARTINEZ-AVIAL wrote: > Hello, > I'm using Struts 2.3.24.1. I have an action that has two execute > methods, and it is used by two actions, as follows: > > class="com.xxx.EasyEnrollmentCreateClient" method="createUserForClient"> > class="com.xxx.EasyEnrollmentCreateClient" method="createUserForParty"> > > > Each method has its own validations, defined by annotations at the method > level. > > @Validations(requiredStrings = { > @RequiredStringValidator(fieldName="idLanguage", key = > "validation-error.mandatory", messageParams={"getText('idLanguage')"}), > @RequiredStringValidator(fieldName="idCompany", key = > "validation-error.mandatory", messageParams={"getText('idCompany')"}), > @RequiredStringValidator(fieldName="idParty", key = > "validation-error.mandatory", messageParams={"getText('idParty')"})}) > public String createUserForParty() throws Exception { > > > > @Validations(requiredStrings = { > @RequiredStringValidator(fieldName="idLanguage", key = > "validation-error.mandatory", messageParams={"getText('idLanguage')"}), > @RequiredStringValidator(fieldName="idCompany", key = > "validation-error.mandatory", messageParams={"getText('idCompany')"}), > @RequiredStringValidator(fieldName="idCustomer", key = > "validation-error.mandatory", messageParams={"getText('idCustomer')"})}) > public String createUserForClient() throws Exception { > > > The issue is that both sets of validations are always executed, no matter > which action has been called. And I see in the response that when > idLanguage or idCompany are missing, the error appears twice, since it is > requited in both actions. > > What am I doing wrong? > > Regards > > JL > -- _ Adam Brin Director of Technology, Digital Antiquity 480.965.1278
Validation using annotations with two execute methods are applied always
Hello, I'm using Struts 2.3.24.1. I have an action that has two execute methods, and it is used by two actions, as follows: Each method has its own validations, defined by annotations at the method level. @Validations(requiredStrings = { @RequiredStringValidator(fieldName="idLanguage", key = "validation-error.mandatory", messageParams={"getText('idLanguage')"}), @RequiredStringValidator(fieldName="idCompany", key = "validation-error.mandatory", messageParams={"getText('idCompany')"}), @RequiredStringValidator(fieldName="idParty", key = "validation-error.mandatory", messageParams={"getText('idParty')"})}) public String createUserForParty() throws Exception { @Validations(requiredStrings = { @RequiredStringValidator(fieldName="idLanguage", key = "validation-error.mandatory", messageParams={"getText('idLanguage')"}), @RequiredStringValidator(fieldName="idCompany", key = "validation-error.mandatory", messageParams={"getText('idCompany')"}), @RequiredStringValidator(fieldName="idCustomer", key = "validation-error.mandatory", messageParams={"getText('idCustomer')"})}) public String createUserForClient() throws Exception { The issue is that both sets of validations are always executed, no matter which action has been called. And I see in the response that when idLanguage or idCompany are missing, the error appears twice, since it is requited in both actions. What am I doing wrong? Regards JL