How to pass EL argument in method?

2019-02-27 22:53发布

问题:

I have just a question in passing parameters on backing beans method.

I would like pass an EL value between a method parameters like:

<p:selectOneMenu id="somsgroup" value="#{store_itemController.filter_sgroup}">
   <f:selectItems value="#{commonDataFunctions.getItemByName('store_sgroup', 'id', 'title', '[tb:store_sgroup][fd:title]=${store_itemController.filter_group}', '[tb:store_sgroup][fd:title]', true)}"/>
</p:selectOneMenu>

it seems like ${store_itemController.filter_group} it is not translated because the method receives ${store_itemController.filter_group} just like a string.

Is there a solution?

回答1:

You can indeed not nest EL expressions this way. EL expressions can only be inlined.

You can use <c:set> to create a new variable wherein the desired expression is inlined in the desired value and then reuse this variable as argument of another EL expression.

xmlns:c="http://java.sun.com/jsp/jstl/core"
...
<c:set var="filterGroup" value="[tb:store_sgroup][fd:title]=#{store_itemController.filter_group}" scope="request" />
...
<f:selectItems value="#{commonDataFunctions.getItemByName('store_sgroup', 'id', 'title', filterGroup, '[tb:store_sgroup][fd:title]', true)}"/>


回答2:

I would like to suggest to use JBoss EL. If so, you need to configure as below in web.xml. Download jar file here and reference for previous post.

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


标签: jsf el