Mustang New
Mustang New

Reputation: 81

How to access the form objects in bean

Iam calling a dialog using ajax, my problem is i have defined a form in dialog and accepting data's when i click save i want the details in my Bean.

My issue: 1 ) when i click save button it does not hit Bean. 2) iam not able to access the objects of this form in my bean.

Thanks in Advance :)

My JSF File

<h:form id="outCompForm">
   <table border="0"  class="InnerBox"    width="60%">
              <tr><th  colspan="7" align="Center" class="clsTitle">OUTBOUND COMPLAINTS</th></tr>
              <tr>
                   <td>Consignment No </td>
                   <td>Consignor Branch</td>
                   <td>Consignor  </td>
                   <td>Contact No </td>
                    <td>Remark</td>
              </tr>
               <tr>
                   <td><h:inputText  id="acno" value="#{outBound.accNo}" onfocus="this.select()" styleClass="formText"  /></td>
                   <td>
                            <h:selectOneMenu value="#{outBound.cnor_Branch}" id="fcoBran" styleClass="formText" >
                                <f:selectItems value="#{outBound.cnor_BranchLi}" var="c" />
                            </h:selectOneMenu>
                        </td>
                        <td>
                            <p:selectOneMenu value="#{outBound.cnor_Name}"  id="fCnNam" editable="true">  
                                <f:selectItem itemLabel="Select One" itemValue="" />  
                                <f:selectItems value="#{outBound.cnor_NameLi}" />  
                            </p:selectOneMenu>  
                        </td>
                        <td><h:inputText  id="fcoCont" value="#{outBound.cnor_Contact}" onfocus="this.select()" styleClass="formText"  /></td>
                        <td><h:inputText  id="fremark" value="#{outBound.remark}" onfocus="this.select()" styleClass="formText"  /></td>
                    </tr>
                    <tr>
                        <td>Consignee Branch</td>
                        <td>Consignee Name </td>
                        <td>Address</td>
                        <td>Contact No</td>
                        <td >Booking Date </td>
                    </tr>
                    <tr>
                        <td>
                            <h:selectOneMenu value="#{outBound.cnee_Branch}" id="fceBran" styleClass="formText" >
                                <f:selectItems value="#{outBound.cnee_BranchLi}" var="c" />
                            </h:selectOneMenu>
                        </td>
                        <td><h:inputText  id="fceName" value="#{outBound.cnee_Name}" onfocus="this.select()" styleClass="formText"  /></td>
                        <td><h:inputText  id="fceAdr" value="#{outBound.cnee_Addr}" onfocus="this.select()" styleClass="formText"  /></td>
                        <td><h:inputText  id="fceCnt" value="#{outBound.cnee_Contact}" onfocus="this.select()" styleClass="formText"  /></td>
                        <td>  <p:calendar value="#{outBound.booking_Date}" id="fBDat"  >  </p:calendar>  </td> 
                        <td> <h:commandButton value="Save" action="#{outBound.saveAction}" onclick="return validate()" /> </td> 
                    </tr>
                    <tr>
                        <td colspan="7">

                            <h:message for="acno"/>
                        </td>
                    </tr>
                </table>
                <p:growl id="growl" showDetail="true"/>  
                <p:dataTable id="tbl" var="o" value="#{  outBound.tick_List}"  
                             paginator="true" rows="10" rowsPerPageTemplate="5,10,15" 
                             rowKey="#{o.accNo}" selection="#{outBound.outSelected}" selectionMode="single"  >  

                    <p:ajax event="rowSelect" listener="#{outBound.onRowSelect}"    
                            update=":outCompForm:display :outCompForm:growl" oncomplete="AccDialog.show()"   />  

                    <p:column headerText="Booking Date" sortBy="#{o.date_conv}">
                        <h:outputText value=" #{o.date_conv.substring(0, 10)}" /> 
                    </p:column>
                    <p:column headerText="Consignment No" sortBy="#{o.accNo}">
                        <h:outputText value=" #{o.accNo}" />  
                    </p:column>
                    <p:column headerText="Con Branch" sortBy="#{o.cnor_Branch}">
                        <h:outputText value=" #{o.cnor_Branch}" />  
                    </p:column >
                    <p:column headerText="Consignor" sortBy="#{o.cnor_Name}">
                        <h:outputText value=" #{o.cnor_Name}" /> 
                    </p:column>
                    <p:column headerText="Con Contact" sortBy="#{o.cnor_Contact}">
                        <h:outputText value=" #{o.cnor_Contact}" /> 
                    </p:column>
                    <p:column headerText="Remarks" sortBy="#{o.remark}">
                        <h:outputText value=" #{o.remark}" /> 
                    </p:column>
                    <p:column headerText="Cnee Branch" sortBy="#{o.cnee_Branch}">
                        <h:outputText value=" #{o.cnee_Branch}" /> 
                    </p:column>
                    <p:column headerText="Cnee Name" sortBy=" #{o.cnee_Name}">
                        <h:outputText value=" #{o.cnee_Name}" /> 
                    </p:column>
                    <p:column headerText="Cnee Addr" sortBy="#{o.cnee_Addr}">
                        <h:outputText value=" #{o.cnee_Addr}" /> 
                    </p:column>
                    <p:column headerText="Cnee Contact" sortBy="#{o.cnee_Contact}">
                        <h:outputText value=" #{o.cnee_Contact}" /> 
                    </p:column>


                </p:dataTable>



                <p:dialog id="dialog" header="Complaint Details" widgetVar="AccDialog" resizable="false" appendToBody="true"  
                          showEffect="fade" hideEffect="slide">
                    <h:panelGrid id="display" columns="2" cellpadding="4">  
                        <h:form id="formtrans">
                            <table border="0"  class="PopupBox"  >
                                <tr>
                                    <td>Consignment No.</td>
                                    <td colspan="3"> <h:outputText value="#{outBound.outSelected.accNo}" />  </td>
                                </tr>
                                <tr class="FormLabel" >
                                    <td>Detail</td>
                                    <td>Suggestion</td>
                                    <td>Privacy</td>
                                    <td>Status</td>
                                </tr>
                                <tr>
                                    <td><h:inputTextarea  id="fdetail" value="#{outBound_trans.details}" onfocus="this.select()" styleClass="formText"  /></td>
                                    <td><h:inputTextarea  id="fsuggest" value="#{outBound_trans.suggest}" onfocus="this.select()" styleClass="formText"  /></td>
                                    <td>
                                        <h:selectOneMenu value="#{outBound_trans.privacy}" id="fpriv" styleClass="formText" >
                                            <f:selectItems value="#{outBound_trans.privacyLi}" var="c" />
                                        </h:selectOneMenu>
                                    </td>
                                    <td>
                                        <h:selectOneMenu value="#{outBound_trans.status}" id="fstatus" styleClass="formText" >
                                            <f:selectItems value="#{outBound_trans.statusLi}" var="c" />
                                        </h:selectOneMenu>
                                    </td>


                                </tr>
                                <tr>
                                    **<td> <h:commandButton value="Save" action="#{outBound_trans.saveTrans}" onclick="return validate1()" /> </td> **
                          </tr>
               </table>

            </h:form>
      </h:panelGrid>  
     </p:dialog>
