0

I keep receiving the same exception again and again. Comparing exception and hmtl-output without for="#{choiceRadio.clientId}" seems to tell me that binding works. But it just doesn't and I feel like I am missing something huge.

The Code:

    <p:selectOneRadio binding="#{choiceRadio}" value="#" layout="custom">
        <f:selectItems value="#" />
    </p:selectOneRadio>

    <h:panelGrid columns="1">
        <ui:repeat var='choice' value='#{item.items3}'>
            <p:radioButton for="#{choiceRadio.clientId}" />#{choice.name}
        </ui:repeat>
    </h:panelGrid>

</h:form>

The Exception:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Cannot find component 'j_idt34:0:j_idt36:2:j_idt46:j_idt82' in view.
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
    org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
root cause

javax.faces.FacesException: Cannot find component 'j_idt34:0:j_idt36:2:j_idt46:j_idt82' in view.
    org.primefaces.component.radiobutton.RadioButtonRenderer.findSelectOneRadio(RadioButtonRenderer.java:126)
    org.primefaces.component.radiobutton.RadioButtonRenderer.encodeEnd(RadioButtonRenderer.java:35)
    javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
    com.sun.faces.facelets.component.RepeatRenderer.encodeChildren(RepeatRenderer.java:104)
    com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:523)
    com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:984)
    com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
    com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
    com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
    javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
    com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
    javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
    com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
    javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    org.primefaces.component.lightbox.LightBoxRenderer.encodeMarkup(LightBoxRenderer.java:52)
    org.primefaces.component.lightbox.LightBoxRenderer.encodeEnd(LightBoxRenderer.java:32)
    javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:59)
    org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:43)
    org.primefaces.component.outputpanel.OutputPanelRenderer.encodeEnd(OutputPanelRenderer.java:46)
    javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
    com.sun.faces.facelets.component.RepeatRenderer.encodeChildren(RepeatRenderer.java:104)
    com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:523)
    com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:984)
    com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
    com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
    javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:55)
    org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:43)
    org.primefaces.component.outputpanel.OutputPanelRenderer.encodeEnd(OutputPanelRenderer.java:46)
    javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
    com.sun.faces.facelets.component.RepeatRenderer.encodeChildren(RepeatRenderer.java:104)
    com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:523)
    com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:984)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
    com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
    com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
    javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
note The full stack trace of the root cause is available in the JBoss Web/7.0.13.Final logs.

JBoss Web/7.0.13.Final

Without ui:repeat I don't get any exception but without ui:repeat I do not have any content either:

    <p:selectOneRadio  id="myRadio" value="#{cartBean.selectedChoice}" layout="custom">
        <f:selectItems value="#{item.items3}" />
    </p:selectOneRadio>

    <h:panelGrid columns="1">

            <p:radioButton for="myRadio" value="hh" itemIndex="0"/>

    </h:panelGrid>

</h:form>
Lester
  • 1,830
  • 1
  • 27
  • 44
  • Possible duplicate of http://stackoverflow.com/questions/8634156/how-to-reference-components-in-jsf-ajax-cannot-find-component-with-identifier – perissf Oct 23 '12 at 10:37
  • That's absolutely possible. It was one of the questions/answers I read before. Maybe I didn't really understand as it could not help me in practise. – Lester Oct 23 '12 at 14:19

1 Answers1

2

The for attribute of the radioButton must be the id of the selectOneRadio it refers to.

Add an id to your selectOneRadio and refer to it in the button:

<p:selectOneRadio id="myRadio" binding="#{choiceRadio}" value="#" layout="custom">
    <f:selectItems value="#" />
</p:selectOneRadio>

<h:panelGrid columns="1">
    <ui:repeat var='choice' value='#{item.items3}'>
        <p:radioButton for="myRadio" />#{choice.name}
    </ui:repeat>
</h:panelGrid>

EDIT

You might need to prepend the ids of all NamingContainers right from ViewRoot before the element id, like: for="form_id:myRadio".

When in doubt what the exact absolute id of an element might be, look at it in FireBug (Firefox) or developer tools (Chrome) or search for its given id (in this case "myRadio") in the html output source and skip possible numbers in-between.

So this

id="iterateCategories:0:iterateItems:2:lightForm:radioForm"

would become

iterateCategories:iterateItems:lightForm:radioForm

as your absolute id.

rbento
  • 9,919
  • 3
  • 61
  • 61
kostja
  • 60,521
  • 48
  • 179
  • 224
  • Thanks for your answer but doing this it is quite similar _javax.servlet.ServletException: Cannot find component 'myRadio' in view._ That's where I started... – Lester Oct 23 '12 at 14:17
  • @Lester - then you need to prepend the form id as well - I have added some details to the answer – kostja Oct 23 '12 at 14:53
  • the ids from generated html (without p:radiobutton and thus without exception) is: form id="j_idt34:0:j_idt36:2:form_id – Lester Oct 23 '12 at 16:19
  • @Lester I'm afraid I'll have to resort semi-wild guessing then - the Ids look right. have you tried it without the and with the itemIndex attribute? - if this still does not work, then i must resign :( sorry – kostja Oct 23 '12 at 16:56
  • Without ui:repeat an with itemIndex I get no exception but I lack any content. Here someone made to use ui:repeat with radiobutton but I just can't see, what I do different and why it doesn't work for me: [link](http://stackoverflow.com/questions/9803344/primefaces-radiobutton-inside-a-uirepeat) Actually I tried to solve the ID/binding problem this way: [link](http://stackoverflow.com/questions/8168302/jsf-component-binding-without-bean-property/8168427#8168427) But it just won't work... – Lester Oct 23 '12 at 18:34
  • Thanks for your help, kostja. I just edited your answer a bit to fully solve my problem. Because of me not posting my full code, you could not know that one (actually two) of the preceding NamingContainers was a `ui:repeat`which seems to produce an additional number for the id in the html source that must not be adopted into absolute id of successive elements. – Lester Oct 26 '12 at 04:09