form initialization

2001-12-12 Thread Jon Burford

Greetings!

I have a dynamic form which needs to be initialized from the database.  If I put code 
to initialize the attributes in the default constructor of the form bean, all this 
happens with no problems - the form is displayed with the proper values.  My problem 
is that the form bean needs some of the request parameters from the calling jsp page 
in order to properly initialize its fields.  What is the preferred way of form bean 
initialization and how can it access request parameters at initialization time?  I 
used a couple hidden form fields which the jsp page initialized to the corresponding 
request parameters, but this does not take effect until AFTER the constructor is 
called.  Any help would be much appreciated.

TIA!
Jon




Re: form initialization

2001-12-12 Thread Arron Bates

The only way which I've done such a thing is with a bean nested one 
level inside another.

The constructor is called on the root bean, and have getters and setters 
there waiting to handle the parameters that you're passing from your 
form. In your action, call another method which will then build the 
nested bean with everything which you need from the database. From then 
in, reference properties in the internal bean via nested properties.

So the sequence happens like this

1) Form is submitted with parameters needed to load the bean.
2) The constructor is called in the root bean and an empty root bean is 
made.
3) Struts servlet will populate properties with your init parameters.
4) In your action, call a method like "initInternalBean()" or something.
5) Inside this method, access the properties which were set by the form, 
and build an internal bean to what you need..
6) If you have a simple getter method to access the bean you can get to 
the properties you need via nested properties which you can use 
thereafter in your JSP's etc.
eg.  "internalBean.beanProperty"

Is this enough to get across what I'm trying to say?...
I can provide a simple code snippet if it's not.
If you're worried about managing nested objects in your JSP's I can 
help there too. ;)


Arron.

Jon Burford wrote:

>Greetings!
>
>I have a dynamic form which needs to be initialized from the database.  If I put code 
>to initialize the attributes in the default constructor of the form bean, all this 
>happens with no problems - the form is displayed with the proper values.  My problem 
>is that the form bean needs some of the request parameters from the calling jsp page 
>in order to properly initialize its fields.  What is the preferred way of form bean 
>initialization and how can it access request parameters at initialization time?  I 
>used a couple hidden form fields which the jsp page initialized to the corresponding 
>request parameters, but this does not take effect until AFTER the constructor is 
>called.  Any help would be much appreciated.
>
>TIA!
>Jon
>
>



--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Re: form initialization

2001-12-12 Thread Craig R. McClanahan



On Wed, 12 Dec 2001, Jon Burford wrote:

> Date: Wed, 12 Dec 2001 20:40:34 -0800
> From: Jon Burford <[EMAIL PROTECTED]>
> Reply-To: Struts Developers List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: form initialization
>
> Greetings!
>
> I have a dynamic form which needs to be initialized from the database.
> If I put code to initialize the attributes in the default constructor
> of the form bean, all this happens with no problems - the form is
> displayed with the proper values.  My problem is that the form bean
> needs some of the request parameters from the calling jsp page in
> order to properly initialize its fields.  What is the preferred way of
> form bean initialization and how can it access request parameters at
> initialization time?  I used a couple hidden form fields which the jsp
> page initialized to the corresponding request parameters, but this
> does not take effect until AFTER the constructor is called.  Any help
> would be much appreciated.
>

This type of question is really more suited for the STRUTS-USER list.

The design pattern I prefer is exemplified in the Struts Example
application -- use an Action to set up the form bean *before* the form is
displayed.

In the example app, note how an "Edit Subscription" transaction is
handled:

* The "/editSubscription" action is called to pre-fill the
  SubscriptionForm bean and place it in request scope.  If you
  need values from the request that triggered this, they are
  accessible to the Action and it can call setters as needed.

* This action forwards to "subscription.jsp" which shows the
  pre-filled-out form.

* The submit goes to the "/saveSubscription" action which
  updates the database (assuming successful validation).

> TIA!
> Jon
>
>

Craig McClanahan



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Re: form initialization

2001-12-13 Thread Oleg V Alexeev

Hello Jon,

Thursday, December 13, 2001, 7:40:34 AM, you wrote:

JB> Greetings!

