Tagged struts2 iterator

I have the following code that does not seem to work. I do not understand why this will not work.

<s:iterator value=%{questions} id="question">
   <s:if test='%{incorrectQs.contains("#question.questionId")}'>
      Print something here
   </s:if>
</s:iterator>

In the above code, basically, I have a method called getQuestions in the action class. This list contains objects of the Exam class, which has a get / set questionId. I also have a list of rightQs that contains strings. I check if errQQ contains a questionId request. if I want to print some text. Although the code above does not work, the code below works fine. Sometimes it works, and sometimes it doesn't ... :(

<s:iterator value=%{questions}>
   <s:if test='%{incorrectQs.contains("${questionId}")}'>
      Print something here
   </s:if>
</s:iterator>

can anyone explain this?

+3
source share
2 answers

, Action, - . s:iterator, , %{foo} , (, ).

. # s:iterator. , , .

public class ActionClass ... {

    private List<Question> mQuestions;
    private Set<Integer> mIncorrectQuestions;

    public String execute() {
        // build/read questions, populate incorrect questions, etc...
        return SUCCESS;
    }

    public List<Question> getQuestions() {
        return mQuestions;
    }

    // does not need to be an inner class
    public class Questions {

        private int mQuestionId;

        public int getQuestionId() {
            return mQuestionId;
        }

        public boolean getIsIncorrect() {
            return mIncorrectQuestions.contains(mQuestionId);
        }
}

JSP:

<s:iterator value='%{questions}'>
    <s:if test='%{isIncorrect}'>
        Question <s:property value='${questionId}'/> is Incorrect!
    </s:if>
</s:iterator>
0
#question.questionId.toString()
0

Source: https://habr.com/ru/post/1714457/


All Articles