Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Nesting/Nested JSF components

843844Sep 29 2008 — edited Sep 30 2008
Please excuse what should be a rudimentary question, but I can't seem to find any documentation on how to nest JSF components.

For example, given the following objects:
public class Order {
   private Address deliveryAddress;
   private Address billingAddress;
   //getters and setters...
}

public class Address
{
    private String street;
    private String city;
    //getters and setters...
}
and the jsf managed beans:
public class OrderModel {
    private Order order;
    // getters/setters and  jsf state, handlers, etc ...
}

public class AddressModel {
   private Address address;
   // getters/setters and jsf state, handlers, etc ...
}
with faces-config.xml:
...
    <managed-bean>
        <managed-bean-name>orderModel</managed-bean-name>
        <managed-bean-class>OrderModel</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

    <managed-bean>
        <managed-bean-name>addressModel</managed-bean-name>
        <managed-bean-class>AddressModel</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
...
So, my question is, how can I go about writing a reusable order and address component so I can call nest the address component within my order template?

I guess I'm looking for something like (just a guess - not actual working code):


order-template.jspx:
<f:view xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets">
Delivery Address:<br/>
    <ui:decorate template="address-template.jspx">

<!-- can I pass in #{orderModel.order.deliveryAddress} here? -->

    </ui:decorate>

Billing Address:<br/>
    <ui:decorate template="address-template.jspx">

<!-- can I pass in #{orderModel.order.billingAddress} here? or use something other than ui:decorate? -->

    </ui:decorate>
</f:view>
address-template.jspx:
<f:view xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets">
street:<h:inputText value="#{addressModel.address.street}" />
city:<h:inputText value="#{addressModel.address.city}"  valueChangeListener="#{addressModel.onCityChanged}"/>
</f:view>
I'm guessing the solution lies in having the OrderModel contain an AddressModel for the delivery and billing address, then pass #{orderModel.deliveryAddressModel} and #{orderModel.billingAddressModel} into the address template.

So really my question is simply how do I pass those objects into the address-template.jspx?

Many many thanks in advance!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 28 2008
Added on Sep 29 2008
2 comments
383 views