JSF-关于UIComponent的操作的两个问题 [英] JSF - Two Questions about actions on UIComponent
问题描述
所以,让我向我展示我的麻烦:)
So, let me show us my troubles :)
1-当我单击命令按钮时
<h:commandButton value="Somethings">
<f:setPropertyActionListener target="#{bean.method}" value="some" />
<f:ajax render="rendering"/>
</h:commandButton>
我没有对commandButton
进行任何操作.我只是开ajax电话.如果我在按钮上添加一个动作(如action="bean.myAction
),它将在JSF生命周期的5度阶段执行(好的,只有当我在f:ajax中写入event ="action"时,这才是默认值).正确的?但是默认情况下,通过点击按钮会触发f:ajax吗?因为例如对于一个ListBox,它仅在我编写event ="change"时才被触发(同样,我不应该编写它,因为它是默认设置).
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-当我点击图片
<h:graphicImage value="img/img.png" alt="img">
<f:setPropertyActionListener target="#{bean.method}" value="some" />
<f:ajax event="onclick" render="rendering"/>
</h:graphicImage>
这不起作用.为什么?
与往常一样,谢谢您的帮助!!!
As usual, thanks for the help!!!!
推荐答案
1-当我单击命令按钮时
我对命令按钮不执行任何操作.我只是开ajax电话.如果我在按钮上添加一个动作(例如action ="bean.myAction),它将在JSF生命周期的5°阶段执行
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
f:setPropertyActionListener
也将在第5阶段执行.
The f:setPropertyActionListener
will be executed in the 5th phase as well.
(好的,只有当我在f:ajax中写入event ="action"时,这才是默认设置).正确的?但是默认情况下,通过点击按钮会触发f:ajax吗?因为例如对于一个ListBox,它仅在我编写event ="change"时才被触发(同样,我不应该编写它,因为它是默认设置).
(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).
f:ajax
只是将行为从同步提交更改为异步(部分)提交.通过为父组件的所需事件属性生成一些其他JavaScript代码(例如onclick
,onchange
等,在webbrowser中查看生成的HTML输出)来完成此操作.它在JSF生命周期中没有任何改变.只有呈现的响应才是部分响应,它恰好是要在具有render
属性中定义的ID的组件中进行更新的部分.
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-当我点击图片
这不起作用.为什么?
因为 h:graphicImage
完全不支持f:setPropertyActionListener
.它仅在 UICommand
组件中有效.
Because the h:graphicImage
does not support f:setPropertyActionListener
at all. It only works in UICommand
components.
您想将其包装在h:commandLink
中.
<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>
(以及必要时将CSS生成的<a>
元素引起的边框/下划线样式设置为CSS)
(and if necessary style the border/underline caused by generated <a>
element away with CSS)
这篇关于JSF-关于UIComponent的操作的两个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!