0

我正在使用 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>

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

4

1 回答 1

0

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

请仔细查看 primefaces 展示selectOneRadio

此外,如果您想从另一个表单更新组件,您可以像这样调用更新update=":formIdOfComponent:componentID"

于 2012-04-09T23:31:02.083 回答