Page reuse

How do I write a JSF page so that it can be "called" by different pages of my application, producing a result that can be immediately displayed by the caller?

This is my usecase:

PageA.jsp and PageB.jsp both have a h:dataTable to show a list of elements, but PageA shows the elements in bean "beanA" while PageB shows the elements in bean "beanB". For example

h:dataTable value="#{beanA.myList}"

The two beans are of different types.

Both PageA and PageB have a "FindElements" button that links to the "FindElements.jsp " page. This page lets the user find the elements he wants, and when the "Done" button is clicked, all found elements will be added to the calling page table.

This would be easy to achieve if, before either PageA or PageB was rendered, I could execute some code that would fetch the result of FindElements from somewhere and write it into the appropriate bean.

Can I do this neatly in JSF?

If not, how whould you solve this problem in the most simple way?

Another solution I can think of is to give both beans a common interface and store them in the HttpSession before the call to FindElements, which would fetch the bean instance from the session and fill it with the new values.

I hope someone can show me a better solution.

Thank you.

[1358 byte] By [Xtiana] at [2007-10-2 20:13:31]
# 1

Your solution is called AliasBean from Tomahawk (www.myfaces.org)

You surrond your included page with an alias bean tag. Inside the included page you refer to this alias bean.

Ex:

On the included page:

<h:outputText value="#{genericBean.titleIdentAE}"/>

On the page that includes the included page.

<t:aliasBean alias="#{genericBean}" value="#{bean}" >

<jsp:include page="/components/genericJsp.jsp" flush="true"/>

</t:aliasBean>

pringia at 2007-7-13 22:55:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...