2013-10-11 8 views
6

Sto provando a far combaciare bene due componenet compositi nidificandone uno come bambino. Il setup è composto da un lightbox e da un input entrambi con un attributo chiamato "Value". Funziona bene, fino a quando non introduco un numero dinamico di ingressi e quindi devo usare ui: repeat.Componenti compositi con i bambini compositi che mescolano i valori quando utilizzati con ui: ripetizione

bugTest.xhtml

<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:ui="http://java.sun.com/jsf/facelets" 
     xmlns:pw="http://java.sun.com/jsf/composite/components"> 

    <h:head></h:head> 
    <h:body> 
     <pw:lightBox value="Header"> 
      <h:form> 
       <ui:repeat var="input" value="#{BugTestBean.inputs}"> 
        <pw:bugTestInput value="#{input}" /> 
       </ui:repeat> 
      </h:form> 
     </pw:lightBox> 
    </h:body> 
</html> 

Il ui: repeat sembra ottenere l'attributo valore dei due componenti mescolati, e si verifica la seguente eccezione.

Caused by: javax.el.PropertyNotFoundException: /resources/components/bugTestInput.xhtml @15,62 value="#{cc.attrs.value.text}": The class 'java.lang.String' does not have the property 'text'. 
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111) 
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) 
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) 
at javax.faces.component.UIOutput.getValue(UIOutput.java:170) 
at javax.faces.component.UIInput.getValue(UIInput.java:284) 
at com.sun.faces.facelets.component.UIRepeat$SavedState.populate(UIRepeat.java:879) 
at com.sun.faces.facelets.component.UIRepeat.saveChildState(UIRepeat.java:396) 
at com.sun.faces.facelets.component.UIRepeat.saveChildState(UIRepeat.java:402) 
at com.sun.faces.facelets.component.UIRepeat.saveChildState(UIRepeat.java:402) 
at com.sun.faces.facelets.component.UIRepeat.saveChildState(UIRepeat.java:356) 
at com.sun.faces.facelets.component.UIRepeat.setIndex(UIRepeat.java:470) 
at com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:586) 
at com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:1042) 
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1819) 
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) 
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:847) 
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304) 
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105) 
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:847) 
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304) 
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105) 
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:847) 
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1819) 
at com.sun.faces.renderkit.html_basic.CompositeRenderer.encodeChildren(CompositeRenderer.java:78) 
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:847) 
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1819) 
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1822) 
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1822) 
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:447) 
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125) 
at com.ocpsoft.pretty.faces.application.PrettyViewHandler.renderView(PrettyViewHandler.java:159) 
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) 
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) 
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) 
... 33 more 
  1. sembra che il valore del ID viene passato agli ingressi.

  2. hanno ridotto l'esempio al minimo per produrre l'errore.

  3. Ho provato su Mojarra 2.1.26 e 2.2.4.

BugTestBean.java

@ManagedBean(name="BugTestBean") 
@ViewScoped 
public class BugTestBean { 
    private List<BugTestInput> inputs; 

    public BugTestBean() { 
     inputs = new ArrayList<BugTestInput>(); 
     inputs.add(new BugTestInput("Test1")); 
     inputs.add(new BugTestInput("Test2")); 
     inputs.add(new BugTestInput("Test3")); 
     inputs.add(new BugTestInput("Test4")); 
    } 

    public List<BugTestInput> getInputs() { 
     return inputs; 
    } 
} 

bugTestInput.xhtml

<cc:interface> 
    <cc:attribute name="value" /> 
</cc:interface> 
<cc:implementation> 
    <div id="#{cc.clientId}"> 
     <h:inputText id="input" value="#{cc.attrs.value.text}" /> 
    </div> 
</cc:implementation> 

BugTestInput.java

public class BugTestInput { 
    private String text; 

    public BugTestInput(String text) { 
     this.text = text; 
    } 

    public String getText() { 
     return text; 
    } 

    public void setText(String text) { 
     this.text = text; 
    } 
} 

lightbox.xhtml

<cc:interface> 
    <cc:attribute name="value" /> 
</cc:interface> 
<cc:implementation> 
    <div id="#{cc.clientId}"> 
     <h:outputText value="#{cc.attrs.value}" /> 
     <h:panelGroup> 
      <cc:insertChildren /> 
     </h:panelGroup> 
    </div> 
</cc:implementation> 

soluzioni attuali

  1. Rinominare il valore dell'attributo a qualcos'altro sulle correzioni lightbox questo problema.

  2. Anche lasciare il valore di attributo vuoto sulla lightbox funziona.

  3. Non utilizzando l'interfaccia utente: la ripetizione risolverà anche il problema, ma questo non è solido.

Attualmente sto usando 2 attributi sul lightbox e lasciando il valore vuoto quando necessario

<h:outputText value="#{cc.attrs.value}#{cc.attrs.title}" /> 

Follow-up Indipendentemente da ciò che il nome dell'attributo è, se sono gli stessi su entrambi componenti che falliranno. Si tratta di un bug in JSF, ho cercato i bug tracker e la maggior parte delle nuove note di patch senza risultato.

+2

+1 per fornire un SSCCE ben spiegato e chiaro. Ben fatto per la tua prima domanda! –

risposta

0

Hai provato a utilizzare il tag <c:forEach> sotto JSTL, anziché <ui:repeat>? Ho sempre riscontrato problemi con il tag <ui:repeat>.

<c:forEach> dovrebbe funzionare se non si esegue nuovamente il rendering del componente utilizzando le chiamate ajax.

Problemi correlati