This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes html:hidden Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:hidden" Watch "html:hidden" New topic
Author

html:hidden

Ud Naik
Greenhorn

Joined: Jun 13, 2006
Posts: 18
Hi all,

I have 2 JSP pages (P1 and P2) where the flow is as follows.

P1->P1Action->P2->P2Action

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.



I also have some other fields which do not accept a null value, so I am using the validator framework (without Javascript) to check those values. But when the control from the validate() method comes back, there's some error and the page simply does not render. There's no mention of an exception in any server log files.

Any help will be greatly appreciated.
[ June 15, 2006: Message edited by: Ud Naik ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Ud Naik
Greenhorn

Joined: Jun 13, 2006
Posts: 18
Hi, thanks for the reply.

I did set a request-scope variable like so


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.
Ud Naik
Greenhorn

Joined: Jun 13, 2006
Posts: 18
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:

[ June 16, 2006: Message edited by: Ud Naik ]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
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:


- Brent
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: html:hidden