aspose file tools*
The moose likes Struts and the fly likes bean:write does not work properly on validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "bean:write does not work properly on validation" Watch "bean:write does not work properly on validation" New topic
Author

bean:write does not work properly on validation

Luke Zechariah
Ranch Hand

Joined: Sep 27, 2005
Posts: 123
Hello,

My Jsp page has these this code and I am using struts validation.

<TD class="left">Applicant Name:</TD>
<TD class="left"><bean:write name="RqstForm" property="applName" /></TD>

My validation part works fine, it displays the errors when OK is clicked. But all the <bean:write> values on my page disappear after the page is re-loaded.

So before clicking OK it looks:
Applicant Name:Johny Hudson

After clicking OK it looks:
Applicant Name:

The value "Johny Hudson" disappears. But the <html:text> values appear to be fine.

Please help. Thanks for your time.

Luke.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30762
    
156

Luke,
RqstForm sounds like a form in the HttpRequest scope. This scope is wiped clean on a new request/trip to server. After the validation, you are on a new request and the data is gone.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Jeanne is absolutely right. However, I'm guessing the next question in your mind is "so now what do I do?".

One way to do it would be to add a hidden field to your page like this:

If you do this, the "applName" property will get submitted along with the form and will be added to your ActionForm when the validation fails. It will then show up on your JSP just like the other input fields do.


Merrill
Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Merrill's suggestion is the easiest and it works great for small sets of data. You will find that you encounter the same issue for the lists used to populate list boxes. If you have a lot of data or if you have lists of data the solution that I use is to have the input attribute of your action mapping point to an action that can populate these values on your form.

- Brent
Luke Zechariah
Ranch Hand

Joined: Sep 27, 2005
Posts: 123
Jeanne, thank you very much in clearing me the concept on what really happens on the background.

Merrill, I would really go ahead with your suggestion, per Brent's recomendation as it has less chunk of data. Thank you.

Brent, I did have the problem a while ago and did not know which way to proceed. So I put the whole arraylist in a session scope. But thank you, that is a good suggestion.

Thanks everyone once again, its working the way it was desired.
Luke.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bean:write does not work properly on validation