2

I am calling a method on the click of link. The following code works ajaxfully

                        <ui:repeat value="#{myBean.names}" var="name"
                               varStatus="idx">
                        <li>
                            <h:commandLink value="#{name.label}">
                                <f:ajax execute="@this" event="click" render="@all" listener="#{myBean.changeActiveName}" >
                                </f:ajax>
                            </h:commandLink>
                        </li>
                    </ui:repeat>

But when I try to pass parameter to the Ajax call it starts refreshing the whole page

                    <ui:repeat value="#{myBean.names}" var="name"
                               varStatus="idx">
                        <li>
                            <h:commandLink value="#{name.label}">
                                <f:ajax execute="@this" event="click" render="@all" listener="#{myBean.changeActiveName}" >
                                    <f:param name="idx" value="#{idx}" />
                                </f:ajax>
                            </h:commandLink>
                        </li>
                    </ui:repeat>

What is wrong with this code?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Paras
  • 804
  • 1
  • 10
  • 25

1 Answers1

5

The <f:param> has to be a child of the parent UICommand component, not of <f:ajax>.

<h:commandLink value="#{name.label}">
    <f:param name="idx" value="#{idx}" />
    <f:ajax listener="#{myBean.changeActiveName}" render="@all" />
</h:commandLink>

(note that I removed the execute and event attributes as your definitions are the defaults already; plus I wonder how it's useful to send a whole IterationStatus instance as request parameter ... maybe you just wanted to send the index instead? Use #{idx.index} instead or so)

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks. That worked. I got confused by some of the examples I found on stackoverflow. And yes, I have removed defaults too and now using idx.index. Thanks – Paras Aug 06 '12 at 18:29