Hi,
JSF presentation layouts (jsp pages, facelets pages, etc) are not meant
to be programming languages. They are meant only to select specific
parts of a model for presentation to the user.
So asking a backing bean for the "customers model" is fine. And
iterating over list-typed properties of the "customers model" is fine.
But EL isn't designed for invoking backing bean methods *passing* data
from the "customers model"; that is crossing the border from "selecting
data from the model" into a generic computing language.
So you might want to rethink your approach here. If you really cannot
present a static model for the EL to pull data from, then the return
object from #{customerBean.customers} could be your own smart wrapper
class, rather than the actual model object. Then it can offer methods
that can be called via #{customer.offices} rather than trying to do a
method call officebean.offices(customer). But pause before doing this:
the fact that it isn't easy is perhaps telling you that you haven't got
the model-view-controller separation right.
Regards,
Simon
On Fri, 2008-01-04 at 18:27 -0500, M Rather wrote:
> Hello,
>
> A similar problem as discussed in this thread.
>
> How is the following possible in JSF: (note, read the code below as
> pseudo code..., a ui:repeat could be a t:dataTable)
>
> <ui:repeat var="customer" value="#{customerBean.customers}" >
> Customer: #{customer.id} - #{customer.name} -
> <ui:repeat var="office" value="#{officeBean.offices}">
> Office: #{office.id}
> </ui:repeat>
> </ui:repeat>
>
> where officeBean.offices should take #{customer.id} as a property. So
> for each customer displayed, display that customers' offices.
>
> When I define officeBean as managed bean with a property for customerId,
> I see that for all customers the same id is sent (i.e. the first one). I
> think it is similar to the issue discussed before in this thread, that
> when the component is built with the values are bound at that time. The
> resolution at that time was to use 'rendered' attribute for components,
> but how can we resolve this issue where another managed-bean's method
> needs to be invoked in a loop and the current value in the loop needs to
> be provided as a porperty for inner invoked method?
>
> I also tried to define the inner manged bean with scope of 'none',
> assuming that for each invocation it will be created and it will pickup
> the value at that instant.. but I get the following exception:
>
> Property [propertyName] references object in a scope with shorter
> lifetime than the target scope none
>
> Thanks
> MRather
>
>
> M Rather wrote:
> > Thanks Andrew,
> >
> > I got the desired output using the rendered attribute. Though I will
> > test out limitRendered tag as well, I am getting some compile errors
> > on 1.1.7 sandbox snapshot (mvn dependencies).
> >
> > For those who might see this thread, below is the code that works..
> >
> > ==================== ui:repeat with rendered=================<br/>
> > <ui:repeat var="customer" value="${customers}" >
> > ${customer.id} - ${customer.name} -
> > <ui:fragment rendered="#{customer.id eq 1}">
> > YES
> > </ui:fragment>
> > <ui:fragment rendered="#{customer.id ne 1}">
> > NO
> > </ui:fragment>
> > <br/>
> > </ui:repeat>
> > ==================== ui:repeat with
> > rendered=================<br/><br/><br/>
> >
> > and this is the generated result, as desired
> >
> > ==================== ui:repeat with rendered=================
> > 1 - cust1- YES
> > 2 - cust2 - NO
> > 3 - cust3 - NO
> > 4 - cust4 - NO
> > 5 - cust5 - NO
> > 6 - cust6 - NO
> > 7 - cust7 - NO
> > 8 - cust8 - NO
> > 9 - cust9 - NO
> > ==================== ui:repeat with rendered=================
> >
> > -MRather
> >
>