0

I have the following facelet:

<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>

Where 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>

Reading this and this answers wasn't helpful because in my case there's the converter which I tried to write:

@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();
    }

}

Later on, I've noticed that it's impossible for the implementation to decide which component I wanted to retrieve (from the first include or from the second one).

Is it even possible to get the component from the second include?

Update: After some debugging, I figured out that the actual name of the component from the second include was submitForm:j_idt5:val. Is there a way to specify the id explicitly for any inlclude instead of j_idt5?

Community
  • 1
  • 1
St.Antario
  • 26,175
  • 41
  • 130
  • 318
  • `` is a naming container. Assign it an `id` and prepend this `id` while searching its children. – Tiny Aug 08 '15 at 11:39
  • @Tiny Don't see how it will solve the problem. I still don't distinguish the input from the first include and from the second one. – St.Antario Aug 08 '15 at 11:42
  • @Tiny BTW, I just did what you proposed and got an expcetion about duplicating id. Because I have including the same subview twice. – St.Antario Aug 08 '15 at 11:45
  • I don't know the function requirement of yours but it appears that you are looking for a reusable input component. I would have potentially gone with a composite component, If I had needed a reusable component. – Tiny Aug 08 '15 at 11:52
  • @Tiny No, I just misunderstood what you said... I specified the id attribute to be replaced as a parameter: ``. But honestly I don't exactly understand what it works. The id attribute is being resolved at the view build phase, so the attrbutes specified by `ui:include` are resolved at view built time too, right? – St.Antario Aug 08 '15 at 11:56

0 Answers0