1

So, let me show us my troubles :)

1 - When i click on a commandbutton

<h:commandButton value="Somethings">
    <f:setPropertyActionListener target="#{bean.method}" value="some" />
    <f:ajax render="rendering"/>
</h:commandButton>

I dont do any action to the commandButton. Just i fire the ajax call. If i add an action on the button (like action="bean.myAction) it will be executedat the 5° phase of the JSF lifecycle (allright, only if i write event="action" in the f:ajax, but thats as default). Right? But the f:ajax is fired by cliccing on the button as default? Because for a ListBox for example, it's fired only if i write event="change" (the same, i shouldnt write it, because is as default).

2 - When i click on image

<h:graphicImage value="img/img.png" alt="img">
    <f:setPropertyActionListener target="#{bean.method}" value="some" />
    <f:ajax event="onclick" render="rendering"/>
</h:graphicImage>

This doesnt work. Why?

As usual, thanks for the help!!!!

markzzz
  • 47,390
  • 120
  • 299
  • 507

1 Answers1

1

1 - When i click on a commandbutton

I dont do any action to the commandButton. Just i fire the ajax call. If i add an action on the button (like action="bean.myAction) it will be executedat the 5° phase of the JSF lifecycle

The f:setPropertyActionListener will be executed in the 5th phase as well.

(allright, only if i write event="action" in the f:ajax, but thats as default). Right? But the f:ajax is fired by cliccing on the button as default? Because for a ListBox for example, it's fired only if i write event="change" (the same, i shouldnt write it, because is as default).

The f:ajax just changes the behaviour from a synchronous submit to asynchronous (partial) submit. It does that by generating some additional JavaScript code to the desired event attribute of the parent component (e.g. onclick, onchange, etc, look in generated HTML output in webbrowser). It doesn't change anything in the JSF lifecycle. Only the rendered response will be a partial response which is exactly the part which is to be updated in the component(s) with ID as definied in render attribute.


2 - When i click on image

This doesnt work. Why?

Because the h:graphicImage does not support f:setPropertyActionListener at all. It only works in UICommand components.

You want to wrap it in a h:commandLink instead.

<h:commandLink>
    <f:setPropertyActionListener target="#{bean.method}" value="some" />
    <f:ajax event="action" render="rendering"/>
    <h:graphicImage value="img/img.png" alt="img"/>
</h:commandLink>

(and if necessary style the border/underline caused by generated <a> element away with CSS)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • for the first question : OK. But what I still dont understand is this : for a ListBox, the `f:ajax` is called when che ListBox change for example. (`event="change"`). But for the button? How say that when you press it you need to execute the code on it? Its the default behaviour i think, or i forgot somethings? – markzzz Dec 01 '10 at 17:23
  • The default `f:ajax` event for `UICommand` (actually, `ActionSource`) components is `click`. See also the description of the `event` attribute in the `f:ajax` PDL document which I linked in my answer (all those blueish code parts in my answer are actually links to the official reference documentation). – BalusC Dec 01 '10 at 17:25
  • Uhm. So if i write my own `action="bean.myFunction"` on `commandButton` and i use `f:ajax event="click"` the action won't be executed? – markzzz Dec 01 '10 at 17:30
  • It will be executed. The `f:ajax` only changes it from synchronous (normal/full) submit to an asynchronous (ajaxical/partial) submit. Leaving JSF outside the question, do you understand anyway what the whole point of Ajax is? – BalusC Dec 01 '10 at 17:32
  • So : `f:ajax event="action"` what mean? :) – markzzz Dec 01 '10 at 17:33
  • On `UICommand` components, it has the same meaning/effect as `click`. Edit: actually, I think I see your confusion, it's called `action` in the docs. But actually, the `action` is kind of alias for `click`. Sorry for causing some confusion. – BalusC Dec 01 '10 at 17:34
  • ah OK! :) Regard second point, the button will be displayed only if i write ``. With `` the code fails! – markzzz Dec 01 '10 at 17:36
  • The `onclick` is not a valid event name. You need `click`. The `onclick` is a typical HTML element attribute name. – BalusC Dec 01 '10 at 17:38
  • Ok. I pasted from your suggestion :) Thanks.. **AGAIN**!! – markzzz Dec 01 '10 at 17:38
  • To all readers: I have to rectify myself, the default `event` for `UICommand` components is `action`, not `click`. JSF interprets both differently. It's definitely not an alias. – BalusC Dec 02 '10 at 16:43