You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Mike Kienenberger <mk...@gmail.com> on 2005/05/02 20:26:07 UTC

Best practice for reusing a jsp(x)?

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

Re: Best practice for reusing a jsp(x)?

Posted by Sylvain Vieujot <sv...@apache.org>.
I don't know if this really helps in your case, but have a look at the
x:aliasBean tag.
I use it to have generic subforms, and it works pretty well.

On Fri, 2005-05-06 at 16:28 -0400, Mike Kienenberger wrote:

> Well, it appears that simple reuse like this isn't possible under JSF.
> 
> 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.
> 
> 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 <mk...@gmail.com> 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
> >

Re: Best practice for reusing a jsp(x)?

Posted by Mike Kienenberger <mk...@gmail.com>.
Well, it appears that simple reuse like this isn't possible under JSF.

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.

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 <mk...@gmail.com> 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
>