0

I've got a set of questions and answers in my database:

@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

}

I want to show all questions with their choices in one JSF page.

Thats my controller class:

@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

}

And that is my JSF page:

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

But that does not seem to work. Can anyone tell me how to make this work?

Tobias Liefke
  • 8,637
  • 2
  • 41
  • 58
eatSleepCode
  • 4,427
  • 7
  • 44
  • 93

0 Answers0