• 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

Populating value of hidden field....

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a bean defined in my jsp like this...
<bean efine id="emp" name="empList" property="currentEmployee" type="bean.EmployeeCargoBean"/>
I am showing the user the attributes of the above bean for display only, and want to also "pass on" a value from this bean into the form so the next action in the sequence can do something with it.
So I also have a hidden field, like this...
<html:hidden property="employeeNum"></html:hidden>
How can I "load" this field with a value from the previously defined bean?
Sounds simple (and probably is !) but I can't work out how to do it!
Can anyone help?
TIA
Dave
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try
<html:hidden property="employeeNum" value="<%= emp.getSomeProperty() %>" />

Note that you could simply have Struts take care of populating this field for you. All you need to do is to set the property value in the appropriate form before the JSP that uses the form is displayed.
[ February 06, 2003: Message edited by: Junilu Lacar ]
 
Dave Hewitson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Junila - thanks
I understand the first part of your reply - though I was trying to avoid using any scriptlets in the jsp.
I'm not sure what you mean about loading the form before the jsp is displayed. I presume you mean in the action previous to this?? But how can I access that form because until struts builds the page it won't be in the session will it?
Have I got the wrong end of the stick here?
Dave
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's Junilu, thank you.
I assume you are following the recommendation to link only to actions. Doing this makes life a lot simpler and allows you to avoid scripting a great deal. Here's what I'm talking about:
first.jsp: contains a form, a hidden field - say employeeNum - without the value set, and a submit button. The form's action="first.do". first.do is associated with FirstAction which is associated with FirstForm. FirstForm would have getEmployeeNum() and setEmployeeNum(). I usually add a submit field in my forms to receive the value of the submit button. In the reset() method, I set the submit field to null.
Configure FirstAction with two forwards: say "display" and "process". The "display" forward will have the first.jsp as a target. The "process" forward will have "second.do" as its target.
FirstAction.perform() or execute() checks if the form (passed as a parameter) was submitted (submit != null). If not submitted, then retrieve the value for the employeeNum (from database or some bean already existing) and call the firstForm.setEmployeeNum(). Then return the "display" forward. This will process first.jsp and Struts will automatically set the value of the hidden employeeNum field. If the form was submitted, the employeeNum value is already in the request as a parameter so all you need to do is return the "process" forward, which will hand off control to the Action associated with "second.do", say SecondAction.
In the SecondAction.perform()/execute(), you can simply use request.getParameter() to get the employeeNum value and use it to prepopulate the second form, say SecondForm. If the employeeNum is also a field in SecondForm and that is all you need to be prepopulated, then don't have to do anything: Struts will automatically populate employeeNum with the value in the request parameter. You just return a "success" forward whose target is "second.jsp" which has a form whose action="second.do".
Clear as mud?
---
seem to be having some trouble posting messages today so sorry if I've confused you with my reply that I have since deleted
[ February 06, 2003: Message edited by: Junilu Lacar ]
 
Dave Hewitson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Junilu (got it right that time!)
I think I understand your suggestion.
At the moment my forwards are to jsp pages, but I like the idea of forwarding to an action because it allows me to do some screen pre-processing that I couldn't easily do at present.
So you're saying that by using the button state stored on the actionform I can tell whether the form was submitted, or whether the page is being shown as a result of a call from another page.
So, because I'm going to another action, all the stuff the request is still there and I can pre-populate the actionform for the second screen.
Yes - that sounds like it'll work.
Many thanks
Dave.
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to make my life simpler, I'm using an ActionForm subclass as my base form that has the following:
 
Dave Hewitson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to do that and use LookupDispatchAction?
I can't work out how to control doing the screen preprocessing, ie when normally the button would be null - because this is taken care of with the mappings in the action.
Dave
 
reply
    Bookmark Topic Watch Topic
  • New Topic