0

I have I the following two drop down. I want drop down A on item change to populate Drop down B.This works fine but the problem occurs during submission drop down B is null and I am getting a null validation error. What could I be doing wrong?

 <h:form id="set_up_form">
     <p:messages id="infor" showDetail="false" closable="true"/>
     <p:panelGrid columns="2" id="panel_grid_id">
         <h:outputLabel value="Select Group A"/>
         <p:selectOneMenu styleClass="font" id="group_list"  value="#{myBean.group_A_id}" required="true" requiredMessage="Group Not Selected">  
             <f:selectItem  itemLabel="--SELECT REVENUE GROUP--" itemValue="#{null}"/>
             <f:selectItems value="#{myBean.groupA}"/>   
             <f:ajax render="sub_group_list"/> when I remove this tag and hand code group_A_id in  getGroupB() form is submitted successfully
         </p:selectOneMenu>
         <h:outputLabel value="Select SubGroup"/>
         <p:selectOneMenu styleClass="font" id="sub_group_list"  value="#{myBean.group_B_id}"  >  
             <f:selectItem  itemLabel="--SELECT Group B--" itemValue="#{null}"/>
             <f:selectItems value="#{myBean.groupB}"/>                                                                       
         </p:selectOneMenu>
         <p:commandButton   update="set_up_form" icon="ui-icon-plus" id="btnregister" value="Configure Revenue" action="#{mybean.savevalues}"/>
     </p:panelGrid>
 </h:form>

Here is my Managed Bean

public class MyBean {

    private long group_A_id;
    private long group_B_id;

    // getter and setter     
    public Map<String, String> getGroupA() {
        Map<String, String> map = new LinkedHashMap();
        List<GroupA> grp = DBDao.getGroupARecords();// all values need to be populated
        for (GroupA g : grp) {
            String groupdId = "" + g.getId();
            String groupName = g.getName().toUpperCase();
            map.put(groupName, groupdId);

        }
        return map;
    }

    public Map<String, String> getGroupB() {// values depends on group_id selected from group A dropdown
        Map<String, String> map = new LinkedHashMap();
        List<GroupB> grp = DBDao.getGroupARecords("select from TableB where group_A_id='" + group_A_id + "'");// all values need to be populated
        for (GroupB g : grp) {
            String groupdId = "" + g.getId();
            String groupName = g.getName().toUpperCase();
            map.put(groupName, groupdId);

        }
        return map;
    }

    public void saveConfigs() {
        System.out.println("Successfully Processed" + group_A_id + ":" + group_B_id);

    }
}
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Morgan Denis
  • 111
  • 1
  • 15
  • @Kukeltje Done with formatting. – Morgan Denis Feb 03 '16 at 09:50
  • Tried `p:ajax`? Or adding an explicit event? What is your version info? – Kukeltje Feb 03 '16 at 10:00
  • Ahh... F****ck I missed the 'validation' error in the text and assumed the null value was in the bean... That is what you get with **almost** identical title and introduction where the title is 'wrong'... – Kukeltje Feb 03 '16 at 10:02
  • @Geinmachi the bean is RequestScoped – Morgan Denis Feb 03 '16 at 10:11
  • @BalusC where is the solution link? – Morgan Denis Feb 03 '16 at 10:11
  • @BalusC I clearly dont understand that link what is the best thing I can do to my xhtml? kindly assist am new to jsf – Morgan Denis Feb 03 '16 at 10:15
  • @BalusC I still cant Rectify that error What do need to do on the two drop down for them to work. – Morgan Denis Feb 03 '16 at 10:21
  • @BalusC what is clientId? what does it represent? am getting this error serverError: class javax.el.PropertyNotFoundException Property 'revenue_group_id' not found on type org.primefaces.component.commandbutton.CommandButton – Morgan Denis Feb 03 '16 at 10:29
  • OK, you've after all a different problem: your bean is in wrong scope. Sorry, I reopened your question. Your question is now a duplicate of http://stackoverflow.com/questions/8537464/how-to-save-2-dependent-selectonemenu-values (and I recommend to read http://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope). Still, you will stumble sooner or later on the same problem as described in initial duplicate. Next time, don't try manipulate code in my answers. All of my answers are as-is. – BalusC Feb 03 '16 at 10:32
  • @BalusC thanks I changed Bean to view scoped and everything is ok. And how do I reset the drop down to intial values after submitting? – Morgan Denis Feb 03 '16 at 10:40
  • 1
    What is masked here "*F****ck*" @Kukeltje – Tiny Feb 03 '16 at 10:40
  • 1
    @Tiny was also asking the same instead of helping me that what he wrote – Morgan Denis Feb 03 '16 at 10:42
  • @Tiny, @ MorganDenis: the long version of f*ck.. in the sense that I really were frustrated with myself not reading the question good enough and mist the part about the 'null validation error' and only read the 'null value' from the title... – Kukeltje Feb 03 '16 at 17:26
  • Why would you get frustrated btw? LOL, everyone makes mistake especially in technical stuff. – Plain_Dude_Sleeping_Alone Feb 04 '16 at 14:31

0 Answers0