We do a similar thing as Jason explained. We're a couple of steps lighter and not as elegant, but same in philosophy, and effective for us.
In our model, we have a ControlledVocabulary factory which can return a list of ControlledVocabularyItem beans (id,name,description) List states = ControlledVocabularyHome.getItems( "states" ); We basically want to convert this list to an <html:options> list, so we have (on the view side of the fence) a class like so: String optionList = PulldownHelper.getOptionList( "states" ); which just calls the ControlledVocabularHome method, iterates through the list and builds option tags. This is used in a jsp page like so: <html:select property="state"> <%= PulldownHelper.getOptionList( "states" ) %> </html:select> You could also do other nifty things as mentioned below, but we found this to work fine, we can cache in either the model or the view, and it's pretty easy to understand/maintain because there aren't many levels of indirection before getting to the meat of the matter. -Don -----Original Message----- From: Jason Rosen [mailto:JRosen@;yvimail.com] Sent: Thursday, November 07, 2002 2:26 PM To: Struts Users Mailing List Subject: RE: form component reuse best practices? To serve just this purpose: I have created a ListFactory that I initialize using a PlugIn when my Struts app starts. The PlugIn creates an instance of the factory and stashes a reference to it in Application scope. Then my Actions or JSPs use a getList(String listName) method on the stashed ListFactory to get the desired List of ListBeans that represent the List keys and values. My ListFactory also holds its own connection to the Model layer and caches Lists that it has previously retrieved. This gives me a single point of access with caching functionality built-in for all my re-usable HTML drop down list keys and values. Then I created a generic JSP template that I can include into my forms to display the lists and defined a template for it using Tiles. Here is my example: Tiles-def.xml ------------- <!-- ======================================================= --> <!-- Drop Down List definitions --> <!-- ======================================================= --> <definition name="doc.ddList" path="/pages/tiles/ddl/ddlist.jsp"/> <!-- Retrieves allowed Credit Card types --> <definition name="ddl.cc_type" extends="doc.ddList"> <put name="value.ddList" content="CCTYPE" direct="true"/> <put name="value.property" content="cc_type" direct="true"/> </definition> <!-- ======================================================= --> <!-- Form definitions --> <!-- ======================================================= --> <definition name="form.billingForm" extends="doc.templateForm"> <put name="page.formBody" content="/pages/tiles/client/billinfo.jsp"/> <put name="ddl.cc_type" content="ddl.cc_type"/> </definition> /pages/tiles/ddl/ddlist.jsp ---------------------------- <%@ page language ="java" import="zzz.mycompany.Constants" %> <%@ taglib uri="/tags/struts/html" prefix="html" %> <%@ taglib uri="/tags/struts/bean" prefix="bean" %> <%@ taglib uri="/tags/struts/tiles" prefix="tiles" %> <%@ taglib uri="/tags/struts/logic" prefix="logic" %> <%-- Tile that defines a generic Drop Down List Defines component attributes for Drop Down List value.ddList = Listname to retrieve from Factory value.property = Form property to set for value selected by client --%> <tiles:useAttribute id="ddList" name="value.ddList"/> <tiles:useAttribute id="property" name="value.property"/> <bean:define id="factory" name="<%= Constants.LISTFACTORY %>" type="zzz.mycompany.ListFactory"/> <bean:define id="list" name="<%= Constants.LISTFACTORY %>" property='<%= "list(" + ddList.toString() + ")" %>' type="java.util.List"/> <html:select property="<%= property.toString() %>"> <html:options collection="list" labelProperty="description" property="title" /> </html:select> My example may not work as posted above because I have removed some lines of code for easier reading, but you should be able to get the gist of it. Jason Rosen -----Original Message----- From: Andy Kriger [mailto:akriger@;greaterthanone.com] Sent: Thursday, November 07, 2002 9:02 AM To: Struts Users Mailing List Subject: form component reuse best practices? (this is a refinement of a question i asked yesterday) If you have common form components that can be reused multiple times on a page or between projects (e.g. a list of months for date entry, a list of states for address entry), what is the best way to share this code (the html:select/html:option items)? Do you use a backing static bean and html:options to point to that bean? Any ideas would be appreciated. thanks andy kriger -- 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>