0

ループでレンダリングされたリンクのリストがあります。リンクをクリックすると、Beanプロパティを設定しますselectedIndex。Ajaxパラメーターに渡して実行しようとしていますが、完全なフォームが更新されています。それでもnotificationPreferencesBean.retrievePreferences解雇されていません。このアプローチは正しいですか?

これが私のテンプレートスニペットです:

<ui:repeat value="#{notificationPreferencesBean.userNotificationPreferences}"
   var="userNotificationPreferenceVar" varStatus="idx">
    <li>
        <h:commandLink
           value="#{userNotificationPreferenceVar.notificationClassName.label}"
           styleClass="#{userNotificationPreferenceVar.cssClassName}"
           action="#{notificationPreferencesBean.retrievePreferences}">
           <f:ajax execute="@form" render="@none">
                <f:param value="#{idx}" name="idx" />
           </f:ajax>
        </h:commandLink>
    </li>
</ui:repeat>

そしてここに豆の宣言があります:

@ManagedProperty(value = "#{param.idx}")
private Integer selectedIndex;

興味深いことに、次のコードはAjaxfullyで機能しますが、を呼び出すだけでnotificationPreferencesBean.retrievePreferences、selectedIndexを設定しません(パラメーターを渡していないため、予想どおり)

 <ui:repeat value="#{notificationPreferencesBean.userNotificationPreferences}"
   var="userNotificationPreferenceVar" varStatus="idx">
    <li>
        <h:commandLink
          value="#{userNotificationPreferenceVar.notificationClassName.label}"
          styleClass="#{userNotificationPreferenceVar.cssClassName}"
          action="#{notificationPreferencesBean.retrievePreferences}">
            <f:ajax execute="@form" render="@none" />
        </h:commandLink>
    </li>
</ui:repeat>

それを行う他の方法はありますか?リンクをクリックしたときにselectedIndexプロパティを設定したいだけです。

4

1 に答える 1

1

そのために注釈を使用する必要はありません@ManagedProperty

使用するだけf:setPropertyActionListenerです:

<ui:repeat value="#{notificationPreferencesBean.userNotificationPreferences}"
   var="userNotificationPreferenceVar" varStatus="idx">
    <li>
        <h:commandLink
           value="#{userNotificationPreferenceVar.notificationClassName.label}"
           styleClass="#{userNotificationPreferenceVar.cssClassName}"
           action="#{notificationPreferencesBean.retrievePreferences}">
           <f:setPropertyActionListener value="#{idx}"
               target="#{notificationPreferencesBean.selectedIndex}" />
           <f:ajax execute="@form" render="@none" />
        </h:commandLink>
    </li>
</ui:repeat>
于 2012-08-01T18:08:37.213 に答える