File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes validation and data flow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "validation and data flow" Watch "validation and data flow" New topic

validation and data flow

jonathan Greens
Ranch Hand

Joined: Apr 07, 2004
Posts: 139
hi folks,
I have a jsp page that accepts some bean and populate the page as the following:
<jsp:include page="/page.jsp" flush="true">
<jsp aram name="data" value="data"/>
so if there's no bean "data" present, this jsp will not display anything.
Typically an action forwards to this page after doing an request.setAttribute("data",data); to create the "data" bean.

Now the form on this jsp submits to an action, if there's validation error, it returns to the current jsp. However when it returns, the bean is no longer present..
why? shouldn't the data still exist in the request?
how do I resolve this issue?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The trouble here is that when a bean is scoped to request, the request and all it's attributes are gone after the page is displayed. When Struts sends it back to the page after a validation error, you are have a different request context from the one you had when you generated the page.

There are a couple of ways around this:
  • put the bean in session scope - or even application scope. (If this data populates a select box that is the same for everybody, there's no need for each user to have a copy in their session)
  • Put code in the bean's reset() method to get the data and put it in the request. Since reset() is called before validate(), this will ensure that the data is there if validate() forwards back to the jsp.

  • Merrill
    Consultant, Sima Solutions
    I agree. Here's the link:
    subject: validation and data flow
    It's not a secret anymore!