primefaces组件不更新支持bean

时间:2012-04-09 02:50:38

标签: java jsf primefaces

我正在使用primefaces布局组件,并且难以使用嵌入式表单中的组件:

<p:selectOneRadio id="customRadio" 
                    value="#{exams.examQuestions.currentQuestion.selectedAnswer}"
                    layout="custom">

<f:selectItem itemLabel="Option1" 
                    itemValue="#{exams.examQuestions.currentQuestion.examentry.answer1}"
                    rendered="#{exams.examQuestions.currentQuestion.render_question1}"/>

    <f:selectItem itemLabel="Option2" 
                    itemValue="#{exams.examQuestions.currentQuestion.examentry.answer2}"
                    rendered="#{exams.examQuestions.currentQuestion.render_question2}"/>

    <f:selectItem itemLabel="Option3" 
                    itemValue="#{exams.examQuestions.currentQuestion.examentry.answer3}"
                    rendered="#{exams.examQuestions.currentQuestion.render_question3}"/>

    <f:selectItem itemLabel="Option4" 
                    itemValue="#{exams.examQuestions.currentQuestion.examentry.answer4}"
                    rendered="#{exams.examQuestions.currentQuestion.render_question4}"/>

    <f:selectItem itemLabel="Option5" 
                    itemValue="#{exams.examQuestions.currentQuestion.examentry.answer5}"
                    rendered="#{exams.examQuestions.currentQuestion.render_question5}"/>

    <h:panelGrid columns="1">  
    <p:radioButton id="opt1"
        for="customRadio"
        itemIndex="0"
        rendered="#{exams.examQuestions.currentQuestion.render_question1}"/>  
    <h:outputLabel for="opt1"
        value="#{exams.examQuestions.currentQuestion.examentry.answer1}"
        rendered="#{exams.examQuestions.currentQuestion.render_question1}"/>
    <br/>
    <p:radioButton id="opt2" for="customRadio" 
        itemIndex="1"
        rendered="#{exams.examQuestions.currentQuestion.render_question2}"/>  
    <h:outputLabel for="opt2" 
        value="#{exams.examQuestions.currentQuestion.examentry.answer2}"
        rendered="#{exams.examQuestions.currentQuestion.render_question2}"/>
    <br/>
    <p:radioButton id="opt3" 
        for="customRadio" 
        itemIndex="2"
        rendered="#{exams.examQuestions.currentQuestion.render_question3}"/> 
    <h:outputLabel for="opt3" 
        value="#{exams.examQuestions.currentQuestion.examentry.answer3}"
        rendered="#{exams.examQuestions.currentQuestion.render_question3}"/>
    <br/>
    <p:radioButton id="opt4" 
        for="customRadio" 
        itemIndex="3"
        rendered="#{exams.examQuestions.currentQuestion.render_question4}"/>
    <h:outputLabel for="opt4" 
        value="#{exams.examQuestions.currentQuestion.examentry.answer4}"
        rendered="#{exams.examQuestions.currentQuestion.render_question4}"/>
    <br/>
    <p:radioButton id="opt5" 
        for="customRadio" 
        itemIndex="4"
        rendered="#{exams.examQuestions.currentQuestion.render_question5}"/> 
    <h:outputLabel for="opt5" 
        value="#{exams.examQuestions.currentQuestion.examentry.answer5}"
        rendered="#{exams.examQuestions.currentQuestion.render_question5}"/>
    </p:selectOneRadio>

当我选择不同的项目时,支持bean exams.examQuestions.currentQuestion.selectedAnswer没有更新,怎么回事?如果我从同一个表单调用此组件“customRadio”的更新,那么支持bean会自行更新,但是我无法在表单外部执行此操作。请帮忙!

1 个答案:

答案 0 :(得分:0)

我真的不知道你到底想要什么(因为我在你的示例代码中没有看到任何形式),但我想你的问题是你在最后一个f之后没有关闭p:selectOneRadio: selectItem ...

请仔细查看primefaces showcase selectOneRadio

此外,如果您要从其他表单更新组件,请调用此更新,如update=":formIdOfComponent:componentID"