JB> I have a dynamic form which needs to be initialized from the
JB> database.  If I put code to initialize the attributes in the
JB> default constructor of the form bean, all this happens with no
JB> problems -   
JB> the form is displayed with the proper values.  My problem is that
JB> the form bean needs some of the request parameters from the
JB> calling jsp page in order to properly initialize its fields.  What
JB> is   
JB> the preferred way of form bean initialization and how can it
JB> access request parameters at initialization time?  I used a couple
JB> hidden form fields which the jsp page initialized to the
JB> corresponding request parameters, but this does not take effect
JB> until AFTER the constructor is called.  Any help would be much
JB> appreciated.  

Firstly - place such questions to the struts-user list, please.

Common solution to fill form with values from database is to create
Action class and appropriate mapping for it -

public class ReadAction extends Action {

   ... some stuff to read values from database, create or retrieve
   ActionForm bean, fill it with values and store this bean in
   request or session. Return 'success' forward if all is ok and
   'error' if any errors.

}

and map this class to the read.do path, for example.


  
  


viewValues.jsp form contains form 'someForm'.

-- 
Best regards,
 Olegmailto:[EMAIL PROTECTED]



--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Re: form initialization

2001-12-13 Thread Colin Sharples

Apologies for following up a user-type question with another one, but in
the interests of (brain) bandwith I don't read the user list. Please
forgive me, I won't do it again :-)

If this approach is used, populating the form bean before the form is
displayed, then it means that hitting a "Reset" button will, rather than
clearing the form, clear out any user modifications and re-fill the form
with the values that the bean was populated with in the previous step.

Now, I know that this is the expected, or even required behaviour from the
point of view of HTML. However, when I had one site going through testing,
the tester complained that a particular form was broken because the reset
button kept on filling in the values instead of clearing them. In this
particular case, it was clear that what was required was not a "reset"
button, but a "clear all the fields" button.

So, getting to the point (eventually), I know that it's possible to do this
server-side, by having a button which will just cause the form bean to have
all its properties set to null and redirect back to the input page.
However, is there a way to do this client-side?

Regards

Colin M Sharples
I/T Architect
IBM Global Services New Zealand

email: [EMAIL PROTECTED]
phone: 64-4-5769853
mobile: 64-21-402085
fax: 64-4-5765616




   

"Craig R.  

McClanahan"  To: Struts Developers List 
<[EMAIL PROTECTED]>    
  Subject: Re: form initialization  

Sent by:   

[EMAIL PROTECTED] 

m.com  

   

   

13/12/2001 

19:30  

Please respond 

to "Struts 

Developers 

List"  

   

   






On Wed, 12 Dec 2001, Jon Burford wrote:

> Date: Wed, 12 Dec 2001 20:40:34 -0800
> From: Jon Burford <[EMAIL PROTECTED]>
> Reply-To: Struts Developers List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: form initialization
>
> Greetings!
>
> I have a dynamic form which needs to be initialized from the database.
> If I put code to initialize the attributes in the default constructor
> of the form bean, all this happens with no problems - the form is
> displayed with the proper values.  My problem is that the form bean
> needs some of the request parameters from the calling jsp page in
> order to properly initialize its fields.  What is the preferred way of
> form bean initialization and how can it access request parameters at
> initialization time?  I used a couple hidden form fields which the jsp
> page initialized to the corresponding request parameters, but this
> does not take effect until AFTER the constructor is called.  Any help
> would be much appreciated.
>

This type of question is really more suited for the STRUTS-USER list.

The design pattern I prefer is exemplified in the Struts Example
application -- use an Action to set up the form bean *before* the form is
displayed.

In the example app, note how an "Edit Subscription" transaction is
handled:

* The "/editSubscription" action is called to pre-fill the
  SubscriptionForm bean and place it in request scope.  If you
  need values from the request that triggered this, they are
  accessible to the Action and it can call setters as needed.

* This actio

RE: form initialization

2001-12-13 Thread Matt Raible

Here's a javascript function that will clear all the values in a form:


function clearForm(frmObj){
for(var i = 0; i < frmObj.length; i++){
if(frmObj.elements[i].type.indexOf("text") == 0){
frmObj.elements[i].value="";
}
else if (frmObj.elements[i].type.indexOf("radio") == 0){
frmObj.elements[i].checked=false;
}
else if (frmObj.elements[i].type.indexOf("checkbox") == 0){
frmObj.elements[i].checked = false;
}
else if (frmObj.elements[i].type.indexOf("select") == 0){
for(var j = 0; j < frmObj.elements[i].length ; j++){
frmObj.elements[i].options[j].selected=false;
}
}
}
}

