我有以下小册子:
<h:form id="submitForm">
<ui:include src="/inc.xhtml">
<ui:param name="bean" value="#{helloBean}" />
</ui:include>
<ui:include src="/inc.xhtml">
<ui:param name="bean" value="#{myBean}" />
</ui:include>
<h:commandButton />
</h:form>
inc.xhtml
:
<f:subview xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:inputText id="val" value="#{bean.p}" converter="conv"/>
</f:subview>
阅读this和this答案没有帮助,因为在我的情况下,我尝试编写了转换器:
@FacesConverter("conv")
public class ProducerConveter implements Converter{
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
UIInput c = (UIInput) arg0.getViewRoot().findComponent("submitForm:val") ;
Object val = c.getValue(); //NPE
//convertion itself involving the val Object
}
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2){
return ((Producer) arg2).getProducer();
}
}
后来,我注意到实现不可能决定我想要检索哪个组件(从第一个包含或从第二个包含)。
是否有可能从第二个包含中获取组件?
更新
经过一些调试后,我发现第二个包含的组件的实际名称是submitForm:j_idt5:val
。有没有办法明确为任何inlclude而不是j_idt5
指定id?