0

継承された JSF アプリを使用しています。まだかなり新しいです。

私が作業しているページのスクリーンショットは次のとおりです: http://goo.gl/GidpCD。これはいくつかの試験ソフトウェアであり、あなたが見ているのは問題管理です。この画面で、ユーザーは質問を書き、質問のソースを引用し、回答を書き、カテゴリに関連付け、画像を関連付けることができます。

行き詰まっているのは、回答を下に向かって追加/削除するときです。

問題が ViewState にあるのではないかと疑っています。

回答の追加または削除をクリックすると。ページがリロードされ、JSF dataTable コンポーネント内のファイルの関連付けが失われます。ViewState は、ページ上の他のすべてのフォーム要素で維持されます。その dataTable 内のファイルだけが、頭を悩ませているようには見えません。これがその JSF dataTable コンポーネントです (以下にコード全体をリストします)。

<h:dataTable id="table0" value="#{adminQuestions.filesList}" var="file" columnClasses="id,title,selected last" rendered="true" >
    <h:column>
        <f:facet name="header">File</f:facet>
        <h:graphicImage value="#{file.path2}" alt="" />
    </h:column>

    <h:column>
        <f:facet name="header">Title</f:facet>
        <h:outputText value="#{file.title}" />
    </h:column>
    <h:column>
        <f:facet name="header">Select files</f:facet>
        <h:selectBooleanCheckbox value="#{file.selected}" />
    </h:column>
</h:dataTable>

add add answer メソッドを起動する JSF ボタンコンポーネントは次のとおりです。

<h:commandButton value="#{msgs.addButton}" action="#{adminQuestions.addQuestionToAnswerRow}" />

そして、そのadd answer方法は次のとおりです。

public String addQuestionToAnswerRow() {
    if(this.questionToAnswerList.size() < 8) {
        // set the scroll
        if(FacesContext.getCurrentInstance().getMessageList().size() > 0) {
            this.scroll = false;
        }
        else {
            this.scroll = true;
        }
        //Create a new answer, set the current question, and add it to the collection
        Answers answer_local = new Answers();
        QuestionToAnswer qta_local = new QuestionToAnswer();
        answer_local.setTitle(this.inputTextAnswer);
        answer_local.setDescription(this.inputTextAnswer);
        answer_local.setCorrect(this.correctAnswer);
        qta_local.setAnswers(answer_local);
        qta_local.setAnswer(this.questionToAnswerList.size() + 1);
        qta_local.setQuestions(this.question);
        this.questionToAnswerList.add(qta_local);
        // reset the input fields
        this.inputTextAnswer = "";
        this.correctAnswer = false;

        List<File1> thisFilesList = getFilesList();

        QuestionsToFiles qtf;
        List<QuestionsToFiles> qtfc = new ArrayList<QuestionsToFiles>();
        if(this.filesList != null) {
            for(Iterator<File1> entries = this.filesList.iterator(); entries.hasNext();) {
                File1 file_temp = entries.next();
                if(file_temp.isSelected()) {
                    qtf = new QuestionsToFiles();
                    qtf.setQuestions(this.question);
                    qtf.setFile1(file_temp);
                    qtfc.add(qtf);
                }
            }
        }

        return null;
    }
    else {
        JSFUtils.addErrorMessage("No more than eight answers are allowed: ", "The question cannot have more than eight answers");
        return null;
    }
}

これは、delete メソッドを起動する JSF ボタン コンポーネントです。

<h:commandButton value="#{msgs.deleteButton}" action="#{adminQuestions.deleteQuestionToAnswerRow(a)}" />

そして削除方法:

public String deleteQuestionToAnswerRow(QuestionToAnswer qta_local) {
    // set the scroll
    if(FacesContext.getCurrentInstance().getMessageList().size() > 0) {
        this.scroll = false;
    }
    else {
        this.scroll = true;
    }
    //Iterate through the category exam collection and delete the associated category so it's reflected on the page
    for (Iterator<QuestionToAnswer> itr = this.questionToAnswerList.iterator(); itr.hasNext();) {
        QuestionToAnswer qta_temp = itr.next();
        if(qta_temp == qta_local) {
            qta_temp.setQuestions(null);
            qta_temp.setAnswers(null);
            itr.remove();
            return null;
        }
    }
    return null;
}

ご覧いただきありがとうございます。

4

0 に答える 0