質問

JSF 2でシンプルなメニーコンポジットコンポーネントを作成しています。ただし、文字列属性をコンポジットコンポーネントに渡して、のアクション属性で使用することはできません。u003Ch:commandLink> 。私のコンポーネントは次のように見えます:

<composite:interface>
    <composite:attribute name="title" required="true" type="java.lang.String"/>
    <composite:attribute name="view" required="true" />
</composite:interface>

<!--implementation-->
<composite:implementation>
    <li><h:commandLink action="#{cc.attrs.view}" value="#{cc.attrs.title}" /></li>
</composite:implementation>

アクション文字列をアクション属性に入れるにはどうすればよいですかu003Ch:commandLink>?

役に立ちましたか?

解決

これはhorstmannsを惹きつけているようです:-)

属性「アクション」に名前を付け、リターゲティングを使用する必要があります。それから、そのいくつかの特別なハンドリングキックは、で絶妙な明快さで説明されています(ではありません)

http://docs.oracle.com/javaee/6/javaserverfaces/2.0/docs/pdldocs/facelets/composite/attribute.html

viewdeclarationlanguage.retargetMethodexpressions(ViewHandlerではない)のAPIドキュメントは、私が貼り付けることを許可されていません。

これがあなたのやり方です。

<composite:interface>
    <composite:attribute name="title" required="true" type="java.lang.String"/>
    <composite:attribute name="action" targets="view" required="true" />
</composite:interface>

<!--implementation-->
<composite:implementation>
    <li><h:commandLink id="view" value="#{cc.attrs.title}" /></li>
</composite:implementation>

他のヒント

属性のタイプを次のような方法に定義する必要があります。

<composite:attribute name="view" method-signature="java.lang.String f()"/>

または、一部の属性名はJSFで特別に処理されます。したがって、属性「アクション」に名前を付けると、メソッド署名なしでも機能する必要があります。

<composite:attribute name="action"/>

編集: あなたがアクションを呼び出すことなくビューIDにリンクしたい場合、私はおそらく質問を誤解しました。 h:link の代わりにタグ h:commandLink:

<h:link outcome="#{cc.attrs.view}" value="#{cc.attrs.title}"/>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top