I am using struts 2.0.14 . I have a hidden parameter that is being passed from a page profile.jsp , which hits an action and navigates to the other page "editUser.jsp", where I am trying to display a few buttons based on the hidden parameter value from the previous page.
<input type="hidden" name ="fromProfilePage" id="fromProfilePage" value="true"/>
I have created a variable and its setter and getter methods in the action class.
For validation , I am using validations xml files
The above thing works fine, if all required fields are entered from the page. But if one of the mandatory fields are not passed, I get the error messages onto the same page, but I am losing fromProfilePage value, which shows the other block now.........
Is there any way to retain fromProfilePage even after the validation ?
Thanks for the reply. I tried replacing the html hidden with the struts hidden in the profile.jsp , but it didnt solve my problem. And I have come up with adding another hidden parameter in the editUser.jsp, which has the value of the earlier hidden parameter
<input type="hidden" name ="fromProfilePage" id="fromProfilePage" value="true"/> or <s:hidden name="fromProfilePage" value="true"/>
<s:hidden name="fromProfilePage" >
This works even failing with the validation, which brings me the first block of components. But I am not finding any reason for this working.
Its actually quite simple concept of http request.
1st time the value gets set into the request and you get it.
But on the submit, a new request is generated.
Now, since you don't have that hidden variable in second jsp, the action object gets initialized with null value in "fromProfilePage" variable.
When you add the hidden variable, the value is retained in the jsp, so you get it in the action as well.