How to pass dynamic parameter to backing bean using EL 2.2 method expression? [duplicate]

我的梦境 提交于 2019-12-22 14:03:19

问题


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>

The method in the backing bean:

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

How is this caused and how can I solve it?


回答1:


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

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

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.

See also:

  • How can I pass selected row to commandLink inside dataTable?


来源:https://stackoverflow.com/questions/8714410/how-to-pass-dynamic-parameter-to-backing-bean-using-el-2-2-method-expression

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!