struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Hardy <ahardy.str...@cyberspaceroad.com>
Subject Re: struts-user Digest 1 Jul 2003 13:07:49 -0000 Issue 3513
Date Wed, 02 Jul 2003 11:10:25 GMT
OK, should I understand that all your forms are initially blank, without 
any text in the boxes? That would explain why I was talking confusingly.

Anyway, you are doing fine NOT storing the select-box-data in the form.

What you are doing seems complicated, although I can't really say. It 
doesn't sound like you are using struts in an optimal fashion. There are 
a number of different, quick & easy ways of setting up your 
struts-config, actions and jsps to get a page working. Which one would 
be best for you, I can't say without knowing what your model looks like. 
You may already have the best way.

You can do the select-boxes more easily than you are at the moment. For 
a start I would put the 'ingen' bean into the top of the list of beans 
during your action, so you don't have to worry about it in your JSP. 
Have a look at html-select.jsp in the struts-exercise-taglib.war that 
comes with struts.

As for getting a group of radio buttons to work, I was looking for an 
example in my work and I realised I've never used them. You'd have to 
look on the struts website in the user guide. You would probably iterate 
over a list with a logic:iterate tag to get the values, but I'm not sure 
what you would do to get the property.

Heather Buch wrote:
> Hi Adam, 
> 
> Thanks for the reply.
> 
> In my step #2, I always save the dataset in a bean in the session or request.
>  I never save data in the form bean from an action. If the idea is to save
> data in a form bean before showing the form to the user, than I'm probably
> doing it all wrong.
> 
> Here is an example of what I might do to populate a select menu (and it is
> pretty circuitious, which means it's probably wrong):
> 
> In a typical "list" action, I might do this to save a list of dates 
> in the session:
> 
> List mydates = Constants.getDates();
> session.setAttribute("coursedates", mydates);
> 
> then, in my form bean, I would have these methods (which would 
> only be invoked *after* the form was displayed to the user:
> 
>     public void setPlanlagtChange(String key, Object value ) {
> 	_planlagtdatochanges.put(key, value);
> 	}
> 	
>     public Object getPlanlagtChange(String key) {
> 	return _planlagtdatochanges.get(key);
>     }
> 
>     public Map getPlanlagtChanges() {
> 	return _planlagtdatochanges;
>     }
> 
> Then in my jsp I have this for a select menu. It cycles over the "coursedates"
> list that is in the session. My jsp pages never take anything from the form
> bean. They only write to the form bean:
> 
>  <html:select property="<%= "planlagtChange(" + String.valueOf(planlagtid) +
> ")" %>" value="ingen"> 
> 
>   <html:option value="ingen">  
>   <bean:message key="no.change"/> 
>   </html:option> 
> <!-- cycle over dates for planlagt fag select box -->
>   <html:options name="coursedates"/> 
> <!-- end cycle over dates for planlagt fag select box -->
>   </html:select>
> 
> This works ok for a select menu, but I can't make radio buttons work. I am
> willing to save stuff to the form bean before the user sees the form, but I do
> not understand why they want me to do it that way.
> 
> Best,
> 
> Heather
> 
> ----------------------------------
> Adam Hardy wrote:
> 
> Date: Tue, 01 Jul 2003 13:20:36 +0200
> From: Adam Hardy  <ahardy.struts@cyberspaceroad.com>
> To: Struts Users Mailing List  <struts-user@jakarta.apache.org>
> Subject: Re: where does a form element get and put it's data
> 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


Mime
View raw message