struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Assenza, Chris" <casse...@Accessdc.com>
Subject RE: getting value from bean
Date Fri, 30 Mar 2001 16:10:58 GMT
Check out the sample app! :) Here's the code for the logon screen that gets
the data from the ActionForm.

	String username = ((LogonForm) form).getUsername();
	String password = ((LogonForm) form).getPassword();

LogonForm is the name of the Form Bean and form is from the arguments you
mentioned (ActionForm form). The getXXX() methods are methods in your Form
Bean that match up to the form-fields on your JSP! :)

That's just an example, but it should be pretty easy for you to replicate
with your bean, MyBean.

Chris Assenza


-----Original Message-----
From: Nishit Trivedi [mailto:nishit.trivedi@insage.com]
Sent: Friday, March 30, 2001 10:58 AM
To: 'struts-user@jakarta.apache.org'
Subject: RE: getting value from bean


ok..
so i am upto this point..
I have perform method in ProcessMyBean.java
it has four aguements : ActionMapping mapping,ActionForm
form,HttpServletRequest request,HttpServletResponse response

so how do i get the reference of "MyBean" in this ProcessBeanClass without
creating new object of  "MyBean"..??

Please bear with me..as i just started working on struts...

Nishit

-----Original Message-----
From: Martin Cooper [mailto:martin.cooper@tumbleweed.com]
Sent: Friday, March 30, 2001 12:51 AM
To: struts-user@jakarta.apache.org
Subject: Re: getting value from bean


See comments intermixed.

----- Original Message -----
From: "Nishit Trivedi" <nishit.trivedi@insage.com>
To: <struts-user@jakarta.apache.org>
Sent: Thursday, March 29, 2001 3:29 PM
Subject: RE: getting value from bean


> This is what i think should happen...
> (Correct me wherever i am wrong...)
>
> This is how i call bean for setting values in config file:
> ------------------------------------
>     <!-- Form bean -->
>     <form-bean      name="myForm"
>                     type="org.apache.struts.dir1.dir2.MyBean"
>                     scope="session"/>
> ------------------------------------

The 'scope' attribute does not apply to the <form-bean> element. It applies
aonly to the <action> element, as you use it below.

It seems odd that your form is under the Struts package, but it won't cause
any problems.

> then after i set the values and after validate method, control goes as
> follows:
> -----------------------------------------------
>     <!-- Action mapping -->
>     <action    path="/doSomeAction" <!-- when i view source of jsp page
that
> has form it has
>                                     action as
> "/struts-example/doSomeAction.do" -->
>                type="org.apache.struts.dir1.dir2.ProcessMyBean"
>                name="myForm"
>               scope="session"
>            validate="false">
>       <forward name="success"              path="/dir1/dir2/Success.jsp"/>
>       <forward name="failure"              path="/dir1/dir2/Error.jsp"/>
>     </action>
> -----------------------------------------------

This looks OK. When doSomeAction.do is invoked, Struts will look for an
instance of your form in the session, under the attribute name "myBean". If
it does not find one, it will create a new one for you. It will then
populate the bean with the values from the request.

> So in ProcessMyBean class, i instantiated object MyBean with:
> MyBean mb = new MyBean();
> and then i called the getter to get the value which was set before:
> (here is somewhat i am missing)

I think this is where your problem lies. You should not be creating an
instance of your form bean. Struts will do that for you, and call the
appropriate setter methods based on the query string for the request. The
form bean will then be passed to your action's perform() method, and you can
call the getter methods as necessary.

Hope this helps.

--
Martin Cooper


>
> Please help me...
> Nishit
> -----Original Message-----
> From: Jacob Thomas [mailto:jthomas@vitria.com]
> Sent: Thursday, March 29, 2001 5:58 PM
> To: 'struts-user@jakarta.apache.org'
> Subject: RE: getting value from bean
>
>
> I think your <html:form> tag is instantiating a new Form bean and hence
the
> fields have their default values when the page is rendered. When the page
is
> submitted another form bean is getting created. You may want to set the
> scope to 'session' and remove the bean appropriately.
> --
> Jacob
>
> -----Original Message-----
> From: Nishit Trivedi [mailto:nishit.trivedi@insage.com]
> Sent: Thursday, March 29, 2001 2:49 PM
> To: struts-user@jakarta.apache.org
> Subject: getting value from bean
>
>
> hi.
>
> I am new to struts...
>
> I have a problem with getting a value from bean...
> here are some pieces of my code where i set and get values:
>
>  In jsp page i have this:
> ---------------------------------------------------------------------
>
>     <td align="left">
>       <html:text property="totalCopies" maxlength="3"/>
>     </td>
> --------------------------------------------------------------------
>
>  In class i have getter and setter as:
> --------------------------------------
>  public String getTotalCopies(){
>    System.out.println("getting total copies:"+this.totalCopies);
>    return this.totalCopies;
>  }
>
>  public void setTotalCopies(String totCopy){
>    this.totalCopies = totCopy;
>    System.out.println("setting total copies:"+this.totalCopies);
>  }
> -------------------------------------
>
> Print statement of setter is perfectly fine as i expected but
> the statement in getter returns null...?? what's wrong?
> TIA..
>
> Nishit Trivedi
> Software Engineer
> Planet Access Networks - An InSage Company
> 973-691-4704 X157

Mime
View raw message