ValueChangeEvent values not getting properly to managed bean in JSF and ajax

Hi friends I developed dynamic input text box from user. when i click submit button that values getting null to managed bean.. so i trying to get the values used input Value Change Event.

when i create 3 input text box . i enter first text box values 6 and when i click second input text box then first input text box values set to be null..

and when i enter second input text box values 10 and when i click third input text box then previous input text box values set to be null..

how can i handle this.. i have attached code..

My Java Server Faces code

   <h:selectOneMenu   class="text_ui"  value="#{bean.s}">
<f:selectItem  itemLabel="--- select ---" noSelectOption="true" />
<f:selectItems value="#{bean.Drop1}" />

</h:selectOneMenu>



 </h:panelGrid>
 <h:panelGrid class="label_ui" border="0"  cellspacing="10"   columns="2" ">        
 <h:commandButton  class="button" value="Enter" action="                                                                                                                     {bean.form}">   </h:commandButton>



            </h:panelGrid>
            </rich:panel>     
        <rich:panel style="width:900px;"> <h:form>
      <rich:dataTable var="info" value="#{bean.val}" >
      <h:column>
       <f:facet name="header">
        <h:outputText value="No"></h:outputText>
       </f:facet>
       <h:outputText value="#{info.serialno}"></h:outputText>
      </h:column>
      <h:column>
      <f:facet name="header">
      <h:outputText value=" Name "></h:outputText>
      </f:facet>

      <h:selectOneMenu id="a" value="#{info.name}" style="display:#{info.flag}"    valueChangeListener="#{bean.removeList}" >
      <f:selectItem itemLabel="Select" itemValue="Select"></f:selectItem>
       <f:selectItems value="#{bean.List}" ></f:selectItems>
       <f:attribute name="serial" value="#{info.serialno}"></f:attribute>
    <f:ajax render="@form" execute="a"></f:ajax>
      </h:selectOneMenu>
      <h:outputText value="#{info.name1}" ></h:outputText>
      </h:column>
      <h:column>
      <f:facet name="header">
      <h:outputText value="count"></h:outputText>
      </f:facet>
       <h:outputText  value="#{info.count}" style="display:#{info.flag2};" class="label_ui"/>
     <h:inputText id="a1"  valueChangeListener="#{bean.countChange}" value="#{info.count}"  style="display:#{info.flag1};" class="text_ui">
     <f:attribute value="#{info.name}" name="name"></f:attribute>
                    <f:attribute value="#{info.serialno}" name="serial"></f:attribute>
                    <f:ajax render="@form" execute="a1"></f:ajax>
     </h:inputText>
      </h:column>
      <h:column>
       <f:facet name="header">
        <h:outputText value="rollno"></h:outputText>
       </f:facet>
       <rich:panel>
      <rich:dataGrid  var="i" value="#{info.roll}"  columns="5">

    <h:column>
               <h:outputText  value="#{i.val1}" style="display:#{i.flag4};" class="label_ui"/>

        <h:inputText id="a2" valueChangeListener="#{bean.getList}" value="#{i.val1}"  style="display:#{i.flag3};" class="text_ui" > 
        <f:attribute value="#{info.name}" name="na"></f:attribute>
                    <f:attribute value="#{info.serialno}" name="serial2"></f:attribute>
                    <f:attribute value="#{i.serialno1}" name="serial3"></f:attribute>
                    <f:attribute value="#{i.val1}" name="val"></f:attribute>
                    <f:attribute value="#{info.count}" name="count"></f:attribute>
                    <f:attribute value="#{info.roll}" name="roles">    </f:attribute>
      <f:ajax render="@form" execute="a2"></f:ajax>
        </h:inputText> </h:column></rich:dataGrid> 
       </rich:panel>
      </h:column>
      </rich:dataTable></h:form>
   </rich:panel> 

and My ManagedBean Code..

