JSF - Two Questions about actions on UIComponent

自闭症网瘾萝莉.ら 提交于 2019-12-11 07:28:58

问题


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!!!!


回答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)



来源:https://stackoverflow.com/questions/4326705/jsf-two-questions-about-actions-on-uicomponent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!