0

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>
HockChai Lim
  • 1,675
  • 2
  • 20
  • 30

1 Answers1

1

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");
    
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks Balus. I used the binding method because I need to put this input field in two different location on the page. Seems like I've no choice but resort back to use bean property method. I've to declare two of them even though they are actually the same. No big deal, just looks strange – HockChai Lim Aug 14 '13 at 18:21
  • If you clarify the concrete functional requirement for which you apparently thought that this would be the right solution, then you may get a better answer. – BalusC Aug 14 '13 at 19:59