public void countChange(ValueChangeEvent count)
{   

    String serialNo=count.getComponent().getAttributes().get("serial").toString();

    String name=count.getComponent().getAttributes().get("name").toString();

    try
    {
        validate=null;
        System.out.println("value---------->"+quantity.getNewValue());
        String count=(String) count.getNewValue();
        System.out.println("count"+count);


        serial=quantity.getComponent().getAttributes().get("serial").toString();
        System.out.println("serial"+serial);*/
        System.out.println("product name------"+name);  
        System.out.println("serialNo"+serialNo);

        int count=Integer.parseInt(count);
        System.out.println("count"+count);


        roll.clear();
        System.out.println("Size 1------"+roll.size());
        for(int i=1; i<=count;i++){

            Bean st=new Bean ();
            st.setSerialno1(""+i);
            st.setBatch1(" ");
            roll.add(st);
        }
        System.out.println("Size"+roll.size());
        Bean he=new Bean();
        he.name(""+name);
        he.setSerialno(s.get(Integer.parseInt(serialNo)-1).getSerialno());
        he.setFlag("none");
        he.setFlag3("1");
        he.setFlag2("none");
        he.setRoll(roll);
        s.set(Integer.parseInt(serialNo)-1,he);

        System.out.println("Size------->>><<<"+s.get(0).getVal());
        System.out.println("roll size------>"+s.get(Integer.parseInt(serialNo)-1).getRoll().size());

    }catch(NumberFormatException number){
        System.out.println("Inside Number Format Exception");
    }
    catch(NullPointerException nullexception){
        System.out.println("Inside Null Pointer Exception");
    }

    catch(Exception e)
    {           
        e.printStackTrace();
    }       
}

public void getList(ValueChangeEvent event)
{
System.out.println(“—-Inside getList ofMethod—-“);

    String serialNo = event.getComponent().getAttributes().get("serial2").toString();

    String count= event.getComponent().getAttributes().get("count").toString();
    String name = event.getComponent().getAttributes().get("producty").toString();
    String serial = event.getComponent().getAttributes().get("serial3").toString();
    String val1= event.getComponent().getAttributes().get("val1").toString();

    System.out.println("----serialNo - " + serialNo + "-- name -" + name
            + "-- quantity--" + quantity + "---Roll" + roll.size());

    System.out.println("i Serial No" + serial);
    System.out.println("Batch name"+val1);

    try {

        System.out.println(""+ homeMBs.get(Integer.parseInt(serialNo) -1).getRoll().size());

        int count= Integer.parseInt(count);
        String ListName = event.getNewValue().toString();
        System.out.println("1111---" + ListName);

        ArrayList<StockInFormMB> roll1 = null;
        roll1 = homeMBs.get(Integer.parseInt(serialNo) - 1).getRoll();
        int j = homeMBs.get(Integer.parseInt(serialNo) - 1).getRoll().size();
        System.out.println("j value-------------" + j);
        System.out.println("list size----------------->" + s.size());

        roll.clear();



        for (int i = 0; i < j; i++) {

            if (serial.equals(""+i)) {
                System.out.println("-----------------------------------");
                Bean st = new Bean ();
                st.setval1(val1);
                st.setSerialno1(serial);
                roll.add(st);

            } else {
                System.out
                        .println("*********************************************");
                Bean st = new Bean ();
                try {
                    st.val1(roll.get(i).getval1());
                    st.setSerialno1(roll.get(i).getSerialno1());
                } catch (Exception e) {
                    System.out
                            .println("-------------inside exception----------------");
                    st.setBatch1(val1);
                    st.setSerialno1("" + (i + 1));
                }

                roll.add(st);
            }

        }


        Bean he = new Bean();
        he.setName(name);

        he.setSerialno(s.get(Integer.parseInt(serialNo) - 1)
                .getSerialno());
        he.setFlag("none");

        he.setFlag2("1");
        he.setFlag1("none");
        he.setRoll(roll);
        he.setCount(count);
        s.set(Integer.parseInt(serialNo) - 1, he);

}catch(Exception e){

    e.printStackTrace();
}
}

and val1 not get that values and it go to inside exception

please friends help me…


Source: ajax

Leave a Reply