[英]<f:ajax> doesn't work on PrimeFaces component
I trying to use the onChange
event of selectOneMenu
, but it doesn't work and the component is not displayed when I add onChange
attribue. 我尝试使用selectOneMenu
的onChange
事件,但是它不起作用,并且在添加onChange
属性时不显示该组件。
Can someone tell me how can I handle the onChange
event of <p:selectOneMenu>
? 有人可以告诉我如何处理<p:selectOneMenu>
的onChange
事件吗?
Here is my view: 这是我的看法:
<p:selectOneMenu id="service" filterMatchMode="startsWith">
<f:selectItem itemLabel="Selectionner un Service : " />
<f:selectItems value="#{newOpProgramme.listeSevice}" var="service" itemValue="#{service.serviceId}" itemLabel="#{service.serviceNom}"/>
<f:ajax event="change" execute="@this" listener="#{newOpProgramme.serviceChange()}" render="nomCdp"/>
</p:selectOneMenu>
And here is the <f:ajax listener>
method in a request scoped bean: 这是请求作用域bean中的<f:ajax listener>
方法:
public void serviceChange() {
System.out.println("change");
}
When I change the menu, however, nothing is been printed. 但是,当我更改菜单时,没有打印任何内容。
How is this caused and how can I solve it? 这是怎么引起的,我该如何解决?
First of all, onChange
is the wrong event name. 首先, onChange
是错误的事件名称。 It's change
. change
。 Secondly, if you intend to call the HTML attribute name, onChange
is also the wrong attribute name. 其次,如果您打算调用HTML属性名称,则onChange
也是错误的属性名称。 It's onchange
. 这是onchange
。
Coming back to your concrete problem; 回到您的具体问题; the standard JSF <f:ajax>
is not compatible with PrimeFaces components. 标准JSF <f:ajax>
与PrimeFaces组件不兼容。 You should be using PrimeFaces own <p:ajax>
instead. 您应该改用PrimeFaces自己的<p:ajax>
。
<p:selectOneMenu ...>
...
<p:ajax listener="#{newOpProgramme.serviceChange()}" update="nomCdp" />
</p:selectOneMenu>
Note that I omitted the event
and the process
attributes. 请注意,我省略了event
和process
属性。 They both have already the right default value of valueChange
and @this
respectively. 它们都已经分别具有正确的默认值valueChange
和@this
。
When I want to update something after change in selectOneMenu, I use <f:ajax>
tag inside selectOneMenu like this: 当我想在selectOneMenu中进行更改后更新某些内容时,我在selectOneMenu中使用<f:ajax>
标签,如下所示:
<h:selectOneMenu value="#{bean.selected}" >
... select items here
<f:ajax event="change" execute="@this" render="search" />
</h:selectOneMenu>
Where search is the Id
of the object you want to update. 搜索是您要更新的对象的Id
。
Other solution is that you should try onchange
not onChange
. 其他解决方案是您应该尝试onchange
而不是onChange
。
<p:selectOneMenu value="#{someBean.myAttr.id}" valueChangeListener="#someBean.mySelectioMethodListener}">
<f:selectItems value="#{someBean.listAttrs}" var="item"
itemLabel="#{item.name}" itemValue="#{item.id}" />
<p:ajax process="@this" update="someElementId" />
</p:selectOneMenu>
You must put an Id for <f:selectItems />
and set your selection on backing bean side by posted ajax itemValue (id). 您必须为<f:selectItems />
放置一个ID,并通过发布的ajax itemValue(id)在后备bean端设置选择。
Server side method bean without a converter: 没有转换器的服务器端方法Bean:
public void mySelectionMethodListener(ValueChangeEvent event) {
ApplicationContext context = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
SomeBeanDao someBeanDao = (SomeBeanDao) context.getBean(SomeBeanDao.class);
myAttr = someBeanDao.byId((Long) event.getNewValue());
System.out.println("value changed...");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.