aspose file tools
The moose likes Struts and the fly likes Losing hidden variable value during Struts 2 validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Losing hidden variable value during Struts 2 validation " Watch "Losing hidden variable value during Struts 2 validation " New topic

Losing hidden variable value during Struts 2 validation

suresh midde

Joined: Aug 22, 2008
Posts: 25
Hi ,

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.

private String fromProfilePage = "false";
public String getFromProfilePage() {
return fromProfilePage;

public void setFromProfilePage(String fromProfilePage) {
this.fromProfilePage = fromProfilePage;

And the following code inside a method that handles the previous page request,

String fromProfile = getServletRequest().getParameter("fromProfilePage");

if ((null != fromProfile) && (!("".equals(fromProfile)))) {
fromProfilePage = fromProfile;

<s:if test="%{fromProfilePage == 'true'}">
Hello from profile page...
<s:submit ondblclick="return false;" action="editProfileChanges" key="" cssClass="btn"/>
<s:submit ondblclick="return false;" action="populateProfiles" key="label.cancel" cssClass="btn"/>
<s:submit ondblclick="return false;" action="addUser" key="" cssClass="btn"/>
<s:submit ondblclick="return false;" action="populateUser" key="label.cancel" cssClass="btn"/>

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 ?

Suresh Midde
Nitin Surana
Ranch Hand

Joined: Jan 21, 2011
Posts: 129

I don't know what is going wrong.

But instead of this in profile.jsp

try this
suresh midde

Joined: Aug 22, 2008
Posts: 25
Hi Nitin,

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"/>

and in


<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.

Suresh Midde
Jigs Gohil

Joined: Jun 09, 2011
Posts: 6

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.
candid java

Joined: Jan 13, 2012
Posts: 14
i found the exact answer from this link you can check it out
I agree. Here's the link:
subject: Losing hidden variable value during Struts 2 validation