struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karim Saloojee" <kar...@hotpop.com>
Subject Re: Help needed with ActionForm Bean
Date Wed, 25 Sep 2002 11:24:00 GMT
Try pre-populating the form i.e create the form, set its variables, put it
into the request, forward to the JSP.
For instance you have:

PageA.jsp
ProcessPageA_Action.java
ActionFormA.java

In the Action before you display PageA.jsp, create an instance of the
ActionFormA class, set the select box variable and whatever else you need.
Then put the ActionFormA object into the session/request under the key you
specified in the struts-config.xml. When PageA.jsp loads, Struts will find
the FormBean in the session/request using the key in the struts-config.xml
and populate the JSP from those values.





----- Original Message -----
From: "Vincent Berruchon" <vincent.berruchon@neo-logism.fr>
To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
Cc: <Galbreath@tessco.com>
Sent: Wednesday, September 25, 2002 12:02 PM
Subject: Re: Help needed with ActionForm Bean


> thanks for your reply, perhaps there's something I've haven't understand:
>
> I'd like to display  in my select dropdown data that come from a
> database... where should I get this data from the DB this should be done
> before the call of the getXXX method of the ActionForm when.
>
> Should I use an action where I get data from the DB and forward it to
> the action associated with the jsp page containing the form?? is it the
> way to do it?
>
>
> Vincent
>
> Galbreath, Mark wrote:
> > It's magic.
> >
> >
> > Seriously, your getters and setters in your ActionForm bean correspond
to
> > the HTML input fields in your JSP.  So if you have a select dropdown in
the
> > JSP called "state," in some HTML form for collecting personal
information
> > you could have
> >
> >   private state = "";
> >
> >   public void setState( String state) {
> >     this.state = state;
> >   }
> >
> >   public String getState() {
> >     return state;
> >   }
> >
> > in your Action form.  In order to make Struts aware of this bean, you
must
> > declare in your struts-config.xml file and have an action path mapped
from
> > your JSP to an Action class that will manipulate the bean values that
are
> > set by Struts:
> >
> > <form-bean  name="PersonalInfoForm"
> >             type="com.whatever.PersonInfoForm" />
> >
> > <action path="/personalInfo"
> >         type="com.whatever.GetPersonalInfoAction"
> >         name="PersonalInfoForm"
> >         scope="session"
> >   validate="true"
> >   parameter="isNew">
> >   <forward name="success" path="/personalInfo.jsp" />
> >   <forward name="error" path="/errors.jsp" />
> > </action>
> >
> > So this associates your bean with your JSP and your ActionClass.  When
your
> > user goes to http://yoursite/personalInfo.do (depending on the mapping
in
> > your web.xml), personalInfo.jsp will be invoked and the rendered HTML
> > displayed.  After the user fills out the form and submits (for example,
the
> > form action is /reviewPersonalInfo which will display everything the
user
> > just entered), the following action path is invoked:
> >
> > <action path="/reviewPersonalInfo"
> >         type="com.whatever.SavePersonalInfoAction"
> >         name="PersonalInfoForm"
> >         input="/PersonalInfo.jsp"
> >         scope="session"
> >   validate="true"
> >   parameter="isError">
> >   <forward name="success" path="/reviewPersonalInfo.jsp" />
> >   <forward name="error" path="/personalInfo.jsp" />
> > </action>
> >
> > and reviewPersonalInfo.jsp will appear to display the information
contained
> > in your bean through the use of Struts tags. At this point you can also
> > access the bean's state in your Action class through the form object to
save
> > it to a database or whatever.
> >
> > Okay?
> >
> > Mark
> >
> > (That should have earned me a few [OT/FRIDAY] msgs, eh?)
> >
> >
> > -----Original Message-----
> > From: Vincent Berruchon [mailto:vincent.berruchon@neo-logism.fr]
> > Sent: Tuesday, September 24, 2002 11:19 AM
> >
> >   Hi, I'm still newie and really confused on how to get HTML form filled
> > with struts...
> > I want to fill a select input in a form in one of my JSP.
> > So I've write an ActionForm Bean with the get and set methods for each
> > properties corresponding to an input on the form.
> > But I don't know where these "set" methods are (or should) be called to
> > fill actionForm properties before the calls to the get methods?
> >
> > Can someone help us?
> >
> > --
> > To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>
> >
> >
> >
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>
>



--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message