I have a simple JSF 2.0 composite component example.
<!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:cc="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<head>
<title>
A panel box component
</title>
</head>
<body>
<cc:interface>
<cc:attribute name="model" required="true" type="at.test.Person"/>
</cc:interface>
<cc:implementation>
<h:inputText value="#{model.vorname}">
</h:inputText>
</cc:implementation>
</body>
And here is my JSF test page:
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:mc="http://java.sun.com/jsf/composite/mygourmet" >
<h:body>
<h:form>
<mc:inputTest model="#{person}">
</mc:inputTest>
<h:commandButton value=""/>
<h:outputText value="#{person.vorname}"/>
</h:form>
</h:body>
</html>
I want that my composite component saves a string value in a JSF session bean with <h:inputText>
. But the problem is, when I submit the form with the <h:commandButton>
I see the following error:
Caused by: javax.el.PropertyNotFoundException: /resources/mygourmet/inputTest.xhtml at line 18 and column 42 value="#{model.vorname}": Target Unreachable, identifier 'model' resolved to null
at org.apache.myfaces.view.facelets.el.TagValueExpression.getType(TagValueExpression.java:73)
at org.apache.myfaces.shared_impl.renderkit._SharedRendererUtils.findUIOutputConverter(_SharedRendererUtils.java:77)
You need to reference composite component attribute values by #{cc.attrs.<name>}
where <name>
is the attribute name. So, this should do:
<h:inputText value="#{cc.attrs.model.vorname}">
<composite:xxx>
tag documentationUnrelated to the concrete problem, all that <html><head><body>
in the composite is unnecessary. I suggest to use <ui:component>
since that's more clear. See also our composite component wiki page for examples.