• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

validation and data flow

Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

      Bookmark Topic Watch Topic
    • New Topic