0

I have an h:inputText, h:selectonemenu and commandbuton. Inputtext is mandatory field and I have defined it as immediate="true". Then I when I click the button I want to pass current value of selectonemenu to managed bean. But its passig null. How can I manage this validation so that it allows me to get the value of selectOneMenu in Managed bean..

My code is..

<h:inputText id="inputSome" required="true" requiredMessage="Pls enter something"/>
        <h:message for="inputSome"></h:message>
        <h:selectOneMenu id="recepients" value="#{controller.selected}" immediate="true">
            <f:selectItem itemLabel="Select" itemValue=""/>
            <f:selectItems value="#{controller.tempNameList1}"></f:selectItems>


        </h:selectOneMenu>

        <p:commandButton value="Add" action="#{controller.submit}"
            immediate="true"/>
Kush Sahu
  • 399
  • 1
  • 13
  • 33
  • 1
    It looks that you haven't bound the `` value to your `controller` attribute (or maybe that's a typo. – Luiggi Mendoza Feb 24 '13 at 16:51
  • As Luiggi Mendoza says, try binding your `h:inputText` to a property into your managed bean. Appart from that, it should take a value. Can you show us your backing bean code? – Aritz Feb 24 '13 at 18:29
  • @LuiggiMendoza Its a example code. If I will bound my h:inputText the problem still remains. It will pass null value to controller. – Kush Sahu Feb 25 '13 at 05:38

1 Answers1

5

When you put immediate=true in the commandButton, then Invoke Application phase is directly executed skipping the phases after (and including) validations. So "applying model values" phase is also skipped and the properties of managed bean are remained uninitialized. This causes you passing null for the value of selectOneMenu. The solution is, you have to retrieve the value for selected property of the controller manually, like bellow:

 Map<String, String> paramMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

    for (String key : paramMap.keySet()) {
        if (key.contains("recepients")) {
            selected = Integer.parseInt(paramMap.get(key));
        }
    } 
Sazzadur Rahaman
  • 6,938
  • 1
  • 30
  • 52