struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Moritz Björn-Hendrik, HH" <Bjoern.Mor...@fja.com>
Subject AW: Hidden Field in a form. Do I use struts taglib or vanilla ht ml?
Date Fri, 30 Nov 2001 08:45:14 GMT
Ted,

a great idea, but you need to know the name of the actionForm in the
jsp-Page. If you change the name in the struts-config.xml, you have to
change it here, too. Doesn't this hurt struts design principles? Isn't it
better (at least until struts 1.1 is released) to have two methods on the
actionForm-class, one for the values and one for the values, which
internally (i.e. in java-Code) map to a method named getNames?

Björn-H. Moritz

> -----Ursprüngliche Nachricht-----
> Von:	Ted Husted [SMTP:husted@apache.org]
> Gesendet am:	Donnerstag, 29. November 2001 22:19
> An:	Struts Users Mailing List
> Betreff:	Re: Hidden Field in a form.  Do I use struts taglib or
> vanilla html?
> 
> The cleanest thing is to put the ArrayList on the ActionForm. The syntax
> of the options tag is suboptimal, so you need to expose the property as
> a bean. 
> 
> <html:select property="namesId">
> <bean:define id="names" name="actionForm" 
> 	property="names" type="java.util.Collection"/>
> <html:options collection="names" property="value"
> labelProperty="label"/>
> </html:select>
> 
> So, you go through an Action, and have it setup the names list. 
> 
> If there's validation involved, use the same Action as the input path,
> so the list gets made again.
> 
> This also makes it much easier to retrieve the list from a database or
> static class that is on the business tier.
> 
> David Lauta wrote:
> > 
> > Wow,
> > Thanks Ted this is great info.
> > 
> > I have narrowed my problem down to:
> > I want to use a <SELECT> Tag on a form and I want the options to be
> > populated when the form is first displayed.
> > To do this I need to set an ArrayList of valueLabel pairs in the page
> Context
> > 
> >  pageContext.setAttribute("names", actionForm.getNames());
> > // getNames returns an ArrayList
> > // each Item in the arrayList has a getValue() and getLabel() accessor.
> > This works but is coded in the JSP ( tightly coupling the UI with the
> Model ).
> > I'm looking for a way to set the attribute outside of the JSP
> > so that the following will work
> > 
> >   <form:select
> >    property="namesId"
> >    onchange="javascript:submitForm()" >
> >    <form:options collection="names" property="value"
> labelProperty="label" />
> >   </form:select>
> > 
> > In the sequence of events listed below when is the earliest that I can
> obtain the
> > pageContext
> > to call the setAttribute() method on it. I'm guessing that the
> PageContext of the JSP is
> > the same as the
> > ServletContext of the HTTPServlet
> > 
> > Could my problem be related to I am using the ActionForm instead of the
> ActionFormBean
> > class?
> >
> 
> --
> To unsubscribe, e-mail:
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>

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


Mime
View raw message