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"/> </jsp:include> 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? thanks!!
posted 10 years ago
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.