问题描述
我有一个简单的JSF 2.0复合组件示例.
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>
这是我的JSF测试页:
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>
我希望我的复合组件使用<h:inputText>
将字符串值保存在JSF会话bean中.但是问题是,当我使用<h:commandButton>
提交表单时,看到以下错误:
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)
推荐答案
您需要通过#{cc.attrs.<name>}
引用复合组件属性值,其中<name>
是属性名称.因此,应该这样做:
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}">
另请参见:
- Java EE 6教程-Facelets-复合组件
- Java EE 6教程-高级复合组件
-
<composite:xxx>
标签文档 - Java EE 6 tutorial - Facelets - Composite Components
- Java EE 6 tutorial - Advanced Composite Components
<composite:xxx>
tag documentation
See also:
无关与具体问题无关,组合中的所有<html><head><body>
都是不必要的.我建议使用<ui:component>
,因为这更加清楚.有关示例,请参见我们的复合组件Wiki页面.
Unrelated 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.
这篇关于如何在cc:implementation中引用cc:attribute中声明的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!