3
votes

I have a form like below :

<h:form id="x" prependId="false">

      <h:dataTable id="v" value="#{userBean.cdManagerCollection}" var="cd" 
         border="1">

            <f:facet name="header">
                Test Table 
            </f:facet>
            <h:column>
                <f:facet name="header">
                    <h:outputText value="Name" />
                </f:facet>
                <h:inputText id="title" value="#{cd.title}"  />
            </h:column>                                                     
        </h:dataTable>

        <input type="hidden" id='btnName' name="btnName" value="Apply"/>
        <a4j:commandButton  id="btn" value="SUBMIT" action="#{userBean.processCD}" reRender="x"/>

</h:form>

My question is , when I submit a form using a4j:command button and then re-render the same, does the request parameter (btnName in this case which is hidden), is available to access ? (means through facescontext environment variable ? )

Basically , I need to decide on data while returning ${userBean.cdManagerCollection} based on request parameter.

2

2 Answers

1
votes

The value if your <input> element will of course be available as an attribute of HTTP request. In other words, that parameter will be visible as a String in your action method userBean.processCD via a call to:

FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("btnName");

If you would like to take the JSF approach, which I strongly recommend, you would bind the value attribute of a <h:inputHidden> tag to a bean property so that JSF could do the input transformation (validation, conversion, property setting, etc.) on its own:

<h:inputHidden id="btnName" value="#{userBean.btnName}"/>

with a property of your managed bean:

private String btnName;//getter+setter
-1
votes

If you'd read the parameter for btnName from the userBean you would have that parameter already in your userBean:

<input type="hidden" id="btnName" name="btnName" value="#{userBean.btnParameter}" />