如何存储多个问题的答案选择

时间:2015-10-06 10:34:09

标签: spring jsf-2

我的数据库中有一组问题和答案:

@Entity
@Table
public class Question implements Serializable{
    @Id
    @SequenceGenerator(name = "question_sequence", sequenceName = "seq_question")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "question_sequence")
    private Long questionId;

    private String question;

    private String choice1;

    private String choice2;

    private String choice3;

    private String choice4;

    private String answer;

    @ManyToOne
    private Exam exam;

    // Snipped getters and setters

}

我想在一个JSF页面中显示他们所有选择的问题。

这是我的控制器类:

@Component
@ManagedBean
public class ExamBean {
    private List<Question> questions;
    private Map<Long, String> questionIdAnswerMap;

    @Autowired
    private ExamService examService;

    public List<Question> getAllQuestion(){
        return examService.getAllQuestion();
    }

    // Getters and setters

}

那是我的JSF页面:

<ui:repeat value="#{examBean.allQuestion}" var="question">
    <h:outputLabel value="#{question.question}"/>
    <h:selectOneRadio value="#{examBean.questionIdAnswerMap}" >
        <f:selectItems itemValue="#{question.choice1}" itemLabel="#{question.choice1}" />
        <f:selectItems itemValue="#{question.choice2}" itemLabel="#{question.choice2}" />
        <f:selectItems itemValue="#{question.choice3}" itemLabel="#{question.choice3}" />
        <f:selectItems itemValue="#{question.choice4}" itemLabel="#{question.choice4}" />
    </h:selectOneRadio>
</ui:repeat>

但这似乎不起作用。谁能告诉我如何使这项工作?

0 个答案:

没有答案