I have just one idea as realize getting user's answers. I decide use List<String> questionsWithAnswers
and put in this list pairs like '1_1', '1_2', '1_3', '2_1'. Something like this. But even with this idea I have a problem. And also important I'll use web-service (it's a constraint for using map for example as structure for saving pairs question and answer).
******** My bean ********
public class TestBean implements Serializable{
private static final long serialVersionUID = 1L;
private List<Test> testList;
private List<Answer> answerList;
private List<Subject> subjectList;
private Map<Question, List<QuestionAnswer>> mapQestionsWithAnswers;
private List<String> questionAnswerList;
private Long subjectId = 0L;
private Test test;
//...
}
getTest.xhtml
<c:forEach items="#{test.testBean.mapQestionsWithAnswers}"
var="entry">
<h:inputHidden value="#{entry.key.questionId}" />
<h:outputText value="#{entry.key.question}" rendered="#{not empty entry.value}"/>
<h:selectManyCheckbox value="#{test.testBean.questionAnswerList}" layout="pageDirection">
<f:selectItems value="#{entry.value}" var="ans"
itemValue="#{fnc:concat(ans.answer.answerId, entry.key.questionId)}"
itemLabel="${ans.answer.answer}" />
</h:selectManyCheckbox>
</c:forEach>
<h:commandButton value="#{msgs['page.content.passtest']}" action="#{test.passTest}" />
For concatination questionId with answerId I use concat. I find this in Concatenate strings in JSF/JSP EL and Javascript
But I cant get value entry.key.questionId
inside itemValue="#{fnc:concat(ans.answer.answerId, entry.key.questionId)}"
I don't understand why.
Where can I make a mistake? And I want to ask some source on more logic and simple decision similar problem. Thanks