Search code examples
jsfmanaged-bean

data from form select menu being passed as null from jsf/html form


I am currently having difficulty passing the value for action variable that is populated when the user selects a select item and clicks the submit button should be written in the logs and not returning null

Value passed using FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); is returning as null, when the first xhtml form is submited

the objective is to pass the value of a selected selection menu from XHTML form1  to XHRML form2 using a managed bean method on the click of a submit button on form1

I am currently having difficulty passing the value for action variable that is populated when the user selects a select item and clicks the submit button should be written in the logs and not returning null

// form1 starts here
 <h:form>
                                        <select id="inputCategory" data-animate-value="#{quickTellerGetCategoryClientBean.inputCategory}" >
                                            <option value="#{null}" Label="-- select one --"/>

                                            <h:dataTable
                                                    value="#{quickTellerGetCategoryClientBean.getCategoryNamesList()}"
                                                    var="item" >

                                                <h:column style="text-align: left">


                                                    <option value="#{item}" label="#{item}" />

                                                </h:column>
                                            </h:dataTable>
                                            <f:param name="action" value="#{item}" />

                                        </select>
                                        <h:commandButton value="Get All Billers" action="#{quickTellerGetCategoryClientBean.chkMe()}">


                                        </h:commandButton>
                                        <h2><h:outputText id="GetCategoryOutput"
                                      value="#{quickTellerGetCategoryClientBean.getSelectedAction()}"/>
                                    </h2>
 </h:form>

// form2 starts here
              <p>
                                        <h:outputText
                                                value="#{quickTellerGetCategoryClientBean.getAttrListener()}" />
                                    </p>
                                    <h:form>

//managed bean starts here

    String attrListener;
    private String inputCategory;


    public String chkMe() {
        return takeMeToAnotherPage("QuickTeller2");
    }

    public String takeMeToAnotherPage(String linkToGo) {
        return linkToGo + "?faces-redirect=true";
    }


    public void setAttrListener(String attrListener) {
        this.attrListener = attrListener;
    }

    //action listener event
    public String getAttrListener() {
        LOGGER.debug("<< inside >attrListener>" );

        Map<String, String> params =
                FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
        action = params.get("action");
        LOGGER.debug("action  is " + action);

        if ("".equals(action) || action == null) {
            return "";
        } else {
            return action;
        }
    }

Solution

  •                                 <h:selectOneMenu
                                            value="#{quickTellerGetCategoryClientBean.inputCategory}"
                                            id="CategorySelected">
                                        <f:selectItem itemLabel="Select..." noSelectionOption="true"/>
                                        <f:selectItems
                                                value="#{quickTellerGetCategoryClientBean.getCategoryNamesList()}"> </f:selectItems>
                                        <f:ajax execute="CategorySelected"/>
                                    </h:selectOneMenu>