我有一个 JSF 页面,显示文件夹的内容(实际上它是 Dropbox 的帐户内容)。
我正在使用 dataTable 来呈现 ListArray 对象的内容:
<h:dataTable style="text-align: left" width="600" var="dContent" value="#{backedBean.contents}">
<h:column>
<f:facet name="header">
<f:verbatim>NAME</f:verbatim>
</f:facet>
<h:commandButton value="#{dContent.fileName}" action="#{backedBean.updateContents(dContent)}"/>
</h:column>
<h:column>
<f:facet name="header">
<f:verbatim>SIZE</f:verbatim>
</f:facet>
<h:outputText value="#{dContent.size}"/>
</h:column>
</h:dataTable>
但是当我运行此页面时,出现以下错误:
/browse.xhtml @34,110 action="#{backedBean.updateContents(dContent)}" Error Parsing: #{backedBean.updateContents(dContent)}
...
...
Caused by: org.apache.el.parser.ParseException: Encountered " "(" "( "" at line 1, column 28. Was expecting one of:
"}" ...
"." ...
"[" ...
">" ...
"gt" ...
"<" ...
"lt" ...
">=" ...
"ge" ...
...
...
有趣的是,Netbeans 能够自动完成方法名称,所以我认为我的后端 bean 没问题。只有当我调用带有参数的方法时才会出现问题。
有任何想法吗?
非常感谢
最佳答案
EL 2.2 中引入了传递方法参数。因此,只有在支持 Servlet 3.0/EL 2.2 的容器(如 Tomcat 7、Glassfish 3、JBoss AS 6 等)上运行时,这才有可能和 您的 web.xml
是根据 Servlet 3.0 规范声明的。
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
>
<!-- Config here -->
</web-app>
如果不是,请检查 this answer有关获取数据表中当前行的替代方法,或 this answer关于将 EL 实现替换为支持传递方法参数的实现,以便您也可以在 Servlet 2.5/EL 2.1 容器上使用它。
关于jsf - 如何在JSF中调用带参数的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5273729/