21

In my JSF 2.0 (on JBoss AS 7) project, I would like on my ajax submitted forms to display a little icon status triggered on begin and complete phases, to let the end user know that something is still happening.

The primefaces p:ajaxStatus is not useful here, as I'd like to have many different icons at different places in my page.

I found a bit of the solution in this question: "How show different ajax status in same input?", but I still have a problem: in order to make my javascript function reusable, I need to provide an extra parameter to the call.

I did something like this:

<h:commandLink value="do something boy!">
    <f:ajax render="@form" execute="@form" listener="#{myBean.doStuff}"
        onevent="showProgress" />
    <f:param name="extraParam" value="extraValue" />
</h:commandLink>

and I can see the parameter "extraParam" sent to the server through the request, but in my javascript showProgress method I cannot recover it through the only given parameter.

So my questions is: can I provide to my f:ajax onevent javascript method an additionnal parameter through f:param (or maybe f:attribute, or anything else)?

Community
  • 1
  • 1
Xavier Portebois
  • 3,354
  • 6
  • 33
  • 53

1 Answers1

48

Wrap it in an anonymous function wherein you pass it as extra argument.

<h:commandLink value="do something boy!">
    <f:ajax render="@form" execute="@form" listener="#{myBean.doStuff}"
        onevent="function(data) { showProgress(data, 'extraValue') }" />
</h:commandLink>

with

function showProgress(data, extraParam) {
    // Use "data" argument the usual way.
    // The "extraParam" argument will contain "extraValue" in above example.
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 2
    Can this 'extraValue' be a jsf expression? I mean can be something like `onevent="function(data) { showProgress(data, '#{myBean.whatever}') }` ? Thx! – dcalap Jan 17 '14 at 09:22
  • 2
    Auto-response: Yes, it can be used, :) – dcalap Jan 17 '14 at 09:47