struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Rosen" <JRo...@yvimail.com>
Subject RE: form component reuse best practices?
Date Thu, 07 Nov 2002 19:26:15 GMT
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>


Mime
View raw message