Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java p:ajax使用全局HTML id引用<;h:信息>;属性_Java_Ajax_Jsf_Primefaces_Messages - Fatal编程技术网

Java p:ajax使用全局HTML id引用<;h:信息>;属性

Java p:ajax使用全局HTML id引用<;h:信息>;属性,java,ajax,jsf,primefaces,messages,Java,Ajax,Jsf,Primefaces,Messages,我目前正在做一个需要“重建”的项目,但仍然没有钱,所以我必须处理眼前的事情。我需要在radioButton的每次更改上显示一条消息,正如您在下面的代码示例中所看到的: <h:form> <h:messages id="msg"/> <p:accordionPanel value="#{exerciseBean.getCategoriesInGrade(5)}" var="category"> <p:tab title="#

我目前正在做一个需要“重建”的项目,但仍然没有钱,所以我必须处理眼前的事情。我需要在radioButton的每次更改上显示一条消息,正如您在下面的代码示例中所看到的:

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

  • 您的表单需要一个id
  • 然后需要修改ajaxupdate属性中对
    msg
    的引用
  • 因此,下面的代码更改应该可以为您做到这一点

    1.


    2.

    完美答案!非常感谢您-我已经尝试过只使用:msg,但是使用了一个固定的formID和:它的工作原理与它应该的一样!
    FacesMessage facesMessage = new FacesMessage("Right Answer!");
    FacesContext.getCurrentInstance().addMessage(null, facesMessage);