1

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

Community
  • 1
  • 1
Ray
  • 1,788
  • 7
  • 55
  • 92
  • 1
    why areyou using JSTL in a jsf 2 project? Much better to use the jsf `` tag – Steve Atkinson Nov 17 '12 at 21:09
  • @SteveAtkinson because I read about problems with output Map in jsf – Ray Nov 17 '12 at 21:19
  • 1
    where? I've never had problems using maps or lists with ui:repeat. The problem with JSTL tags is that they execute in the wrong part of the lifecycle and cause unexpected results. See http://stackoverflow.com/questions/3342984/jstl-in-jsf2-facelets-makes-sense – Steve Atkinson Nov 18 '12 at 08:50
  • @SteveAtkinson Ok, I try rewrite with . What do you think about my idea with List? May be that's will be the best solution my problem that's why I'm going to use web services – Ray Nov 18 '12 at 09:39

2 Answers2

2

You don't need to concatenate :

itemValue="#{fnc:concat(ans.answer.answerId, entry.key.questionId)}"

could be as simple as :

itemValue="#{ans.answer.answerId}, #{entry.key.questionId}"
Alexandre Lavoie
  • 8,711
  • 3
  • 31
  • 72
1

Why not using your own method to concatenate? You can use a bean named concatenatorBean having method

String customConcat(String str1, String str2) {
   return str1+"_"+str2;
}

Then in getTest.xhtml you can use your own concatenator to solve the problem.

Sazzadur Rahaman
  • 6,938
  • 1
  • 30
  • 52