JSF + Facelets将bean动作视为属性

时间:2009-08-05 20:52:09

标签: jsf facelets managed el javabeans

伙计们,由于某些原因,EL并没有告诉房产行为。我有这个页面test.xhtml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html   xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core">

<body>

<form action="#{TestBean.test}">
    <p>#{TestBean.status}</p>
    <input type="submit" value="Test Again"/>
</form>

</body>

</html>

TestBean.status是一个字符串属性(有一个getStatus方法),TestBean.test是一个返回“成功”的方法。

每当我调用页面时,我都会遇到此异常:

ERROR [STDERR] 05/08/2009 17:41:07 com.sun.facelets.FaceletViewHandler handleRenderException
SEVERE: Error Rendering View[/etc/test/test.xhtml]
javax.el.ELException: /etc/test/test.xhtml: Bean: test.TestBean, property: test
    at com.sun.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:53)
    at com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
    at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:232)
    at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:239)
    at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:580)
    at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
    at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
    at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:384)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    at java.lang.Thread.run(Unknown Source)

也许这是一个很长的镜头,我可以更好地描述我的环境。但乍一看,任何提示?

TKS

2 个答案:

答案 0 :(得分:0)

据我所知,EL没有调用任意方法的语法。当您应用于MapList或数组以外的任何其他语法时,您使用的语法将查找与该名称对应的属性getter;点是TestBean["test"]的语法糖。

虽然可以为EL定义自定义函数作为JSP标记库的一部分,但它们必须通过静态方法实现。有关如何操作的详细信息,请参阅this tutorial

此功能为currently in the JSR pipeline

答案 1 :(得分:0)

我认为问题是忘记了jsfc属性。

应该是:

<form **jsfc="h:form"** action="#{TestCaseBean.test}">

TKS。