Struts 2 redirect on validation failure and keep error message -
i'm trying display validation error message after redirect of input field of action. i'm trying use messagestoreinterceptor, without success. here struts.xml:
<action name="list" class="myaction" method="list"> <interceptor-ref name="store"> <param name="operationmode">retrieve</param> </interceptor-ref> <interceptor-ref name="mydefaultinterceptorstack" /> <result name="success">/list.jsp</result> <result name="input">/list.jsp</result> </action> <action name="add" class="myaction" method="add"> <interceptor-ref name="store"> <param name="operationmode">store</param> </interceptor-ref> <interceptor-ref name="mydefaultinterceptorstack" /> <result name="success" type="redirectaction"> <param name="actionname">list</param> </result> <result name="input" type="redirectaction"> <param name="actionname">list</param> </result> </action>
the list method of action sets values of dropdown in list.jsp, has executed before displaying jsp.
the validation in myaction-add-validation.xml:
<!doctype validators public "-//opensymphony group//xwork validator 1.0.2//en" "http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd"> <validators> <field name="name"> <field-validator type="requiredstring"> <message key="name.required" /> </field-validator> </field> </validators>
if call list.action, list.jsp displayed correctly populated. submit form calling add.action , since left name field emtpy, validation fails. messagestoreinterceptor stores field error, input redirect points list action, list action apparently forwards input forward without executing list method first.
so if place tag in list.jsp, can see error message validation, dropdown in list.jsp not populated because list method of list.action has not been executed.
is there way achieve need? helps more welcome. thanks
as described here myaction needs implement preparable, when validation fails, since prepare() method called before it, still have our controls populated.
Comments
Post a Comment