1

答えのある質問を介したループがあります。マップを塗りつぶしたい マップ>チェック済みの回答値

<ui:repeat value="#{test.questionList}" var="question">
                <h:outputText value="#{question.question}"
                    rendered="#{not empty question}" />
                <p:selectManyCheckbox value="#{test.selectedItems[question.questionId]}"
                    layout="pageDirection" converter="#{answerConverter}">
                    <f:selectItems value="#{question.questionAnswers}" var="ans"
                        itemValue="#{ans.answer}" itemLabel="#{ans.answer.answer}" />
                </p:selectManyCheckbox>             
</ui:repeat>

私の豆で私は持っています

private Map<Long, List<Answer>> selectedItems;

    private List<Question> questionList;
    private Map<Long, List<Answer>> questionAnswerMap;

//getter- setter selectedItems

public Map<Long, List<Answer>> getQuestionAnswerMap() {
        if (!selectedItems.isEmpty()) {
            Set<Long> idsSet = selectedItems.keySet();
            for (Long questionId : idsSet) {
                List<Answer> answersOnPassedQuestion = selectedItems
                        .get(questionId);
                questionAnswerMap.put(questionId, answersOnPassedQuestion);
            }
        }
        return questionAnswerMap;

    }
public void setQuestionAnswerMap(Map<Long, List<Answer>> questionAnswerMap) {
    this.questionAnswerMap = questionAnswerMap;
}

また、モデルクラスを示します

public class Question implements Serializable{

    private Long questionId;
    private String question;
    private Integer complexity;
    private Set<QuestionAnswer> questionAnswers;
}

QuestionAnswerこのようなモデルクラスもどこにありますか

public class QuestionAnswer implements Serializable{

    private QuestionAnswerIdentifer questionAnswerIdentifer;
    private Answer answer;
}

componentId としてサービスを提供し、そこから構成される QuestionAnswerIdentifer クラスLong answerId, Long questionId

「テスト合格ボタン」を押すとエラーが発生する

j_id280458803_1_639e37a6:0:j_id280458803_1_639e37cf: 
        Validation Error: Value is not valid

///UPDATED 私は BalusC の答えを試して、コンバーターを書きます

@ManagedBean
@RequestScoped
public class AnswerConverter implements Converter{  

    @ManagedProperty(value="#{answerService}")
    private IAnswerService  answerService;

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String submittedValue)
            throws ConverterException {     
        Answer answer = new Answer();
        try {
            answer =  answerService.getById(Long.valueOf(submittedValue));
        } catch (DAOException | NumberFormatException e) {          
            e.printStackTrace();
        }
        return answer;
    }

    @Override
    public String getAsString(FacesContext context, final UIComponent component, Object  modelValue)
            throws ConverterException {     

                return String.valueOf(((Answer) modelValue).getAnswerId());
    }

    public void setAnswerService(IAnswerService answerService) {
        this.answerService = answerService;
    }
}

// Answer の equals と hashCode

  @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((answer == null) ? 0 : answer.hashCode());
            result = prime * result
                    + ((answerId == null) ? 0 : answerId.hashCode());
            result = prime * result
                    + ((correctness == null) ? 0 : correctness.hashCode());
            return result;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            Answer other = (Answer) obj;
            if (answer == null) {
                if (other.answer != null)
                    return false;
            } else if (!answer.equals(other.answer))
                return false;
            if (answerId == null) {
                if (other.answerId != null)
                    return false;
            } else if (!answerId.equals(other.answerId))
                return false;
            if (correctness == null) {
                if (other.correctness != null)
                    return false;
            } else if (!correctness.equals(other.correctness))
                return false;
            return true;
        }

しかし、私はまだ同じエラー検証を取得します (なぜこのエラーが発生するのかわかりません

4

1 に答える 1