Re: Struts 2 s:action tag doesn't render action errors if any are present
I don't know if this aplies to the issue here, but I once used this interceptor: interceptor-ref name=store param name=operationModeAUTOMATIC/param /interceptor-ref So the errors / messages will be passed through actions and redirections if not retrieved / showed. As far as I recall it worked to me pretty well. Alfredo Manuel Osorio Martinez, 28-10-2010 23:35: I am using defaultStack but I was reading the issue you just told me: https://issues.apache.org/jira/browse/WW-2869 And talks about invoking an action with the action tag an ChainingInterceptor but I don't know if the actionErrors from the source action will be copied. And by the way I am using the lastest version 2.2.1 -Mensaje original- De: Maurizio Cucchiara [mailto:maurizio.cucchi...@gmail.com] Enviado el: Thursday, October 28, 2010 5:25 PM Para: Struts Users Mailing List Asunto: Re: Struts 2 s:action tag doesn't render action errors if any are present Which interceptor do you mean? ChainingInterceptor? I meant implementing a new Interceptor from scratch. Although this issue are related to the chainInterceptor. What interceptor stack are you using? Does your request fire chainInterceptor? 2010/10/29 Alfredo Manuel Osorio Martinezalfredo.oso...@afirme.com: -- Maurizio Cucchiara - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Struts 2 s:action tag doesn't render action errors if any are present
Rendering a control (and repopulating its values) is a different thing than displaying validation error messages. IMO the way you're doing it isn't a particularly good idea; it would be better to render the control on the page, *possibly* using s:action to create the list of possible values (which I also really don't like), but not to render the control. Note that the text on that page states only that the control will be populated and rendered, which is true. I'm opposed to using the s:action tag as a solution to this problem in general; I don't think it's a good idea, and introduces more issues than it solves, particularly since better alternatives exist. Dave On Thu, Oct 28, 2010 at 1:35 PM, Alfredo Manuel Osorio Martinez alfredo.oso...@afirme.com wrote: For example I have the following: struts.xml: action name=personForm result/jsp/personForm.jsp/result /action action name=savePerson result/jsp/successSave.jsp/result result name=input/jsp/personForm.jsp/result /action action name=countries result/jsp/countries.jsp/result /action personForm.jsp: %@ taglib prefix=s uri=/struts-tags % s:form action=savePerson s:textfield name=firstName label=First Name / s:textfield name=lastName label=Last Name / s:action name=countries executeResult=true / s:submit / /s:form CountriesAction.java: public class CountriesAction extends ActionSupport { public String execute() { countries = getCountries(); return SUCCESS; } private MapString, String getCountries() { ... } private MapString, String countries; } countries.jsp: %@ taglib prefix=s uri=/struts-tags % s:select name=countryId label=Countries list=countries headerKey=-1 headerValue=Please select the country .../ SavePerson.action public class SavePerson extends ActionSupport { public void validate() { if (firstName == ) { addFieldError(firstName, First Name is required.); } if (lastName == ) { addFieldError(lastName, Last Name is required.); } if (countryId == -1) { addFieldError(countryId, Country is required.); } } public String execute() { //get the properties and save the person... return SUCCESS; } private String firstName; private String lastName; private String countryId; //corresponding setters and getters.. } When I submit the form and a validation error occurs for example let's say we didn't fill in any data so the input fields 'firstName' and 'lastName' will have their corresponding message next to them. But that's not the case for the country select list, even though there are action errors those won't display. I believe this happens because the parent action which is SavePerson is the one who added the errors (addFieldErrors) but when the other action Countries (the one that populates the list) is called then those errors are not available in that context because if I call hasErrors() within that Action it will be false so when the input gets rendered and check if there are any errors in order to render the message will call hasErrors and will return false so no errors messages will be rendered. This approach of calling another action just to render another input controls is one of the ways that Struts 2 FAQS tell to do that: http://struts.apache.org/2.2.1/docs/how-do-we-repopulate-controls-when-v alidation-fails.html http://struts.apache.org/2.2.1/docs/how-do-we-repopulate-controls-when- validation-fails.html So how can I make those controls on those actions render the action errors from its parent action. Any thoughts? Thank you in advance - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: Struts 2 s:action tag doesn't render action errors if any are present
Hello Dave and thank you for your quick response, 1. Let's say I want to keep doing the rendering of the control in that way. How would I solve the problem with the action error messages? 2. What I liked about having an action for rendering the controls it's that I can reuse them across different JSP pages. What other alternatives do you suggest me that can achieve the same level of modularity? Alfredo Osorio -Mensaje original- De: Dave Newton [mailto:davelnew...@gmail.com] Enviado el: Thursday, October 28, 2010 12:51 PM Para: Struts Users Mailing List Asunto: Re: Struts 2 s:action tag doesn't render action errors if any are present Rendering a control (and repopulating its values) is a different thing than displaying validation error messages. IMO the way you're doing it isn't a particularly good idea; it would be better to render the control on the page, *possibly* using s:action to create the list of possible values (which I also really don't like), but not to render the control. Note that the text on that page states only that the control will be populated and rendered, which is true. I'm opposed to using the s:action tag as a solution to this problem in general; I don't think it's a good idea, and introduces more issues than it solves, particularly since better alternatives exist. Dave On Thu, Oct 28, 2010 at 1:35 PM, Alfredo Manuel Osorio Martinez alfredo.oso...@afirme.com wrote: For example I have the following: struts.xml: action name=personForm result/jsp/personForm.jsp/result /action action name=savePerson result/jsp/successSave.jsp/result result name=input/jsp/personForm.jsp/result /action action name=countries result/jsp/countries.jsp/result /action personForm.jsp: %@ taglib prefix=s uri=/struts-tags % s:form action=savePerson s:textfield name=firstName label=First Name / s:textfield name=lastName label=Last Name / s:action name=countries executeResult=true / s:submit / /s:form CountriesAction.java: public class CountriesAction extends ActionSupport { public String execute() { countries = getCountries(); return SUCCESS; } private MapString, String getCountries() { ... } private MapString, String countries; } countries.jsp: %@ taglib prefix=s uri=/struts-tags % s:select name=countryId label=Countries list=countries headerKey=-1 headerValue=Please select the country .../ SavePerson.action public class SavePerson extends ActionSupport { public void validate() { if (firstName == ) { addFieldError(firstName, First Name is required.); } if (lastName == ) { addFieldError(lastName, Last Name is required.); } if (countryId == -1) { addFieldError(countryId, Country is required.); } } public String execute() { //get the properties and save the person... return SUCCESS; } private String firstName; private String lastName; private String countryId; //corresponding setters and getters.. } When I submit the form and a validation error occurs for example let's say we didn't fill in any data so the input fields 'firstName' and 'lastName' will have their corresponding message next to them. But that's not the case for the country select list, even though there are action errors those won't display. I believe this happens because the parent action which is SavePerson is the one who added the errors (addFieldErrors) but when the other action Countries (the one that populates the list) is called then those errors are not available in that context because if I call hasErrors() within that Action it will be false so when the input gets rendered and check if there are any errors in order to render the message will call hasErrors and will return false so no errors messages will be rendered. This approach of calling another action just to render another input controls is one of the ways that Struts 2 FAQS tell to do that: http://struts.apache.org/2.2.1/docs/how-do-we-repopulate-controls-when-v alidation-fails.html http://struts.apache.org/2.2.1/docs/how-do-we-repopulate-controls-when- validation-fails.html So how can I make those controls on those actions render the action errors from its parent action. Any thoughts? Thank you in advance - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Struts 2 s:action tag doesn't render action errors if any are present
You could try keeping them in the session, but that might involve tricky configuration sometimes--not sure. You're rendering a single control; I don't see that you're saving much... I still believe Preparable is a cleaner choice. You might be able to configure the action in such a way that the actionErrors property is filled off the value stack, but ew. Dave On Thursday, October 28, 2010, Alfredo Manuel Osorio Martinez alfredo.oso...@afirme.com wrote: Hello Dave and thank you for your quick response, 1. Let's say I want to keep doing the rendering of the control in that way. How would I solve the problem with the action error messages? 2. What I liked about having an action for rendering the controls it's that I can reuse them across different JSP pages. What other alternatives do you suggest me that can achieve the same level of modularity? Alfredo Osorio -Mensaje original- De: Dave Newton [mailto:davelnew...@gmail.com] Enviado el: Thursday, October 28, 2010 12:51 PM Para: Struts Users Mailing List Asunto: Re: Struts 2 s:action tag doesn't render action errors if any are present Rendering a control (and repopulating its values) is a different thing than displaying validation error messages. IMO the way you're doing it isn't a particularly good idea; it would be better to render the control on the page, *possibly* using s:action to create the list of possible values (which I also really don't like), but not to render the control. Note that the text on that page states only that the control will be populated and rendered, which is true. I'm opposed to using the s:action tag as a solution to this problem in general; I don't think it's a good idea, and introduces more issues than it solves, particularly since better alternatives exist. Dave On Thu, Oct 28, 2010 at 1:35 PM, Alfredo Manuel Osorio Martinez alfredo.oso...@afirme.com wrote: For example I have the following: struts.xml: action name=personForm result/jsp/personForm.jsp/result /action action name=savePerson result/jsp/successSave.jsp/result result name=input/jsp/personForm.jsp/result /action action name=countries result/jsp/countries.jsp/result /action personForm.jsp: %@ taglib prefix=s uri=/struts-tags % s:form action=savePerson s:textfield name=firstName label=First Name / s:textfield name=lastName label=Last Name / s:action name=countries executeResult=true / s:submit / /s:form CountriesAction.java: public class CountriesAction extends ActionSupport { public String execute() { countries = getCountries(); return SUCCESS; } private MapString, String getCountries() { ... } private MapString, String countries; } countries.jsp: %@ taglib prefix=s uri=/struts-tags % s:select name=countryId label=Countries list=countries headerKey=-1 headerValue=Please select the country .../ SavePerson.action public class SavePerson extends ActionSupport { public void validate() { if (firstName == ) { addFieldError(firstName, First Name is required.); } if (lastName == ) { addFieldError(lastName, Last Name is required.); } if (countryId == -1) { addFieldError(countryId, Country is required.); } } public String execute() { //get the properties and save the person... return SUCCESS; } private String firstName; private String lastName; private String countryId; - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: Struts 2 s:action tag doesn't render action errors if any are present
The problem is that the functionality it's already working except for the validation message part. Also the scenario was just an example it's not the real code from the application. In my application I have 4 controls Country, State, City and Postal Code and I need to use that four controls on different pages across the application in different JSPs. So for the sake of modularity I thought that using the action approach would work and it does except for the validation messages. You might be able to configure the action in such a way that the actionErrors property is filled off the value stack, but ew. I'd like to know how can I put the actionErrors property set to the parent action actionErrors in order to let the messages get rendered properly. Thanks Alfredo -Mensaje original- De: Dave Newton [mailto:davelnew...@gmail.com] Enviado el: Thursday, October 28, 2010 1:10 PM Para: Struts Users Mailing List Asunto: Re: Struts 2 s:action tag doesn't render action errors if any are present You could try keeping them in the session, but that might involve tricky configuration sometimes--not sure. You're rendering a single control; I don't see that you're saving much... I still believe Preparable is a cleaner choice. You might be able to configure the action in such a way that the actionErrors property is filled off the value stack, but ew. Dave On Thursday, October 28, 2010, Alfredo Manuel Osorio Martinez alfredo.oso...@afirme.com wrote: Hello Dave and thank you for your quick response, 1. Let's say I want to keep doing the rendering of the control in that way. How would I solve the problem with the action error messages? 2. What I liked about having an action for rendering the controls it's that I can reuse them across different JSP pages. What other alternatives do you suggest me that can achieve the same level of modularity? Alfredo Osorio -Mensaje original- De: Dave Newton [mailto:davelnew...@gmail.com] Enviado el: Thursday, October 28, 2010 12:51 PM Para: Struts Users Mailing List Asunto: Re: Struts 2 s:action tag doesn't render action errors if any are present Rendering a control (and repopulating its values) is a different thing than displaying validation error messages. IMO the way you're doing it isn't a particularly good idea; it would be better to render the control on the page, *possibly* using s:action to create the list of possible values (which I also really don't like), but not to render the control. Note that the text on that page states only that the control will be populated and rendered, which is true. I'm opposed to using the s:action tag as a solution to this problem in general; I don't think it's a good idea, and introduces more issues than it solves, particularly since better alternatives exist. Dave On Thu, Oct 28, 2010 at 1:35 PM, Alfredo Manuel Osorio Martinez alfredo.oso...@afirme.com wrote: For example I have the following: struts.xml: action name=personForm result/jsp/personForm.jsp/result /action action name=savePerson result/jsp/successSave.jsp/result result name=input/jsp/personForm.jsp/result /action action name=countries result/jsp/countries.jsp/result /action personForm.jsp: %@ taglib prefix=s uri=/struts-tags % s:form action=savePerson s:textfield name=firstName label=First Name / s:textfield name=lastName label=Last Name / s:action name=countries executeResult=true / s:submit / /s:form CountriesAction.java: public class CountriesAction extends ActionSupport { public String execute() { countries = getCountries(); return SUCCESS; } private MapString, String getCountries() { ... } private MapString, String countries; } countries.jsp: %@ taglib prefix=s uri=/struts-tags % s:select name=countryId label=Countries list=countries headerKey=-1 headerValue=Please select the country .../ SavePerson.action public class SavePerson extends ActionSupport { public void validate() { if (firstName == ) { addFieldError(firstName, First Name is required.); } if (lastName == ) { addFieldError(lastName, Last Name is required.); } if (countryId == -1) { addFieldError(countryId, Country is required.); } } public String execute() { //get the properties and save the person... return SUCCESS; } private String firstName; private String lastName; private String countryId; - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
Re: Struts 2 s:action tag doesn't render action errors if any are present
I totally agree with Dave: ParameterInterceptor is the better choice. BTW, I'm not sure it fits your needs but you should take a look at this issue https://issues.apache.org/jira/browse/WW-2869 and https://issues.apache.org/jira/browse/WW-3488 (especially where Lukasz talked about copyErrors and copyMessages flags) Anyway, you should be able to copy actionError through actions simply by implementing an Interceptor. -- Maurizio Cucchiara - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: Struts 2 s:action tag doesn't render action errors if any are present
Which interceptor do you mean? ChainingInterceptor? Alfredo Osorio -Mensaje original- De: Maurizio Cucchiara [mailto:maurizio.cucchi...@gmail.com] Enviado el: Thursday, October 28, 2010 4:25 PM Para: Struts Users Mailing List Asunto: Re: Struts 2 s:action tag doesn't render action errors if any are present I totally agree with Dave: ParameterInterceptor is the better choice. BTW, I'm not sure it fits your needs but you should take a look at this issue https://issues.apache.org/jira/browse/WW-2869 and https://issues.apache.org/jira/browse/WW-3488 (especially where Lukasz talked about copyErrors and copyMessages flags) Anyway, you should be able to copy actionError through actions simply by implementing an Interceptor. -- Maurizio Cucchiara - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Struts 2 s:action tag doesn't render action errors if any are present
Which interceptor do you mean? ChainingInterceptor? I meant implementing a new Interceptor from scratch. Although this issue are related to the chainInterceptor. What interceptor stack are you using? Does your request fire chainInterceptor? 2010/10/29 Alfredo Manuel Osorio Martinez alfredo.oso...@afirme.com: -- Maurizio Cucchiara - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Struts 2 s:action tag doesn't render action errors if any are present
I don't know what struts version you are running, in 2.2.1 version, chain interceptor should copy actionError through actions. -- Maurizio Cucchiara - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: Struts 2 s:action tag doesn't render action errors if any are present
I am using defaultStack but I was reading the issue you just told me: https://issues.apache.org/jira/browse/WW-2869 And talks about invoking an action with the action tag an ChainingInterceptor but I don't know if the actionErrors from the source action will be copied. And by the way I am using the lastest version 2.2.1 -Mensaje original- De: Maurizio Cucchiara [mailto:maurizio.cucchi...@gmail.com] Enviado el: Thursday, October 28, 2010 5:25 PM Para: Struts Users Mailing List Asunto: Re: Struts 2 s:action tag doesn't render action errors if any are present Which interceptor do you mean? ChainingInterceptor? I meant implementing a new Interceptor from scratch. Although this issue are related to the chainInterceptor. What interceptor stack are you using? Does your request fire chainInterceptor? 2010/10/29 Alfredo Manuel Osorio Martinez alfredo.oso...@afirme.com: -- Maurizio Cucchiara - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Struts 2 s:action tag doesn't render action errors if any are present
I am using defaultStack but I was reading the issue you just told me: Well, default stack includes chain interceptor. And by the way I am using the lastest version 2.2.1 Unfortunately, I'm pretty sure that chainInterceptor doesn't copy action errors (the attached patch in WW-2869 prevents this behavior). 2.2.2 version introduces two new fields: copyErrors and copyMessages (that fits to your needs). So, it seems you have 2 way: 1. implementing custom interceptor (you might inspire looking at chain interceptor) 2. download a *nightly* build. 2010/10/29 Alfredo Manuel Osorio Martinez alfredo.oso...@afirme.com: https://issues.apache.org/jira/browse/WW-2869 And talks about invoking an action with the action tag an ChainingInterceptor but I don't know if the actionErrors from the source action will be copied. -Mensaje original- De: Maurizio Cucchiara [mailto:maurizio.cucchi...@gmail.com] Enviado el: Thursday, October 28, 2010 5:25 PM Para: Struts Users Mailing List Asunto: Re: Struts 2 s:action tag doesn't render action errors if any are present Which interceptor do you mean? ChainingInterceptor? I meant implementing a new Interceptor from scratch. Although this issue are related to the chainInterceptor. What interceptor stack are you using? Does your request fire chainInterceptor? 2010/10/29 Alfredo Manuel Osorio Martinez alfredo.oso...@afirme.com: -- Maurizio Cucchiara - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- Maurizio Cucchiara - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Struts 2 s:action tag doesn't render action errors if any are present
2. What I liked about having an action for rendering the controls it's that I can reuse them across different JSP pages. What other alternatives do you suggest me that can achieve the same level of modularity? Try jsp:include or s:include. You can create a common jsp, and include it in different pages. Actually, in my project, I create: (1)common_head.jsp to render the common html head part: css, js, and so on (2)common_form.jsp to render the common form part: s:actionerror /, the page loading Indicator, and so on. And include them in all pages This mechanism make your project very easy to maintain. - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org