Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
410 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...