Jsf 记录表单无效时单击提交按钮的次数
我正在尝试记录按钮的点击次数。 1.应记录表单无效时的单击次数。表单中的字段值1为整数。因此,它也应该考虑转换误差。 2.在备份bean时要执行的操作 我试过在ajax上使用listenerJsf 记录表单无效时单击提交按钮的次数,jsf,jsf-2,jsf-2.2,Jsf,Jsf 2,Jsf 2.2,我正在尝试记录按钮的点击次数。 1.应记录表单无效时的单击次数。表单中的字段值1为整数。因此,它也应该考虑转换误差。 2.在备份bean时要执行的操作 我试过在ajax上使用listener <h:form id="form"> <h:inputText id="in" name="in" value="#{listenBean.value1}" autocomplete="off"> </h:inputText>
<h:form id="form">
<h:inputText id="in" name="in" value="#{listenBean.value1}" autocomplete="off">
</h:inputText>
<h:commandButton value="Click Me" action="#{listenBean.save}">
<f:ajax execute="@form" render="@form message eventcount" />
</h:commandButton>
<h:message for="in"/>
Button Clicks: <h:outputText id="eventcount" value="#{listenBean.eventCount}"/>
</h:form>
问题:
当输入字段上的转换错误绑定到bean的整数时,侦听器方法不被调用。我将值输入为“某些文本”。在此期间,不调用侦听器
版本:Mojaraa 2.2.8
这是正确的做法吗。我犯了什么错误吗
有人能帮我吗。这个
不代表应该引用bean(侦听器)方法的方法表达式。它表示一个值表达式,该表达式应该引用一个bean属性,然后该属性将作为(转义)文本输出到响应
最好的方法是挂接组件的preRenderView
事件,并检查当前请求是否表示回发请求
<h:form id="form">
<h:commandButton ...>
<f:ajax execute="@form" render="@form" />
</h:commandButton>
Button Clicks:
<h:outputText id="eventcount" value="#{listenBean.eventCount}">
<f:event type="preRenderView" listener="#{listenBean.incrementEventCount}" />
</h:outputText>
</h:form>
请注意,render=“@form”
已经覆盖了整个表单,因此不需要在同一表单中指定单个组件。如果您在同一表单中有另一个ajax操作,您不想计算该事件,那么请确保render=“…”
足够具体,它不包含eventcount
组件。感谢您给出了明确的答案。是否可以在commandButton上使用相同的f:event,以及添加与click相同的EventType?是的,您可以在任何想要的组件上使用它。否,f:event侦听服务器端事件,而不是客户端事件。服务器上不会出现单击。有关有效(标准)f:event值的概述,请参阅您也可以添加自定义值,这里可以找到一个启动示例
<h:form id="form">
<h:commandButton ...>
<f:ajax execute="@form" render="@form" />
</h:commandButton>
Button Clicks:
<h:outputText id="eventcount" value="#{listenBean.eventCount}">
<f:event type="preRenderView" listener="#{listenBean.incrementEventCount}" />
</h:outputText>
</h:form>
private int eventCount;
public void incrementEventCount(ComponentSystemEvent event) {
if (FacesContext.getCurrentInstance().isPostback()) {
eventCount++;
}
}
public int getEventCount() {
return eventCount;
}