8

ページの開発を容易にするために、いくつかの Facelets を作成しました。特に、入力コンポーネント用に一連の Facelets を作成しました。<xxx:input />入力フィールドの周りにラベルを表示するFaceletが1つあります。それを超えて、実際の入力フィールドをレンダリングするような Facelets が<xxx:inputText />あります。<xxx:inputSecret />これらはそれぞれ、 を使用<xxx:input />してラベルを表示します。Facelet は次のようになります。

<html ...>
   <composite:interface>
      ...
   </composite:interface>
   <composite:implementation>
       <label><h:outputText value="#{cc.attrs.labelText}" /></label>

       <composite:insertChildren />
   </composite:implementation>
</html>

Facelet は次の<xxx:inputText />ようになります...

<html ...>
   <composite:interface>
      ...
   </composite:interface>
   <composite:implementation>
      <xxx:input labelText=...>
         <h:inputText id="myinput" ... />
      </xxx:input>
   </composite:implementation>
</html>

<f:validator />すべてが正常にレンダリングされますが、またはその他の検証タグを追加しようとすると問題が発生します。私が読んだことから、Facelet にタグを追加する必要があります。それで、<composite:editableValueHolder name="myinput" targets="myinput" />インターフェイスセクションに行を追加しました。ただし、バリデーターが起動されていることはまだわかりません。私は.xhtmlファイルにこのようなものを持っています...

 ...
    <xxx:inputText value="...">
      <f:validateLength minimum="10" for="myinput" />
    </xxx:inputText>
    ...

入力内容に関係なく、バリデーターが起動することはなく、エラー メッセージも表示されません。同僚は、私が使用しているターゲット ID と、<xxx:input />Facelet によってラップされているという事実が原因であると示唆しました。

ターゲット定義に親コンポーネント ID を組み込む必要がありますか? 私が見逃しているものは他にありますか?<xxx:input />Faceletを除外すれば問題なく動作するので、それが関係しているのではないかと推測していますが、解決方法がわかりません。あなたが提供できるどんな助けも大歓迎です。

4

1 に答える 1

9

の と一致するようにforバリデータの属性を指定する必要があります。name<composite:editableValueHolder>

<xxx:inputText value="...">
  <f:validateLength for="myinput" minimum="10" />
</xxx:inputText>

また、 が両方のコンポジットで<composite:editableValueHolder>指定されていることを確認する必要があります。Mojarra 2.1.12でうまく機能する完全な例を次に示します。input.xhtml

/resources/components/input.xhtml:

<ui:component
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:cc="http://java.sun.com/jsf/composite"
>
    <cc:interface>
        <cc:attribute name="label" required="true" />
        <cc:editableValueHolder name="input" targets="input" />
    </cc:interface>
    <cc:implementation>
       <h:outputLabel for="input" value="#{cc.attrs.label}" />
       <cc:insertChildren />
    </cc:implementation>
</ui:component>

/resources/components/inputText.xhtml:

<ui:component
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:cc="http://java.sun.com/jsf/composite"
    xmlns:my="http://java.sun.com/jsf/composite/components"
>
    <cc:interface>
        <cc:attribute name="label" required="true" />
        <cc:attribute name="value" required="true" />
        <cc:editableValueHolder name="input" targets="input:text" />
    </cc:interface>
    <cc:implementation>
        <my:input id="input" label="#{cc.attrs.label}">
            <h:inputText id="text" value="#{cc.attrs.value}" />
        </my:input>
    </cc:implementation>
</ui:component>

一部での使用法test.xhtml:

<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:my="http://java.sun.com/jsf/composite/components"
>
    <h:head>
        <title>SO question 12188638</title>
    </h:head>
    <h:body>
        <h:form>
            <my:inputText label="foo" value="#{bean.input}">
                <f:validateLength minimum="10" for="input" />
            </my:inputText>
            <h:commandButton value="submit" action="#{bean.submit}">
                <f:ajax execute="@form" render="@form"/>
            </h:commandButton>
            <h:messages/>
        </h:form>
    </h:body>
</html>

以下も参照してください。


具体的な問題とは関係ありませんが<h:outputLabel>

<h:outputLabel value="#{cc.attrs.labelText}" />

そして、明示的な必要なしにテンプレートテキストにELをインライン化できるという事実<h:outputText>?

<label>#{cc.attrs.labelText}</label>

forラベルが参照する必要がある入力要素の ID を参照する属性もラベルにないことに気付きましたか?

<h:outputLabel for="someId" ... />
<h:inputText id="someId" ... />
于 2012-08-30T03:33:50.393 に答える