HockChai Lim
HockChai Lim

Reputation: 1713

jsf 1.1 - Passing input value as paramter to action or actionlistner

I'm trying to pass a input value to a jsf action/actionlistner and am having some problems with it: When I try this method, I get EL error saying something about ( is not valid:

<h:inputText binding="#{pageNoInput1 }" style="font-family:verdana;font-size:0.9em;" maxlength="4" size="4"/>
<a4j:commandLink style="font-family:verdana;font-size:0.9em; margin-left:5px;" value="GO" reRender="deviceList, messagesForm" actionListener="#{viewDevicesBean.goToPageNo(pageNoInput1.value)}" />

When I try this method, I'm getting null value in backend bean: event.getComponent().getAttributes().get("pageNo");

<h:inputText binding="#{pageNoInput1 }" style="font-family:verdana;font-size:0.9em;" maxlength="4" size="4"/>
<a4j:commandLink style="font-family:verdana;font-size:0.9em; margin-left:5px;" value="GO" reRender="deviceList, messagesForm" actionListener="#{viewDevicesBean.goToPageNo}">
    <f:param value="#{pageNoInput1.value}" name="pageNo"/>
</a4j:commandLink>

Upvotes: 0

Views: 1097

Answers (1)

BalusC
BalusC

Reputation: 1109570

I'm trying to pass a input value to a jsf action/actionlistner and am having some problems with it: When I try this method, I get EL error saying something about ( is not valid:

This is out the box only supported since Servlet 3.0 / EL 2.2. So if you deploy to a Servlet 3.0 compatible container (Tomcat 7, Glassfish 3, etc), then it'll work fine. However, if you're targeting a Servlet 2.5 container (Tomcat 6, Glassfish 2, etc) then you'd need to install JBoss EL in order go be able to use parameterized methods in EL. But if you're targeting a Servlet 2.4 container (Tomcat 5.5, SJAS, etc), then you're completely out of luck.

See also:


When I try this method, I'm getting null value in backend bean: event.getComponent().getAttributes().get("pageNo");

UIComponent#getAttributes() returns the attributes of the component, which are those <h:someComponent attribute1="value1" attribute2="value2" ...> and those nested <f:attribute name="attribute3" value="value3">, etc. But you're merely adding a <f:param> which does not make any sense in this construct. The <f:param> is not evaluated during the form submit, but during the form display.

You've basically 2 options:

  1. Just don't do it the ridiculous hard way and bind the input value to a bean property the usual way.

     <h:inputText value="#{bean.value}">
    

    The value is instantly available inside the action(listener) method this way.

  2. Give it (and its parent form) a fixed ID.

     <h:form id="formId"><h:inputText id="inputId">
    

    and manually grab it from request parameter map:

     String value = externalContext.getRequestParameterMap().get("formId:inputId");
    

Upvotes: 1

Related Questions