Primefaces自动完成错误completeMethod

时间:2015-11-05 09:37:59

标签: jsf primefaces autocomplete

我有关于primefaces自动完成的问题。 jsf页面如下:

<h:inputText class="form-control" style="" for="villeRecherche"/>
<p:autoComplete id="villeRecherche"
value="#{rechercheRestoMb.selectedVille}"
completeMethod="#{rechercheRestoMb.completeVille}"
converter="convertisseurVille" var="c" itemLabel="#{c.ville}"
itemValue="#{c}" forceSelection="true" required="true" />

当调用jsf时,我有这个服务器500错误:

javax.el.ELException: /corpsIndex.xhtml: The class 'fr.afcepf.al25.projetResto.managedBean.RechercheRestoMb' does not have the property 'completeVille'.
    com.sun.faces.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:94)
    com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
    com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
    javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
    com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
    com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
    com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)

我的ManagedBean是RechercheRestoMb,它包含方法completeVille

如果我使用getter和setter插入public String completeVille,我没有错误,但自动完成功能不起作用。

任何人都有这个问题的想法吗?

1 个答案:

答案 0 :(得分:1)

javax.el.ELException: /corpsIndex.xhtml: The class 'fr.afcepf.al25.projetResto.managedBean.RechercheRestoMb' does not have the property 'completeVille'.

This exception means that the EL expression is being interpreted as a property value expression (which requires a getter method), not as a method expression. Basically, it couldn't find the getCompleteVille() method. However, you actually shouldn't need one. There's more at matter.

Look closer at the stack trace what happened during rendering:

com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
javax.faces.render.Renderer.encodeChildren(Renderer.java:168)

UILeaf>UIInstructions is the Facelets representation for EL in template text like so

<p>Welcome, #{user.name}</p>

This is unexpected as you declared the EL expression in a <p:autoComplete> component which should appear as org.primefaces.component.autocomplete.AutoComplete in that line. This thus means that the <p:xxx> tag library is not recognized and is interpreted as template text and thus remain unparsed during generating the HTML output. In effects, you're sending <p:autoComplete> plain vanilla to webbrowser instead of letting JSF generate its HTML output.

This in turn can have several causes, the most common being:

  • You didn't install PrimeFaces (just drop JAR in /WEB-INF/lib).
  • You didn't declare its XML namespace (use xmlns:p="http://primefaces.org/ui").