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

查看:85
本文介绍了如何在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:遇到了 ("("在第28行的第1行.期望以下其中之一:
}" ...
." ...
"[" ...
>" ...
"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>

如果不是,请检查这个答案,关于用支持传递方法参数的EL替换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天全站免登陆