-Original Message-
From: Colin Sharples [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 13, 2001 1:37 PM
To: Struts Developers List
Subject: Re: form initialization


Apologies for following up a user-type question with another one, but in
the interests of (brain) bandwith I don't read the user list. Please
forgive me, I won't do it again :-)

If this approach is used, populating the form bean before the form is
displayed, then it means that hitting a "Reset" button will, rather than
clearing the form, clear out any user modifications and re-fill the form
with the values that the bean was populated with in the previous step.

Now, I know that this is the expected, or even required behaviour from the
point of view of HTML. However, when I had one site going through testing,
the tester complained that a particular form was broken because the reset
button kept on filling in the values instead of clearing them. In this
particular case, it was clear that what was required was not a "reset"
button, but a "clear all the fields" button.

So, getting to the point (eventually), I know that it's possible to do this
server-side, by having a button which will just cause the form bean to have
all its properties set to null and redirect back to the input page.
However, is there a way to do this client-side?

Regards

Colin M Sharples
I/T Architect
IBM Global Services New Zealand

email: [EMAIL PROTECTED]
phone: 64-4-5769853
mobile: 64-21-402085
fax: 64-4-5765616





"Craig R.
McClanahan"  To:     Struts Developers List
<[EMAIL PROTECTED]>
  Subject: Re: form
initialization
Sent by:
[EMAIL PROTECTED]
m.com


13/12/2001
19:30
Please respond
to "Struts
Developers
List"







On Wed, 12 Dec 2001, Jon Burford wrote:

> Date: Wed, 12 Dec 2001 20:40:34 -0800
> From: Jon Burford <[EMAIL PROTECTED]>
> Reply-To: Struts Developers List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: form initialization
>
> Greetings!
>
> I have a dynamic form which needs to be initialized from the database.
> If I put code to initialize the attributes in the default constructor
> of the form bean, all this happens with no problems - the form is
> displayed with the proper values.  My problem is that the form bean
> needs some of the request parameters from the calling jsp page in
> order to properly initialize its fields.  What is the preferred way of
> form bean initialization and how can it access request parameters at
> initialization time?  I used a couple hidden form fields which the jsp
> page initialized to the corresponding request parameters, but this
> does not take effect until AFTER the constructor is called.  Any help
> would be much appreciated.
>

This type of question is really more suited for the STRUTS-USER list.

The design pattern I prefer is exemplified in the Struts Example
application -- use an Action to set up the form bean *before* the form is
displayed.

In the example app, note how an "Edit Subscription" transaction is
handled:

* The "/editSubscription" action is called to pre-fill the
  SubscriptionForm bean and place it in request scope.  If you
  need values from the request that triggered this, they are
  accessible to the Action and it can call setters as needed.

* This action forwards to "subscription.jsp" which shows the
  pre-filled-out form.

* The submit goes to the "/saveSubscription" action which
  updates the database (assuming successful validation).

> TIA!
> Jon
>
>

Craig McClanahan



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]
>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]
>





--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Re: form initialization

2001-12-14 Thread Ted Husted

You really *MUST* post these questions to the user list where there are
more people to help you. 

But, yes, you can write a Javascript that clears the fields. Anything
you want to do "client-side" is going to involve Javascript, and is
technically outside the scope of the framework.

Colin Sharples wrote:
> 
> Apologies for following up a user-type question with another one, but in
> the interests of (brain) bandwith I don't read the user list. Please
> forgive me, I won't do it again :-)
> 
> If this approach is used, populating the form bean before the form is
> displayed, then it means that hitting a "Reset" button will, rather than
> clearing the form, clear out any user modifications and re-fill the form
> with the values that the bean was populated with in the previous step.
> 
> Now, I know that this is the expected, or even required behaviour from the
> point of view of HTML. However, when I had one site going through testing,
> the tester complained that a particular form was broken because the reset
> button kept on filling in the values instead of clearing them. In this
> particular case, it was clear that what was required was not a "reset"
> button, but a "clear all the fields" button.
> 
> So, getting to the point (eventually), I know that it's possible to do this
> server-side, by having a button which will just cause the form bean to have
> all its properties set to null and redirect back to the input page.
> However, is there a way to do this client-side?
> 
> Regards
> 
> Colin M Sharples
> I/T Architect
> IBM Global Services New Zealand
> 
> email: [EMAIL PROTECTED]
> phone: 64-4-5769853
> mobile: 64-21-402085
> fax: 64-4-5765616

--
To unsubscribe, e-mail:   
For additional commands, e-mail: