如何在JSF中调用带参数的方法 [英] How to call a method with a parameter in JSF

查看:23
本文介绍了如何在JSF中调用带参数的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 JSF 页面,显示文件夹的内容(实际上它是 Dropbox 的帐户内容).

I' ve a JSF page that shows the content of a folder (really it's a dropbox's account content).

我正在使用 dataTable 来呈现 ListArray 对象的内容:

I'm using a dataTable to render the content of a ListArray object:

<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>

但是当我运行这个页面时,我得到以下错误:

But when I run this page I obtain the following error:

/browse.xhtml @34,110 action="#{backedBean.updateContents(dContent)}"错误解析:#{backedBean.updateContents(dContent)}
...
...
引起:org.apache.el.parser.ParseException:遇到"(" "( "" 在第 1 行,第 28 列.期待以下之一:
"}" ...
."...
"[" ...
">" ...
GT"...
<"...
lt"...
">=" ...
"ge" ...
...
...

/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 没问题.只有当我调用带有参数的方法时才会出现问题.

The funny thing is that Netbeans is able to autocomplete the method name so I image that my backend bean is ok. The problem occurs only when I call a method with a parameter.

有什么想法吗?

非常感谢

推荐答案

传递方法参数是在 EL 2.2 中引入的.因此,只有在支持 Servlet 3.0/EL 2.2 的容器(如 Tomcat 7、Glassfish 3、JBoss AS 6 等web.xml)上运行时,这才是可能的根据 Servlet 3.0 规范声明.

Passing method arguments was introduced in EL 2.2. So this is only possible if you're running on a Servlet 3.0 / EL 2.2 capable container like Tomcat 7, Glassfish 3, JBoss AS 6, etc and your web.xml is been declared as per Servlet 3.0 specification.

<?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 用于获取数据表中当前行的替代方法,或这个答案 关于将 EL 实现替换为支持传递方法参数的实现,以便您也可以在 Servlet 2.5/EL 2.1 容器上使用它.

If you aren't, then check this answer for alternatives with regard to obtaining current row in datatables, or this answer with regard to replacing the EL implementation by one which supports passing method arguments so that you can use it on Servlet 2.5 / EL 2.1 containers as well.

这篇关于如何在JSF中调用带参数的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