• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

html:hidden

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ud Naik
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic