[英]PrimeFaces 3.2 selsectOneMenu valueChangeListener not working
i wish to retrieve List based on the selection of dropdownlist item. 我希望根据下拉列表项的选择检索列表。 for that i am using the following code which is not working:
因为我使用以下代码不起作用:
<p:selectOneMenu style="width: 150px" value="#{watchBean.exchange}">
<f:selectItem itemLabel="NSE" itemValue="nse"/>
<f:selectItem itemLabel="BSE" itemValue="bse"/>
<p:ajax event="change" update=":frm" listener="#{watchBean.doScripList}" />
</p:selectOneMenu>
bean code: bean代码:
public void doScripList(ValueChangeEvent e)
{
sl=getAllScripByExchange((String)e.getNewValue()); //sl is of type List<MasterScrip>
}
when i debug , i see that the event is not fired and i get the following error: 当我调试时,我看到事件没有被触发,我得到以下错误:
javax.el.MethodNotFoundException: Method not found: beans.watchBean@9ac2e4.doScripList(javax.faces.event.AjaxBehaviorEvent)
at com.sun.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:155)...
when i omit p:ajax the 'exchange' type is also not get/set what is causing this problem? 当我省略p:ajax时,'exchange'类型也没有得到/设置导致这个问题的原因是什么? what is its solution?
它的解决方案是什么?
edited renamed the method to wow() still the same error : 编辑重命名的方法哇()仍然是同样的错误:
javax.el.MethodNotFoundException: Method not found: beans.watchBean@1732d83.wow(javax.faces.event.AjaxBehaviorEvent)
edited : managed bean code 编辑 :托管bean代码
import java.util.List;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.xml.ws.WebServiceRef;
import service.MasterScrip;
import service.StatelessWebService_Service;
@Named(value = "watchBean")
@RequestScoped
public class watchBean {
@WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8080/StatelessWebService/StatelessWebService.wsdl")
private StatelessWebService_Service service;
/** Creates a new instance of watchBean */
public watchBean() {
}
String uname,scripSym,exchange;
Integer scripID;
List<UserTrack> ut;
List<MasterScrip> sl;
public List<MasterScrip> getSl() {
return sl;
}
public void setSl(List<MasterScrip> sl) {
this.sl = sl;
}
public String getExchange() {
return exchange;
}
public void setExchange(String exchange) {
sl=getAllScripByExchange(exchange);
this.exchange = exchange;
}
public void wow(ValueChangeEvent e)
{
sl=getAllScripByExchange((String)e.getNewValue());
// setSl(sl);
//FacesContext.getCurrentInstance().renderResponse();
// sl=getAllScripByExchange(exchange);
}
Try changing 尝试改变
<p:ajax event="change" update=":frm" listener="#{watchBean.doScripList}" />
to 至
<p:ajax event="change" update=":frm" listener="#{watchBean.doScripList()}" />
add parenthesis at the end of the method. 在方法的末尾添加括号。
JSF is looking for a method setDoScripList
in your backing bean, but when adding the parenthesis at the end you're calling this method doScripList
explicitly. JSF正在你的支持bean中寻找一个方法
setDoScripList
,但是当你在末尾添加括号时,你明确地调用了这个方法doScripList
。
Landed on the same problem as yours, but I figured out that the valueChangeListener 登陆与你相同的问题,但我想出了valueChangeListener
public void doScripList(ValueChangeEvent e)
works only when you use <f:ajax>
tag and not when you use <p:ajax>
. 仅在使用
<f:ajax>
标记时才有效,而在使用<p:ajax>
时则不起作用。 But since selectOneMenu is of type <p:selectOneMenu>
, so <f:ajax>
won't work. 但由于selectOneMenu的类型为
<p:selectOneMenu>
,因此<f:ajax>
将不起作用。
I worked out by removing the parameter ValueChangeEvent e
and it worked. 我通过删除参数
ValueChangeEvent e
来解决它并且它工作了。 So try out a no-parameter listener in case of <p:ajax>
tag. 因此,在
<p:ajax>
标记的情况下尝试一个无参数的侦听器。
public void doScripList()
{
sl=getAllScripByExchange(getExchangeName());
}
Note: here you don't have the event parameter so, it sets the new value by calling respective setter methods, and you can access updated values in the listener. 注意:这里没有事件参数,它通过调用相应的setter方法设置新值,并且您可以在侦听器中访问更新的值。 For this case you also need to provide id to selectOneMenu like this:
对于这种情况,您还需要像selectOneMenu一样提供id:
<p:selectOneMenu id="exchangeName" style="width: 150px" value="#{watchBean.exchange}">
...
</p:selectOneMenu>
and then you add get and set methods for exchangeName in your Bean class: 然后在Bean类中为exchangeName添加get和set方法:
private String exchangeName;
public String getExchangeName(){
return exchangeName;
}
public void setExchangeName(String exchangeName) {
this.exchangeName = exchangeName;
}
It is primefaces 3.2 bug, please replace your code as the following. 它是primefaces 3.2 bug,请替换你的代码如下。
<h:selectOneMenu style="width: 150px" value="#{watchBean.exchange}" valueChangeListener="#{watchBean.doScripList}" onchange="submit()">
<f:selectItem itemLabel="NSE" itemValue="nse"/>
<f:selectItem itemLabel="BSE" itemValue="bse"/>
</h:selectOneMenu>
Change your method likes here; 在这里改变你的方法;
public void doScripList(ValueChangeEvent e){
sl = getAllScripByExchange((String)e.getNewValue());
setAllScriptExchange(sl); //please write setAllScriptExchange method yourself
FacesContext.getCurrentInstance().renderResponse();
}
Your page is reloaded, because of onchange event. 由于onchange事件,您的页面会重新加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.