18

テンプレートがあり、その定義でいくつかのフォームとボタンを使用しています。

問題は、定義(define)xhtmlファイルがコンポーネント階層を認識していないことです。

たとえば、同じ定義ファイル内の別の形式で要素「table2」を更新したいとします。

テンプレート挿入:

<p:tabView id="nav"> <!-- nav -->
    <ui:insert name="content_nav">content navigation</ui:insert>
</p:tabView>

私の階層「nav」の最初のレベルを定義します

テンプレート定義:

<ui:define name="content_nav">
    <h:form id="form1"> <!-- nav:form1 -->
        <h:dataTable id="table1"/> <!-- nav:form1:table1 -->
        <p:inputText value="#{bean.value}"/>
        <p:commandButton action="..." update="nav:form2:table2"/>
    </h:form>
    <h:form id="form2">
        <h:dataTable id="table2"/> <!-- nav:form2:table2 -->
        <!-- other elements -->
    </h:form>
</ui:define>

私の定義部分では、「nav」を知りたくありません!

これどうやってするの?または、1つの名前付けコンポーネントを上に移動するにはどうすればよいですか?または、親の完全なIDの最上位を変数に保存するにはどうすればよいですか?

時々私は次のようなものを見ました:

update=":table2"

しかし、これに関する情報は見つかりませんでしたか?、JavaEE6のドキュメントには@キーワードが記載されています。

4

5 に答える 5

52

醜いですが、これはあなたのためにうまくいくはずです:

<p:commandButton action="..." update=":#{component.namingContainer.parent.namingContainer.clientId}:form2:table2" />

すでにPrimeFacesを使用しているので、別の方法としてを使用します#{p:component(componentId)}。このヘルパー関数は、ビュールート全体をスキャンして、指定されたIDを持つコンポーネントを探し、そのクライアントIDを返します。

<p:commandButton action="..." update=":#{p:component('table2')}" />
于 2012-01-13T12:59:31.693 に答える
1

醜い答えはうまくいく

update=":#{component.namingContainer.parent.namingContainer.clientId}:form2:table2

主に、開いたダイアログから親データテーブルへの更新がより便利です

于 2013-02-28T15:21:44.290 に答える
1

属性を使用bindingして、JSFコンポーネントにバインドされたEL変数を宣言できます。次に、を使用してこのコンポーネントの絶対クライアントIDにアクセスできますjavax.faces.component.UIComponent.getClientId()。以下の例を参照してください。

<t:selectOneRadio 
   id="yourId"
   layout="spread"
   value="#{yourBean.value}"
   binding="#{yourIdComponent}">
       <f:selectItems value="#{someBean.values}" />
</t:selectOneRadio>
<h:outputText>
   <t:radio for=":#{yourIdComponent.clientId}" index="0" />
</h:outputText>
于 2016-04-25T10:05:56.903 に答える
0

これを試して:

<h:commandButton value="Click me">
    <f:ajax event="click" render="table" />
</h:commandButton>
于 2012-01-13T07:58:46.830 に答える
0

上記の解決策に加えて、サーバー側のロジックに基づいて更新されるコンポーネント(多く)を動的に生成する必要があるという問題がありました(ネストを見つけるのが難しい場合があります)。

したがって、サーバー側のソリューションは、以下を使用する1と同等update=":#{p:component('table2')}"です。org.primefaces.util.ComponentUtils.findComponentClientId( String designId )

// UiPnlSubId is an enum containing all the ids used within the webapp xhtml.
// It could easily be substituted by a string list or similar.
public static String getCompListSpaced( List< UiPnlSubId > compIds ) {

    if ( compIds == null || compIds.isEmpty() )
        return "" ;
    StringBuffer sb = new StringBuffer( ":" ) ;
    for ( UiPnlSubId cid : compIds )
        sb.append( ComponentUtils.findComponentClientId( cid.name() ) ).append( " " ) ;
    return sb.deleteCharAt( sb.length() - 1 ).toString() ;  // delete suffixed space
}

それを使用する他のメソッドを介して呼び出され... update="#{foo.getCompListComputed( 'triggeringCompId' )}"ます。

1public static String getCompListSpaced0() { return ":#{p:component('table2')}" ; } :最初に、式を返すことをあまり考えずに試しました... update="#{foo.getCompListSpaced0()}が、もちろん(フレームワークがどのように機能するかを考えた後:))は解決されず(そのまま返されます)、一部のユーザーが経験した問題を引き起こす可能性があります。また、私のEclipse / JBoss Tools環境は、:#{p.component('table2')}(「:」の代わりに「。」)を書くことを提案しましたが、これは役に立ちませんでした-もちろん。

于 2016-01-21T13:14:48.233 に答える