在JSF 1.2中使用EL调用带有参数的方法 [英] Invoking methods with parameters by EL in JSF 1.2

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

问题描述

我正在使用一个数据表,每行都有两个按钮,分别是编辑"和删除".

I am using a datatable and for each row I have two buttons, an "Edit" and a "Delete".

如果所讨论的行满足特定条件,则我需要将这些按钮设为只读(即禁用).我在 JSF 2 中看到可以将参数传递给方法调用. JSF 1.2中有什么等效的东西吗?

I need these buttons to be read-only, i.e. disabled, if a certain condition is met for the row in question. I have seen in JSF 2 that it is possible to pass parameters to method calls. Is there anything equivalent in JSF 1.2?

理想地是我想要的东西(循环变量是 loop ,还有另一个bean helper ,其中包含我想调用的方法):

Ideally what I would like it something like (the looping variable is loop and there is another bean, helper, which contains the method I would like to invoke):

<h:commandButton value="Edit"
                   disabled="#{helper.isEditable(loop.id)}" />

在这种情况下,向bean添加 isEditable 属性没有语义,并且在bean周围创建包装对象也是不现实的.

In this case it does not make semantic sense to add an isEditable attribute to the bean and it is not practical to create a wrapper Object around the bean.

谢谢.

推荐答案

我在JSF 2中看到,可以将参数传递给方法调用. JSF 1.2中有什么等效的东西吗?

将参数传递给方法调用不是不是特定于JSF2.它特定于EL 2.2,后者又是JSP 2.2/Servlet 3.0/Java EE 6的一部分.也应成为Java EE 6的一部分.换句话说,如果将JSF 1.2 Web应用程序部署到与Servlet 3.0兼容的容器(例如Tomcat 7,Glassfish 3等),并且您的web.xml被声明为符合Servlet 3.0规范版本,那么它将仅适用于JSF也是1.x.

Passing parameters to method calls is not specific to JSF 2. It is specific to EL 2.2, which is in turn part of JSP 2.2 / Servlet 3.0 / Java EE 6. JSF 2 just happens to be part of Java EE 6 as well. In other words, if you deploy your JSF 1.2 web application to a Servlet 3.0 compatible container like Tomcat 7, Glassfish 3, etc and your web.xml is declared conform Servlet 3.0 spec version, then it'll just work out the box for JSF 1.x as well.

但是,如果您仍然针对较旧Servlet版本的容器,则需要提供其他EL实现,该实现支持带有参数的调用方法.这些实现之一是 JBoss-EL 只需删除 jboss-el.jar 文件放在您的Web应用程序的/WEB-INF/lib中,并将以下上下文参数添加到web.xml中.这是一个Mojarra特有的示例( Mojarra 是JSF RI的代号):

If you're however still targeting a container of an older Servlet version, then you need to supply a different EL implementation which supports invoking methods with arguments. One of those implementations is JBoss-EL which you can install by just dropping the jboss-el.jar file in /WEB-INF/lib of your webapp and adding the following context parameter to the web.xml. Here's a Mojarra-specific example (Mojarra is the codename of JSF RI):

<context-param>     
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>   
</context-param>

如果将MyFaces用作JSF实现,则需要以下上下文参数:

If you're using MyFaces as JSF implementation, you need the following context parameter instead:

<context-param>
    <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
    <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>   
</context-param>

另请参见:

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