You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Heather Buch <hb...@www.thebuchs.dk> on 2003/07/01 12:28:22 UTC

where does a form element get and put it's data

I know the Struts form bean raises a lot of discussion. Personally, form beans
cause me a lot of confusion too, maybe not in the same way that they confuse
others, but maybe so. I'll attempt to explain.

I feel like it is not consistent whether a form bean is first used upon
creating, or submitting a form.

Basically, my Action classes fall into two general categories:

1. "list" action classes which get data from my database and put it into a form.
2. "save" action classes which take data from the form and write to the db.

As far as I am concerned, this is how use of a form bean makes sense to me:

1. user requests a form
2. "list" action executes and saves some database data into a the session or
request.
3. user fills out and submits form
4. form bean collects data
5. "save" action executes and gets data out of form bean

But sometimes I feel like struts intends for me to use a form bean like this:

1. user requests a form
2. "list" action executes and saves some database data into a the session or
request.
3. "list" action creates a form bean and puts data into it (I don't like this.
I don't want to see my form bean until after form is submitted)
4. user fills out and submits form
5. form bean collects data
6. "save" action executes and gets data out of form bean

I cannot understand how some of the jsp tags work vis a vis form beans.

For example, if, in a "list" action, I make a list of beans of database
information and set that list in the session, I can then use the "html:select"
tag to retrieve data from the bean I have set in the session, and write it to
the form bean. This makes sense.

However, if I want to use a prepopulated radio button, then, in my "list"
action I have to get data from the database and put it in my *form bean*.
Based on what I understand, the html:radio "property" attribute will only
prepopulate the radio button if the information retrieved from the *form bean*
via "property" matches the "value" attribute of html:radio. But I do not want
to *retrieve* infromation from my form bean when I display my form. I want to
retrieve information from the bean that my "list" action has saved in the
session. I only want to retrieve information from my form bean during my
"save" action. 

so it seems like the flow of information from database to form bean and then
to action is kind of inconsistent. I hope this makes sense. If  you need some
examples, let me know and I'll try to create them.

Best,

Heather Buch



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


Re: where does a form element get and put it's data

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Surely you have the same issue with selecting the correct option in the 
select box as you do with the radio buttons?

If I understand correctly what you are saying, you are actually talking 
about 2 seperate datasets: the dataset that you are going to edit in the 
form, and the dataset that you use to populate radio buttons or select 
boxes.

In the average application I write, the datasets for dropdowns etc 
rarely gets edited, so I retrieve it from the database and keep it, 
normally as a list of beans, in APPLICATION_SCOPE, and I keep the 
editable data in the request or the session. But to get the editable 
data into an HTML form, I always have to call it up first (your step 2) 
and put it into the ActionForm. How else are you going to get it into 
the textboxes, checkboxes, selectboxes etc?

If I want to keep my editable data around server-side for some reason, I 
keep the form in the session, but normally I don't, so I keep my forms 
in my request. Normally too I only ever edit one bean of data at a time. 
I have done editable lists of many beans using the nested-beans plug-in too.

Hope I understood you correctly and haven't been waffling on beside the 
point.

Adam

Heather Buch wrote:
> I know the Struts form bean raises a lot of discussion. Personally, form beans
> cause me a lot of confusion too, maybe not in the same way that they confuse
> others, but maybe so. I'll attempt to explain.
> 
> I feel like it is not consistent whether a form bean is first used upon
> creating, or submitting a form.
> 
> Basically, my Action classes fall into two general categories:
> 
> 1. "list" action classes which get data from my database and put it into a form.
> 2. "save" action classes which take data from the form and write to the db.
> 
> As far as I am concerned, this is how use of a form bean makes sense to me:
> 
> 1. user requests a form
> 2. "list" action executes and saves some database data into a the session or
> request.
> 3. user fills out and submits form
> 4. form bean collects data
> 5. "save" action executes and gets data out of form bean
> 
> But sometimes I feel like struts intends for me to use a form bean like this:
> 
> 1. user requests a form
> 2. "list" action executes and saves some database data into a the session or
> request.
> 3. "list" action creates a form bean and puts data into it (I don't like this.
> I don't want to see my form bean until after form is submitted)
> 4. user fills out and submits form
> 5. form bean collects data
> 6. "save" action executes and gets data out of form bean
> 
> I cannot understand how some of the jsp tags work vis a vis form beans.
> 
> For example, if, in a "list" action, I make a list of beans of database
> information and set that list in the session, I can then use the "html:select"
> tag to retrieve data from the bean I have set in the session, and write it to
> the form bean. This makes sense.
> 
> However, if I want to use a prepopulated radio button, then, in my "list"
> action I have to get data from the database and put it in my *form bean*.
> Based on what I understand, the html:radio "property" attribute will only
> prepopulate the radio button if the information retrieved from the *form bean*
> via "property" matches the "value" attribute of html:radio. But I do not want
> to *retrieve* infromation from my form bean when I display my form. I want to
> retrieve information from the bean that my "list" action has saved in the
> session. I only want to retrieve information from my form bean during my
> "save" action. 
> 
> so it seems like the flow of information from database to form bean and then
> to action is kind of inconsistent. I hope this makes sense. If  you need some
> examples, let me know and I'll try to create them.
> 
> Best,
> 
> Heather Buch
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 


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


Re: where does a form element get and put it's data

Posted by Sandeep Takhar <sa...@yahoo.com>.
If the page is editable, then you should have the form
as the "bean" in the list action.

It is easier to think of the whole thing as layers of
systems.  For struts - the entity that we populate
into and is auto-populated is the form.  From here we
can populate DTO's or a middle-tier object that can
eventually used by the back-end.

You may want to consider using
beanUtils.copyProperties to ease the moving of data
from the form to the DTO.

You may want to consider using XDoclet or DynaForms to
ease the burden of creating all the forms.  I would be
careful about coding too much in XDoclet for the
back-end to know too much about the front-end though. 
If it is a generic form-bean with coarse-grained
attributes that would be ok.

sandeep
--- Heather Buch <hb...@www.thebuchs.dk> wrote:
> I know the Struts form bean raises a lot of
> discussion. Personally, form beans
> cause me a lot of confusion too, maybe not in the
> same way that they confuse
> others, but maybe so. I'll attempt to explain.
> 
> I feel like it is not consistent whether a form bean
> is first used upon
> creating, or submitting a form.
> 
> Basically, my Action classes fall into two general
> categories:
> 
> 1. "list" action classes which get data from my
> database and put it into a form.
> 2. "save" action classes which take data from the
> form and write to the db.
> 
> As far as I am concerned, this is how use of a form
> bean makes sense to me:
> 
> 1. user requests a form
> 2. "list" action executes and saves some database
> data into a the session or
> request.
> 3. user fills out and submits form
> 4. form bean collects data
> 5. "save" action executes and gets data out of form
> bean
> 
> But sometimes I feel like struts intends for me to
> use a form bean like this:
> 
> 1. user requests a form
> 2. "list" action executes and saves some database
> data into a the session or
> request.
> 3. "list" action creates a form bean and puts data
> into it (I don't like this.
> I don't want to see my form bean until after form is
> submitted)
> 4. user fills out and submits form
> 5. form bean collects data
> 6. "save" action executes and gets data out of form
> bean
> 
> I cannot understand how some of the jsp tags work
> vis a vis form beans.
> 
> For example, if, in a "list" action, I make a list
> of beans of database
> information and set that list in the session, I can
> then use the "html:select"
> tag to retrieve data from the bean I have set in the
> session, and write it to
> the form bean. This makes sense.
> 
> However, if I want to use a prepopulated radio
> button, then, in my "list"
> action I have to get data from the database and put
> it in my *form bean*.
> Based on what I understand, the html:radio
> "property" attribute will only
> prepopulate the radio button if the information
> retrieved from the *form bean*
> via "property" matches the "value" attribute of
> html:radio. But I do not want
> to *retrieve* infromation from my form bean when I
> display my form. I want to
> retrieve information from the bean that my "list"
> action has saved in the
> session. I only want to retrieve information from my
> form bean during my
> "save" action. 
> 
> so it seems like the flow of information from
> database to form bean and then
> to action is kind of inconsistent. I hope this makes
> sense. If  you need some
> examples, let me know and I'll try to create them.
> 
> Best,
> 
> Heather Buch
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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