How to bind a complex object to a composite component
fericit.bostan Dec 16, 2010 3:03 PMI'm using RichFaces 4 M4 and I know this question is not specific to RichFaces, but the forum has been so helpful to me that I was hoping that someone could help me with this.
I have written a composite component (not very complex) that will display a drop-down list of countries and should bind the selection to a provided target bean.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<!-- INTERFACE -->
<composite:interface>
<composite:attribute name="label" required="true" />
<composite:attribute name="requiredMessage" required="true"/>
<composite:attribute name="target" required="true" type="com.mycompany.entity.Country"/>
</composite:interface>
<!-- IMPLEMENATION -->
<composite:implementation>
<h:panelGrid columns="2">
<h:outputLabel for="country-list" value="#{cc.attrs.label}"/>
<h:panelGrid id="country" columns="1" styleClass="select-one-menu-panel" >
<h:selectOneMenu id="country-list"
enabledClass="select-one-menu-enabled" disabledClass="select-one-menu-disabled"
layout="pageDirection"
value="#{cc.attrs.target}"
required="true" requiredMessage="#{cc.attrs.requiredMessage}"
>
<f:selectItem itemLabel="#{msgs['label.pleaseSelect']}" itemValue="" />
<f:selectItems value="#{countryController.countries}" />
<a4j:ajax />
</h:selectOneMenu>
<a4j:outputPanel id="country-list-error-panel" ajaxRendered="true">
<h:message id="country-list-error" for="country-list" style="color:red"/>
</a4j:outputPanel>
</h:panelGrid>
</h:panelGrid>
</composite:implementation>
</html>
I want to be able to use the composite component in the following way:
<util:country-select
label="#{msgs['label.countryOfBirth']}"
requiredMessge="#{msgs['error.birthCountryRequired']}"
target="#{participant.countryOfBirth}"/>
When I load the page everything renders correctly, but when I select an item from the drop-down I get a validation error.
apply-form:j_idt77:country-list: Validation Error: Value is not valid
I know that it must be something with the way that I have the parameters defined but I simply can't find any information to help me figure this out.
Any light that you might be able to she on this would be greatly appreciated.
Thank you for the help...