如何使用EL 2.2方法表达式将动态参数传递到支持bean? [英] How to pass dynamic parameter to backing bean using EL 2.2 method expression?

查看:98
本文介绍了如何使用EL 2.2方法表达式将动态参数传递到支持bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的后备bean中通过动态参数从JSF 2.0页面调用一个函数.只要我传递静态字符串,它就可以正常工作,但是当我尝试使用动态字符串时,总是会出现EL解析错误.我猜想这是一个语法问题,但是我想不出另一种使用方法表达式来做到这一点的方法.我知道我可以使用<f:param..../>标记来做到这一点,但我不会放弃这个:)

I'm trying to call a function from a JSF 2.0 page in my backing bean passing a dynamic parameter. It works fine as long as im passing a static string, but when I try using a dynamic one, I always get an EL parsing error. I guess its a syntax problem, but I can't think of another way to do this using method expression. I know that I could do it with the <f:param..../> tag, but I'm not going to give up on this one :)

<h:dataTable  var="urlresult" value="#{search.searchResults_sites_urls}">
    <h:column>
        <h:form>
            <h:outputText value="#{urlresult}" />
            <h:commandLink action="#{search.showUrls(#{urlresult})}" value=" x" />
        </h:form>
    </h:column>
</h:dataTable>

后备bean中的方法:

The method in the backing bean:

public void showUrls(String url) {
    //CODE
}

这是怎么引起的,我该如何解决?

How is this caused and how can I solve it?

推荐答案

嵌套EL表达式#{}是非法的.只需删除嵌套表达式即可.

It's illegal to nest EL expressions #{}. Just remove the nested expression.

<h:commandLink action="#{search.showUrls(urlresult)}" value=" x" />

此外,当您在<h:dataTable>中使用它时,为了使其正常工作,请确保#{search} bean在视图范围内,或者如果确实需要将其请求范围设置,确保在bean初始化期间保留#{search.searchResults_sites_urls}.

Also, as you're using this in a <h:dataTable>, in order to get it to work properly, make sure that the #{search} bean is in the view scope, or if it really needs to be request scoped, make sure that you're preserving the #{search.searchResults_sites_urls} during bean's initialization.

这篇关于如何使用EL 2.2方法表达式将动态参数传递到支持bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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