</h:form>

outBound bean

@ManagedBean(name = "outBound")
@SessionScoped
public class OutBound implements Serializable {

private String dataBase, finYear;
private int userCode, cnt = 0, ticketNo;
private String accNo, cnor_Branch, cnor_Name, cnor_Contact, cnee_Branch, cnee_Name, cnee_Addr, cnee_Contact, message = "Error";

private String cnor_Addr, cnor_Email, cnee_Email, remark;
private Date booking_Date;
private int cnee_branchCode, cnor_Code;
private ArrayList cnor_BranchLi = new ArrayList();
private ArrayList cnee_BranchLi = new ArrayList();
private ArrayList cnor_NameLi = new ArrayList();
DataFetch fetch;
DataConnect dataPush;
FacesMessage doneMessage = null;
ResultSet rs;
private ArrayList<OutBoundB> Tick_List;
Connection con;
Statement stat;
PreparedStatement pstat;
DBConnection dbconn = new DBConnection();
Utility dateFetch = new Utility();
private OutBoundB outSelected;


public OutBound() {
    FacesContext ctx = FacesContext.getCurrentInstance();
    HttpSession session = (HttpSession) ctx.getExternalContext().getSession(false);
    this.dataBase = (String) session.getAttribute("dataBase");
    this.finYear = (String) session.getAttribute("FinYear");
    this.userCode = (Integer) session.getAttribute("userCode");

    if (this.dataBase == null) {
        doneMessage = new FacesMessage("Session Expired");
    } else {
        fetch = new DataFetch(this.dataBase);
        cnor_BranchLi = fetch.getArrayString("select subbranchcode from subbranch  order by subbranchcode");
        cnor_NameLi = fetch.getArrayString("Select FirmName from accountscustomer where flag='Acti' order by FirmName");
        cnee_BranchLi = fetch.getArrayString("select distinct city from destinationmaster order by city");
        addList();
        fetch.closeAll();
    }


}

public String saveTicketOut() {
    // program to save to database
}

public String saveAction() {
    //validation before saving
    return null;
}



public void onRowSelect(SelectEvent event) {  
FacesMessage msg = new FacesMessage("Acc Selected", ((OutBoundB) event.getObject()).getAccNo());  
   FacesContext.getCurrentInstance().addMessage(null, msg);  
}  

public void onRowUnselect(UnselectEvent event) {  
    FacesMessage msg = new FacesMessage("Acc Unselected", ((OutBoundB) event.getObject()).getAccNo());  
    System.out.println("entered unselect");
    FacesContext.getCurrentInstance().addMessage(null, msg);  
}  


public static class OutBoundB {
    private int cnor_branchCode, cnee_branchCode, cnor_Code, userCode, ticketNo;
    private String accNo, cnor_Branch, cnor_Name, cnor_Contact, cnee_Branch, cnee_Name, cnee_Addr, cnee_Contact,date_conv;
    private String cnor_Addr, cnor_Email, cnee_Email, remark, type, escala;
    private Date booking_Date, ticket_Date;
    Utility dateFetch1 = new Utility();

