Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bean:write does not work properly on validation

 
Luke Zechariah
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34375
345
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic