0

私は PrimeFaces を初めて使用<p:inplace><f:facet>、複数の入力フィールドに使用しようとすると、検証が失敗しても元に戻ります。

コードは次のとおりです。

<p:inplace editor="true">
  <f:facet name="output">
    <h:outputText value="Hello Inplace" />
  </f:facet>
  <f:facet name="input">
    <p:inputText value="#{myBean.name}" required="true" />
    <p:inputText value="#{myBean.age}" required="true" />
  </f:facet>
</p:inplace>

したがって、2 つの入力フィールドを空白のままにすると、出力ファセットに戻りますが、赤い境界線で同じままにしておく必要があります。私を助けてください。ありがとうございました。

4

1 に答える 1

2

同じ問題が発生しているため、ファセットの使用に関連する inplace.isValid() にバグがあると思います。InplaceRenderer の encodeMarkup メソッドからの関連コードを次に示します。ご覧のとおり、入力と出力の名前付きファセットが必要です

protected void encodeMarkup(FacesContext context, Inplace inplace) throws IOException {
    // ...

    boolean validationFailed = context.isValidationFailed() && !inplace.isValid();
    String displayStyle = validationFailed ? "none" : "inline";
    String contentStyle = validationFailed ? "inline" : "none";

    UIComponent outputFacet = inplace.getFacet("output");
    UIComponent inputFacet = inplace.getFacet("input");

    // ...
}

ここで完全なコードを見ることができます: https://github.com/primefaces/primefaces/blob/master/src/main/java/org/primefaces/component/inplace/InplaceRenderer.java

InplaceTemplate の isValid を見ると、inplace の直接の子に対してのみ検証を試行し、他の子孫を再帰しないように見えます (getFacetsAndChildren が子孫ツリーを平坦化しない限り、これは現在調査中です)。ファセットは EditableValueHolder のインスタンスではないため、ファセットの検証も試行せず、true を返します。isValid メソッド全体を次に示します。

public boolean isValid() {
    boolean valid = true;

    for(Iterator<UIComponent> it = this.getFacetsAndChildren(); it.hasNext();) {
        UIComponent component = it.next();
        if(component instanceof EditableValueHolder && !((EditableValueHolder) component).isValid()) {
            valid = false;
            break;
        }
    }

    return valid;
}

https://github.com/primefaces/primefaces/blob/master/src/main/java-templates/org/primefaces/component/inplace/InplaceTemplate.javaで完全なコードを確認できます。

バグを送信する以外にこれに対する解決策があるため、わかりません。

編集

<p:inplace id="inplace" editor="true">
    <f:facet name="output">
        <h:outputText value="#{bean.value}" />
    </f:facet>
    <f:facet name="input">
        <p:inputText id="input" value="#{bean.value}" required="true" requiredMessage="Required field message goes here" />
        <p:message for="input" />
    </f:facet>
</p:inplace>

このようなものに更新することで距離が縮まったため、ファセット内に複数のコンポーネントがあることが問題である可能性があります。

<p:inplace id="inplace" editor="true">
    <p:ajax event="save" update="message" />
    <f:facet name="output">
        <h:outputText value="#{bean.value}" />
    </f:facet>
    <f:facet name="input">
        <p:inputText id="input" value="#{bean.value}" required="true" requiredMessage="Required field message goes here" />
    </f:facet>
</p:inplace>
<p:message id="message" for="input" />

残念ながら、キャンセルを押したときにフィールドとメッセージをリセットすることに関連して、これはまだ少し望まれていますが、少なくとも私たちにとって正しい方向への一歩です.

于 2015-05-07T20:58:56.847 に答える