This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have 2 JSP pages (P1 and P2) where the flow is as follows.
P2 needs to display some text but P2Action also needs that very text to do some processing in the backend. Hence, I set a request-scope variable in P1Action, retrieve the value in P2 and display it. I then use html:hidden in P2 but it's value always comes out blank.
I know I can use the following to set the value.
Any help will be greatly appreciated. [ June 15, 2006: Message edited by: Ud Naik ]
Take out the value attribute altogether. You don't need it as long as "display" is a property of the form bean. The <html:hidden> tag automatically populates it with whatever value is in the form bean property. If you want to set the value, set it in the action class before calling the JSP.
If you just leave the value attribute alone, the hidden fields will propagate from one page to the other.
in the Action class P1Action and then forwarded to P2. I have also left out the 'value' attribute, but that doesn't seem to work. When I view the source, the message is printed, which means bean:write is doing it's job, but the value for the hidden field is blank.
Joined: Jun 13, 2006
Managed to solve the problem. Here's what I did.
1) Set a request-scope variable in P1Action
2) The P2FormBean has a String variable 'display' defined. This corresponds to the hidden variable 'property' attribute. See my posts above if this is unclear. Override the reset() nethod of P2FormBean, adding
That sets the value of the hidden field in P2.jsp.
3) Override the validate() method of P2FormBean
This adds a request-scope variable 'display' so that the bean:write tag can display the value on p2.jsp. Again, see my posts above if this is unclear.
Just wanted to share this working solution. In case testing reveals a problem, I will be sure to post it here.
Forgot to add: I did remove the 'value' attribute for the <html:hidden> tag, so that part in P2.jsp looks like:
Your solution looks like it is more complex than it needs to be. Did you try this?
Like the other html tags, if you do not specify the name attribute then it will default to the form bean of the enclosing html:form tag. What does your html:form tag look like? Including your struts-config settings would be helpful also. I try to avoid setting individual values on the request so I would probably try something like this: