0

アプリケーションに2つのエンティティとバッキングBeanがあります。以下、その簡略化されたバージョン:

コントローラーとモデル:

class BackingBean {
    private List<A> collectionOfA;
    private A currentA;
    private B currentB;

    private String newDescription;

    // accessors

    public void prepareForUpdate(ActionEvent e) {
        currentA = (A) e.getComponent().getAttributes().get("a");
        currentB = (B) e.getComponent().getAttributes().get("b");
    }

    public void save(ActionEvent e) {
        // method to save b
        b.setName("changing the name");
        b.setSomeNumber(2);
        b.setDescription(newDescription);
        entityManager.merge(b);
    }
}

@Entity
class A {
    private String name;

    @OneToMany
    private List<B> bs;
}

@Entity
class B {
    private String name;
    private String description;
    private int someNumber;
}

意見:

<div>
    <!-- some popup with inputs for updating B -->
    <h:inputText value="#{backingBean.currentB}" />
    <h:commandLink actionListener="#{backingBean.save}" />
</div>

<ui:repeat value="#{backingBean.collectionOfA}" var="a">
    <h:outputText>#{a.name}</h:outputText>

    <ui:repeat value="#{a.bs}" var="b">
        #{b.name}
        #{b.description}
        #{b.someNumber}
        <h:commandLink actionListener="#{backingBean.prepareForUpdate}">
            <f:attribute name="a" value="#{a}" />
            <f:attribute name="b" value="#{b}" />
        </h:commandLink>
    </ui:repeat>
</ui:repeat>

commandLinkforをクリックすると、ポップアップが表示されると仮定するとprepareForUpdate()、私の問題は次のとおりです。エンティティを保存すると、currentBエンティティのすべてのフィールドがビューで更新されます。ただし、その直後に、フィールドb.descriptionは古い値で再度レンダリングされます。データベースをチェックすると、実際には、ページを更新した場合と同じように、説明が更新されます。

なぜこれが起こっているのかについて何か考えはありますか?

4

0 に答える 0