JSF - Primefaces自动完成onselect事件监听器无法正常工作 - Methodnotfound Exception

时间:2013-07-02 20:48:27

标签: ajax jsf-2 primefaces listener primefaces-mobile

项目规范:JSF 2.1.2,Primefaces-Mobile 0.9.5,Primefaces 3.5 我正在尝试使用即时ajax选择实现primefaces的自动完成功能,下面是代码:

<pm:content>
                <p:panel header="header1" toggleable="true" id="panel1">
                    <h:form>
                        <p:autoComplete value="#{analyzerFilterInput.ipAddress}"
                            completeMethod="#{analyzerFilterInput.getIpAddrList}">
                            <p:ajax event="itemSelect"
                                listener="analyzerFilterInput.handleSelect" update="msg" />
                        </p:autoComplete>
                        <p:messages id="msg" />
                    </h:form>
                </p:panel>
                <p:panel header="header2" toggleable="true" id="panel2">
                </p:panel>
            </pm:content>

View-Scoped Class AnalyzerFilterInput

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.application.FacesMessage;

import org.primefaces.event.SelectEvent;

public class AnalyzerFilterInput implements Serializable
{

    private static final long serialVersionUID = 1L;
private String ipAddress;
private List<String> ipAddrs;

    public AnalyzerFilterInput()
    {
        ipAddrs = new ArrayList<String>();
    }

    public String getIpAddress()
    {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress)
    {
        this.ipAddress = ipAddress;
    }
public List<String> getIpAddrList(String query){
        ipAddrs.clear();
        ipAddrs.add("192.168.1.1");
        ipAddrs.add("192.168.1.2");
        ipAddrs.add("192.168.1.3");
        return ipAddrs;
    }

    public void handleSelect(SelectEvent event) {
        Object item = event.getObject();
        FacesMessage msg = new FacesMessage("Selected", "Item:" + item);
        }
}

我收到一个Methodnotfound异常,有人可以帮我解决这个问题吗?

javax.el.MethodNotFoundException: Method not found: com.atr.web.userhome.AnalyzerFilterInput@1026921.handleSelect(org.primefaces.event.SelectEvent)
at com.sun.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:155)
at com.sun.el.parser.AstValue.invoke(AstValue.java:231)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
at org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processCustomListener(AjaxBehaviorListenerImpl.java:70)
at org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processArgListener(AjaxBehaviorListenerImpl.java:59)
at org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:47)
at org.primefaces.event.SelectEvent.processListener(SelectEvent.java:40)
at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:102)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:760)
at org.primefaces.component.autocomplete.AutoComplete.broadcast(AutoComplete.java:381)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:681)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:452)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1083)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:379)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1017)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:445)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:260)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:225)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:596)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:527)
at java.lang.Thread.run(Thread.java:722)

我可以找到与我的问题相关的Listening to onSelect events from Autocomplete (Primefaces) component,但3.5版本中的primefaces自动完成没有selectlistener属性。

1 个答案:

答案 0 :(得分:3)

您需要bean和范围注释才能访问bean:

@ManagedBean
@SessionScoped,@ViewScoped...