struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Siggelkow, Bill" <bill.siggel...@mirant.com>
Subject RE: [newbie] default values for form elements
Date Fri, 12 Oct 2001 13:27:18 GMT
This will work Rob, but I you need to place the formBean in the scope
specified by the mapping ... something like ... in general, I think, in most
cases, FormBeans really belong in the request scope.

	    if (form == null) {
	        form = new MyFormBean();
            if ("request".equals(mapping.getScope()))
                request.setAttribute(mapping.getAttribute(), form);
            else
                session.setAttribute(mapping.getAttribute(), form);
    	}


-----Original Message-----
From: Robert Pieper [mailto:Robert.Pieper@macquarie.com]
Sent: Thursday, October 11, 2001 7:57 PM
To: 'struts-user@jakarta.apache.org'
Subject: RE: [newbie] default values for form elements


Instantiate the bean in your action.  So if you have written MyFormBean.java
with all the required getters and setters then inside your Action (and
before the form is displayed the first time) do;

MyFormBean mfb = new MyFormBean();
mfg.setWhatever( "hello" );
etc

Then store it in the user's session;

request.getSession().setAttribute( mfb, "myFormBean" );


When the JSP is displayed, Struts will look for myFormBean in session first
and only create it if it does not exist.  Since you have explicitly created
it yourself and put it there it should simply use your copy.  The only thing
you need to make sure of is that your struts-config.xml file uses the same
logical name for the bean to use (ie. myFormBean)

This works for me but I'm only a newbie myself so if anybody feels this is
not the best way, tell us ;)

Rob Pieper

-----Original Message-----
From: Jan G.P. Sijm [mailto:jan.sijm@hccnet.nl]
Sent: Friday, 12 October 2001 7:44 AM
To: struts-user@jakarta.apache.org
Subject: RE: [newbie] default values for form elements


Hi,

> The most robust way would be
> instead of having a link go right to the JSP
> containing the form ... have
> the link go to an action that initializes the
> form ...

I understand what you mean, but I do n't see how I can
initialize the form. The form bean that represents the form
fields is n't instantiated until the form is submitted for
the first time. So, how do I initialize this form bean?

Bye Jan...

> -----Original Message-----
> From: Jan G.P. Sijm [mailto:jan.sijm@yoursurfice.com]
> Subject: [newbie] default values for form elements
> Hi,
> I am very new to struts: Struts remembers input values,
> which are re-displayed automatically when a form is
> displayed for the second time. I do n't
> understand, however,
> how default values for form elements can be set that are
> shown when the form is displayed for the first
> time. How can
> I set the default values for all text fields,
> radio buttons,
> checkboxes etc. that are in a form?
>
> Bye Jan...

Mime
View raw message