    public OutBoundB() {
    }

    public OutBoundB(String conBran, String conNam, String cnoCnt, String acno, String cneeBran, String cneeNam, String cneAdd, String cneeCnt, Date boDate) {
        this.accNo = acno;
        this.cnor_Branch = conBran;
        this.cnor_Name = conNam;
        this.cnor_Contact = cnoCnt;
        this.cnee_Name = cneeNam;
        this.cnee_Branch = cneeBran;
        this.cnee_Addr = cneAdd;
        this.cnee_Contact = cneeCnt;
        this.date_conv = dateFetch1.setCorrectDate(boDate);
        this.booking_Date = boDate;
    }
 }
}

// i have deleted all getter and setter outBound_trans bean

@ManagedBean(name = "outBound_trans")
@SessionScoped
public class OutBoundTrans {

private String dataBase, finYear, userName;
private int userCode;
private String  details, suggest,  privacy, status,message;
private ArrayList statusLi = new ArrayList();
private ArrayList privacyLi = new ArrayList();
//
DataFetch fetch;
 Connection con;
Statement stat;
PreparedStatement pstat;
DBConnection dbconn = new DBConnection();
Utility dateFetch = new Utility();
//

public void saveTrans( ) {

System.out.println(this.details);
if(this.details==null){
      System.out.println("save trans");
 }else{
      System.out.println(this.details);
 }
  // code to validate and save 
}

public class outboundTransB {

    private int ticketNo, responseCount;
    private Date resp_Date;
    private String oeBrach, deBranch, details, suggest, ticketType, flag, privacy;
  }
}

Upvotes: 1

Views: 185

Answers (1)

bjedrzejewski
bjedrzejewski

Reputation: 2436

After reviewing your code I have noticed that you have nested forms! This is extremly bad and can create unpredictable behaviour. Fix it and test again if the problem persists.

Additional Information

If your problem is the ability of retrieving some form values I suggest looking at:

String value = FacesContext.getCurrentInstance().getExternalContext()
.getRequestParameterMap().get("myInputField");

Inside the method that is being called. This should let you get any value from the method inside the form.

Upvotes: 1

Related Questions