> Well, it appears that simple reuse like this isn't possible under JSF.


You might check out the Clay component under Struts Shale: 
http://cvs.apache.org/builds/struts/nightly/struts-shale/clay-plugin

This component will allow you to define a sub-tree within a jsp page where the 
component metadata is defined in an XML config file.  The metadata is very 
tiles like in that it allows inheritances.
 
A subtree is added to an existing component tree using a JSP tag.

<sh:clay id="subview" jsfid="template.html" managedBeanName="mybean"/>

The subtree can be formed using three methods:
1)      Tapestry like html templates where a "jsfid" attribute in the html 
binds it to a JSF component.
2)      The composition can be formed using an xml definition.  This option 
gives the most in terms of inheritances and resues.
3)      The subtree can be defined at runtime by a property event of the 
component, shapeValidator="#{fullAddress.createSubtree}. 
  

The attribute "jsfid" is a mnemonic that represents a meta-component definition 
in the XML configuration file or an html fragment.

The �managedBeanName� attribute is the name of the registered bean in the faces 
config.   The value of this attribute is substituted in place of a literal, 
�managed-bean-name� in the clay config.  This allows you to create reusable 
view fragments that are not bound to a single logical bean name.  

Consider the following simple example of an html fragment that is added to the 
jsf component tree.

JSP:
<sh:clay id="subview" jsfid="Template.html" managedBeanName="mybean"/>


Template.html:
  <input jsfid="username" type="text">

clay-config.xml
   <!-- username input widget -->
   <component jsfid="username" extends="inputText" id="username">
      <attributes>
         <set name="required" value="true"/>
         <set name="value" useValueLateBinding="true" 
value="#{managed-bean-name.username}"/>
         <set name="size"  value="20"/>
         <set name="validator" value="#{managed-bean-name.validateUser}"/>
      </attributes>
   </component>


You might find the dialog features in the logon use cases interesting too.  It 
allows you to reuse a jsp page within many page flows where you can insert 
action logic between the transitions of pages to do additional processing 
specific to the flow.

Gary

> 
> What would have been a five-minute task under WebObjects, and maybe a
> five-hour task with Struts/Velocity became a 30-hour ordeal of
> creating a custom composite component
> (HtmlDataTable/UIColumn/UIColumns/UICommand) in JSF, and all of the
> horrors of serialization/saveState/restoreState that it entailed.

You might find the Clay html JSF binding an interesting option.  The runtime 
composition option might solve this problem.

> 
> And I still have to create a new jsp[x] page for every situation where
> this page will be used in order to initialize it with my data.
> 
> It's starting to make me long for the days of chaining struts actions 
> together.
> 
> On the other hand, now that my knowledge has increased, I could
> probably reproduce it from scratch in only a few hours :)
> 
> I'd be willing to provide this as an example component for the
> sourceforge "JSF components" project if there's interest.
> 
> It's an NxM DataTable that uses the following
> RowAndColumnRelationshipDataModel interface as a datasource.  I use it
> to providing a UI to many-to-many database join tables.   The only
> non-standard dependency is for org.apache.myfaces.component.UIColumns.
> 
> It shows off some fun things like how to deal with saving and
> restoring state, how to create indirect Value- and MethodBindings, and
> how to initialize your component with dynamically-created data on
> startup.
> 
> public interface RowAndColumnRelationshipDataModel
> {
>     String getRowCategoryName();
>     String getColumnCategoryName();
>     List getRowList();
>     List getColumnList();
>     String getColumnLabelFor(Object columnObject);
>     String getRowLabelFor(Object rowObject);
>     boolean getValueFor(Object rowObject, Object columnObject);
>     void setValueFor(boolean newValue, Object rowObject, Object columnObject);
>     void update();
> }
> 
> -Mike
> 
> 
> On 5/2/05, Mike Kienenberger <[EMAIL PROTECTED]> wrote:
> > I've got a "RowAndColumnRelationshipsPage.jspx" with an associated
> > RowAndColumnRelationshipsPage backing bean.
> > 
> > I have a large number of row-and-column-based "data source" classes
> > that implement a RowAndColumnRelationshipData interface which will
> > provide the actual data displayed on the page.
> > 
> > However, I can't figure out a clean way to specify a particular source
> > for data when navigating to my page.
> > 
> > For instance, I'd like to initialize the R&CRPage backing bean with an
> > instance of class A when clicking on link A, an instance of class B
> > when clicking on link B, an instance of class C when clicking on link
> > C, etc.
> > 
> > I'm also using Spring if there's some sort of dependency-injection
> > methodology that I've overlooked that I could use in this situation.
> > 
> > I'm hoping this is a case of overlooking the obvious.
> > 
> > Thanks for any suggestions,
> > 
> > -Mike
> >


Reply via email to