【发布时间】:2011-09-23 00:37:04
【问题描述】:
嗨,有这个奇怪的问题,我正在使用我编写的 Composite Component,并且我从之前使用 CC 的支持 bean(componentType bean)中获取值
我不知道如何比仅显示代码更好地描述这一点。
我会尽量简要介绍一下并删除多余的部分:
这是Composite Component 的定义:
<cc:interface componentType="dynamicFieldGroupList">
<cc:attribute name="coupletClass" />
<cc:attribute name="form" default="@form"/>
<cc:attribute name="list" type="java.util.List" required="true"/>
<cc:attribute name="fieldNames" type="java.util.List" required="true" />
</cc:interface>
<cc:implementation>
<h:dataTable value="#{cc.model}" var="currLine">
<h:column>
<h:outputText id="inner_control_component" value="Inner Look at currLine:#{currLine}"/>
</h:column>
</h:dataTable>
</cc:implementation>
CC bean 定义:
@FacesComponent(value = "dynamicFieldGroupList")
// To be specified in componentType attribute.
@SuppressWarnings({ "rawtypes", "unchecked" })
// We don't care about the actual model item type anyway.
public class DynamicFieldGroupList extends UIComponentBase implements
NamingContainer
{
private transient DataModel model;
@Override
public String getFamily()
{
return "javax.faces.NamingContainer"; // Important! Required for
// composite components.
}
public DataModel getModel()
{
if (model == null)
{
model = new ListDataModel(getList());
}
return model;
}
private List<Map<String, String>> getList()
{ // Don't make this method public! Ends otherwise in an infinite loop
// calling itself everytime.
return (List) getAttributes().get("list");
}
}
以及使用代码:
<ui:repeat var="group" value="#{currentContact.detailGroups}">
<h:panelGroup rendered="#{not empty group.values}">
<h:outputText id="controlMsg" value=" list:#{group.values}" /><br/><br/>
<utils:fieldTypeGroupList list="#{group.values}"
fieldNames="#{group.fields}" coupletClass="utils" />
</h:panelGroup>
</ui:repeat>
id controlMsg 的文本在#{group.values} 中显示正确的值,而在 id inner_control_component 的组件内的控制输出显示之前使用的值。
值第一次是正确的...
我猜这是使用 CC bean 的根本错误,否则可能是 MyFaces 2.1 的错误(我正在使用)
【问题讨论】:
标签: jsf jsf-2 myfaces composite-component