Question

I currently working on an project that needs some "rebuild" but still there is no money on this - so I have to deal with that what's in front of me. I need to display an message on every change of the radioButton as you can see in this code example:

<h:form>
    <h:messages id="msg"/>
    <p:accordionPanel value="#{exerciseBean.getCategoriesInGrade(5)}" var="category">
        <p:tab title="#{category.categoryName}">
            <h:panelGrid columns="1" cellpadding="5"> 
                <ui:repeat value="#{exerciseBean.getSingleChoiceInGrade(5, category.categoryName)}" var="exercise">
                     <div>#{exercise.getText()}</div>
                     <p:selectOneRadio value="#{exerciseBean.data}" > 
                         <f:selectItems value="#{exercise.getChoices()}" var="c" itemLabel="#{c.id}" itemValue="#{c.id}"  />  
                         <p:ajax event="change" process="@this" listener="#{exerciseBean.validateInput(exercise.getId())}" update="msg"/>
                      </p:selectOneRadio>  
                </ui:repeat>
            </h:panelGrid>
        </p:tab>
     </p:accordionPanel>  
</h:form>

As you can see - inside this <h:form> there is directly an <h:messages> with the id msg. Now the problem: I still get the error: "cannot find component with identifier 'msg'". I now tried it with the prefix : but still the same problem. Is there a way to get PrimeFaces/JSF to reference to this "global-id"?

In my backend I send the message like this:

FacesMessage facesMessage = new FacesMessage("Right Answer!");
FacesContext.getCurrentInstance().addMessage(null, facesMessage);

thanks.

Was it helpful?

Solution

  1. You need an id for your form.
  2. You then need to modify the reference to msg in the ajax update attribute.

So the following code change should do it for you.

1.<h:form id="formID" >

2.<p:ajax event="change" process="@this" listener="#{exerciseBean.validateInput(exercise.getId())}" update=":formID:msg"/>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top