2010-07-28 67 views
0

我的結果表/圖像將顯示在同一頁面中。但提交按鈕不被調用。我有兩個下拉菜單,其他兩個下拉菜單的值依賴於這兩個下拉菜單。如果我正在寫immediate="true"該方法被調用,但只有兩個值與我關聯的processValueChange動作被設置,其他所選值不會在bean中更新。提交BackBean中的監聽器方法未被調用

JSP頁面如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 

<%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%> 
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%> 
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%><%@taglib 
uri="http://www.ibm.com/jsf/BrowserFramework" prefix="odc"%> 
<html> 
<head> 
<script language="javascript" src="Validation.js"></script> 
<link rel="stylesheet" href="../css/style.css" type="text/css"> 
<title>SLA DASHBOARD</title> 
</head> 

<f:view> 
    <body> 
    <hx:scriptCollector id="scriptCollector1"> 

    <div id="mDiv" class="pStyle">  
    <h:form styleClass="form" id="LoginForm" ><br> 
     <br> 
    <div id="Header" class="hStyle"> 
      <h:outputText value= "WELCOME TO SLA DASHBOARD" /> 
    </div> 
    <br><br>&nbsp;&nbsp;&nbsp;&nbsp; 
    <div id="fDiv" > 
     <fieldset class="fStyle"> 
      <legend style="text-align: left;padding: 6px; font-weight:bold; font-size: 14">PLEASE MAKE YOUR SELECTION</legend><br> 
      &nbsp;&nbsp; 
      <h:outputText value="BU"/>&nbsp; 
      <h:selectOneMenu id="slaBU" value="#{LoginForm.slaPeriod}" 
       onchange="this.form.submit();" valueChangeListener="#{LoginForm.processBUChange}"> 
       <f:selectItems value="#{LoginForm.buList}" /> 
      </h:selectOneMenu>&nbsp;&nbsp; 
      <h:outputText>Application</h:outputText>&nbsp; 
      <h:selectOneMenu id="slaApplication" style="width:160px" value="#{LoginForm.slaApp}" required="true"> 
       <f:selectItems value="#{LoginForm.appList}" /> 
      </h:selectOneMenu>&nbsp;&nbsp; 
      <h:outputText>Period</h:outputText> 
      <h:selectOneMenu id="slaPeriod" value="#{LoginForm.slaPeriod}" onchange="this.form.submit()" 
       valueChangeListener="#{LoginForm.processPeriodChange}" > 
       <f:selectItems value="#{LoginForm.periodList}" /> 
      </h:selectOneMenu> 
      &nbsp; 
      <h:selectOneMenu id="slaPeriod1" style="width:100px" 
       value="#{LoginForm.slaPeriod1}" required="true"> 
       <f:selectItems value="#{LoginForm.periodList1}" /> 
      </h:selectOneMenu>&nbsp; 

      <h:selectOneMenu id="slaPeriod2" value="#{LoginForm.slaPeriod2}" required="true"> 
       <f:selectItems value="#{LoginForm.periodList2}" /> 
      </h:selectOneMenu>&nbsp;&nbsp; 
      <h:outputText value="SLA Group" /> 
      <h:selectOneMenu id="slaGroup" value="#{LoginForm.slaGroup}" required="true"> 
       <f:selectItems value="#{LoginForm.groupList}" /> 
      </h:selectOneMenu>&nbsp;&nbsp; 

      <h:outputText>View</h:outputText>&nbsp; 
      <h:selectOneMenu id="slaView" value="#{LoginForm.slaView}" required="true"> 
       <f:selectItems value="#{LoginForm.viewList}" /> 
      </h:selectOneMenu> &nbsp;&nbsp;&nbsp; 
      <h:commandButton id="submitButton" value="Submit" 
       type="submit" 
       style="width:60px;" action="#{LoginForm.processSubmit}" 
       /> 
      &nbsp; 
       <br> 
       <br> 
      </fieldset> 
     </div><br><br><br> 
     <div id="tDiv" > 
     <h:dataTable id="bTable" value="#{LoginForm.BT}" var="BillingTable" 
       style="font-weight: bold; text-align: center;" bgcolor="#D4D7FE" 
       border="4" cellpadding="1" width="60%" 
       rendered="#{LoginForm.btDisplay}"> 

       <f:facet name="header"> 
        <h:outputText value="Billing Report" style="font-weight: bold"/> 
       </f:facet> 

       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Buisness Unit" /> 
        </f:facet> 
        <h:outputText value="#{BillingTable.buName}" /> 
       </h:column> 

       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Completion Date" /> 
        </f:facet> 
        <h:outputText value="#{BillingTable.completionDate}" /> 
       </h:column> 

       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Target Date" /> 
        </f:facet> 
        <h:outputText value="#{BillingTable.targetDate}"></h:outputText> 
       </h:column> 
       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Billing Cycle" /> 
        </f:facet> 
        <h:outputText value="#{BillingTable.billingCyle}"></h:outputText> 
       </h:column> 
       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Status" /> 
        </f:facet> 
        <h:outputText value="#{BillingTable.status}"></h:outputText> 
       </h:column> 
      </h:dataTable> 
      <br> 
      <h:dataTable id="uTable" value="#{LoginForm.UT}" var="UptimeTable" 
       style="text-align: center" bgcolor="#D4D7FE" 
       border="4" cellpadding="1" width="60%" rendered="#{LoginForm.utDisplay}"> 

       <f:facet name="header"> 
        <h:outputText value="Uptime Report" style="font-style: normal; font-weight: bold"/> 
       </f:facet> 

       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Application Name" style="width:60px" /> 
        </f:facet> 
        <h:outputText value="#{UptimeTable.applicationName}" /> 
       </h:column> 
       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Application Class" /> 
        </f:facet> 
        <h:outputText value="#{UptimeTable.applicationClass}" /> 
       </h:column> 

       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Availability-Actual" /> 
        </f:facet> 
        <h:outputText value="#{UptimeTable.actual}" /> 
       </h:column> 

       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Availability-Target" /> 
        </f:facet> 
        <h:outputText value="#{UptimeTable.target}"></h:outputText> 
       </h:column> 
      </h:dataTable> 
      <br> 
      <h:dataTable id="tTable" value="#{LoginForm.TT}" var="TATTable" 
       style="font-weight: bold; text-align: center" bgcolor="#D4D7FE" 
       border="4" cellpadding="1" width="60%" 
       rendered="#{LoginForm.ttDisplay}"> 

       <f:facet name="header"> 
        <h:outputText value="Turn Around Time Report" /> 
       </f:facet> 

       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Application Name" /> 
        </f:facet> 
        <h:outputText value="#{TATTable.applicationName}" /> 
       </h:column> 

       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Application Class" /> 
        </f:facet> 
        <h:outputText value="#{TATTable.applicationClass}" /> 
       </h:column> 

       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="TAT Average" /> 
        </f:facet> 
        <h:outputText value="#{TATTable.tatAverage}" /> 
       </h:column> 

       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="TAT Target" /> 
        </f:facet> 
        <h:outputText value="#{TATTable.tatTarget}"></h:outputText> 
       </h:column> 
       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Request Count" /> 
        </f:facet> 
        <h:outputText value="#{TATTable.reqCount}"></h:outputText> 
       </h:column> 
       <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Request Type" /> 
        </f:facet> 
        <h:outputText value="#{TATTable.reqType}"></h:outputText> 
       </h:column> 
      </h:dataTable> 
      </div> 
      <br> 
      <h:graphicImage styleClass="graphicImage" id="reportImage" alt="Sorry records not found !!" 
       value="#{LoginForm.imageLocation}" width="700" height="250" rendered="#{LoginForm.viewImage}"> 
       </h:graphicImage><br> 
      <h3><h:outputText value="Sorry records not found !!" rendered="#{LoginForm.notFoundMsg}"/></h3> 
     </h:form> 
     </div> 
    </hx:scriptCollector></body> 
</f:view> 
</html> 

我支持bean登錄形式如下:

package sla.dashboard.form; 

import sla.dashboard.Search.SearchManager; 
import sla.dashboard.drop_down_components.*; 
import sla.dashboard.datatables.*; 
import java.util.*; 
import javax.faces.context.FacesContext; 
import javax.faces.event.*; 
import javax.faces.model.*; 



public class LoginForm implements ValueChangeListener,ActionListener 
{ 

    private String slaBU=null,slaPeriod1=null,slaPeriod2=null,slaGroup=null, 
    periodType=null,periodSelected=null,slaView=null,period=null, 
    imageResult=null,imageLocation=null; 
    private int slaPeriod,slaApp; 

    Boolean btDisplay,utDisplay,ttDisplay,viewImage,notFoundMsg; 

    //Table Lists 
    List <BillingTable> BT; 
    List <UptimeTable> UT; 
    List <TATTable> TT; 

    DropDownComponents ddC; 

    List<SelectItem> buList; 
    List<SelectItem> periodList; 
    List<SelectItem> periodList1; 
    List<SelectItem> periodList2; 
    List<SelectItem> groupList; 
    List<SelectItem> appList; 

    List<SelectItem> viewList; 

    ArrayList<String> result= new ArrayList<String>(); 


    public LoginForm() 
    { 

     ddC=new DropDownComponents(); 
     buList=ddC.getBuList(); 
     this.reset(); 

     BT=new ArrayList<BillingTable>(); 
     UT=new ArrayList<UptimeTable>(); 
     TT=new ArrayList<TATTable>(); 

     System.out.println("\n Back Bean Object Instantiated"); 
    } 

    public int getSlaApp() { 
     return slaApp; 
    } 

    public Boolean getBtDisplay() { 
     return btDisplay; 
    } 

    public void setBtDisplay(Boolean btDisplay) { 
     this.btDisplay = btDisplay; 
    } 

    public Boolean getUtDisplay() { 
     return utDisplay; 
    } 

    public void setUtDisplay(Boolean utDisplay) { 
     this.utDisplay = utDisplay; 
    } 

    public Boolean getTtDisplay() { 
     return ttDisplay; 
    } 

    public void setTtDisplay(Boolean ttDisplay) { 
     this.ttDisplay = ttDisplay; 
    } 

    public void setSlaApp(int slaApp) { 
     this.slaApp = slaApp; 
    } 

    public int getSlaPeriod() { 
     return slaPeriod; 
    } 

    public void setSlaPeriod(int slaPeriod) { 
     this.slaPeriod = slaPeriod; 
    } 


    public String getPeriod() { 
     return period; 
    } 

    public void setPeriod(String period) 
    { 

     this.period = period; 
    } 

    public List<SelectItem> getViewList() { 
     return viewList; 
    } 

    public void setViewList(List<SelectItem> viewList) { 
     this.viewList = viewList; 
    } 

    public List<SelectItem> getPeriodList() { 
     return periodList; 
    } 
    public void setPeriodList(List<SelectItem> periodList) { 

     this.periodList = periodList; 
    } 

    public List<SelectItem> getBuList() 
    { 
     return buList; 
    } 

    public String getPeriodType() { 
     System.out.println("Inside getPeriodType " + periodType); 
     return periodType; 
    } 

    public void setPeriodType(String periodType) { 
     System.out.println("Inside setPeriodType "+ periodType); 
     this.periodType = periodType; 
    } 

    public void setBuList(List<SelectItem> buList) { 
     this.buList = buList; 
    } 

    public String getSlaBU() { 
     return slaBU; 
    } 

    public void setSlaBU(String slaBU) 
    { 
     this.slaBU = slaBU; 
    } 
    public String getSlaPeriod1() 
    { 

     return slaPeriod1; 
    } 

    public void setSlaPeriod1(String slaPeriod1) { 
     this.slaPeriod1 = slaPeriod1; 
    } 

    public String getSlaPeriod2() { 
     return slaPeriod2; 
    } 

    public void setSlaPeriod2(String slaPeriod2) { 
     this.slaPeriod2 = slaPeriod2; 
    } 
    public String getPeriodSelected() { 
     return periodSelected; 
    } 

    public void setPeriodSelected(String periodSelected) { 
     this.periodSelected = periodSelected; 
    } 
    public List<SelectItem> getPeriodList1() { 
     return periodList1; 
    } 

    public void setPeriodList1(List<SelectItem> periodList1) { 
     this.periodList1 = periodList1; 
    } 

    public List<SelectItem> getPeriodList2() { 
     return periodList2; 
    } 

    public void setPeriodList2(List<SelectItem> periodList2) { 
     this.periodList2 = periodList2; 
    } 
    public String getSlaGroup() { 
     return slaGroup; 
    } 

    public void setSlaGroup(String slaGroup) { 
     this.slaGroup = slaGroup; 
    } 

    public List<SelectItem> getGroupList() { 
     return groupList; 
    } 

    public void setGroupList(List<SelectItem> groupList) { 
     this.groupList = groupList; 
    } 

    public List<SelectItem> getAppList() { 
     return appList; 
    } 

    public void setAppList(List<SelectItem> appList) { 
     this.appList = appList; 
    } 


    public String getSlaView() { 
     return slaView; 
    } 

    public void setSlaView(String slaView) { 
     this.slaView = slaView; 
    } 


    //ValueChangeListener 
    public void processValueChange(ValueChangeEvent arg0) throws AbortProcessingException 
    {} 

    public void processPeriodChange(ValueChangeEvent arg0) throws AbortProcessingException 
    { 
     this.setSlaPeriod(Integer.parseInt(arg0.getNewValue().toString())); 
     this.setPeriodList1(ddC.getPeriodList1(Integer.parseInt(arg0.getNewValue().toString()))); 

     System.out.println("Period Changed Value : "+this.getSlaPeriod()); 
     FacesContext.getCurrentInstance().renderResponse(); 
    } 

    public void processBUChange(ValueChangeEvent arg0) throws AbortProcessingException 
    { 
     this.setSlaBU(arg0.getNewValue().toString()); 
     this.setAppList(ddC.getAppList(Integer.parseInt(arg0.getNewValue().toString()))); 
     System.out.println("\n BU Slected : " + this.getSlaBU()); 
     FacesContext.getCurrentInstance().renderResponse(); 
    } 


    public void processAction(ActionEvent arg0) throws AbortProcessingException 
    {} 
    public List<BillingTable> getBT() { 
     return BT; 
    } 

    public void setBT(List<BillingTable> bt) { 
     BT = bt; 
    } 

    public List<UptimeTable> getUT() { 
     return UT; 
    } 

    public void setUT(List<UptimeTable> ut) { 
     UT = ut; 
    } 

    public List<TATTable> getTT() { 
     return TT; 
    } 

    public void setTT(List<TATTable> tt) { 
     TT = tt; 
    } 


    public void setImageLocation(String imageLocation) { 
     this.imageLocation = imageLocation; 
    } 

    public String getImageLocation() { 
     return imageLocation; 
    } 
    String getLabel(String index,List<SelectItem> lst) 
    { 
     return(lst.get(Integer.parseInt(index)).getLabel()); 
    } 
    public Boolean getViewImage() { 
     return viewImage; 
    } 

    public void setViewImage(Boolean viewImage) { 
     this.viewImage = viewImage; 
    } 

    public void setImageResult(String imageResult) { 
     this.imageResult = imageResult; 
    } 

    public String getImageResult() { 
     return imageResult; 
    } 

    public Boolean getNotFoundMsg() { 
     return notFoundMsg; 
    } 

    public void setNotFoundMsg(Boolean notFoundMsg) { 
     this.notFoundMsg = notFoundMsg; 
    } 

    public void reset() 
    { 
     slaPeriod=0; 
     slaApp=0; 
     slaBU="0"; 
     slaPeriod1="0"; 
     slaPeriod2="0"; 
     slaGroup="0"; 
     slaView="0"; 
     periodList=ddC.getPeriodList(); 
     periodList1=ddC.getPeriodList1(slaPeriod); 
     periodList2=ddC.getPeriodList2(); 
     groupList=ddC.getSlaGroupList(); 
     appList=ddC.getAppList(slaApp); 
     viewList=ddC.getViewList(); 
     this.setViewImage(false); 
     this.setUtDisplay(false); 
     this.setTtDisplay(false); 
     this.setBtDisplay(false); 
     this.setNotFoundMsg(false); 

    } 
    public String processSubmit() 
    { 
     System.out.println("Inside Process Submit "); 
     System.out.println(this.getSlaBU()+this.getSlaApp()+this.getSlaPeriod()+this.getSlaPeriod1()+ 
       this.getSlaPeriod2()+this.getSlaGroup()+this.getSlaView()); 
     this.setViewImage(false); 
     this.setUtDisplay(false); 
     this.setTtDisplay(false); 
     this.setBtDisplay(false); 
     this.setNotFoundMsg(false); 

     /*slaPeriod=1; 
     slaApp=0; 
     slaBU="1"; 
     slaPeriod1="1"; 
     slaPeriod2="2"; 
     slaGroup="2"; 
     slaView="1";*/ 

     if(this.slaGroup=="1" && slaView=="1") 
     { 
      BT=new SearchManager().searchBillingTable 
       (slaBU,periodList.get(slaPeriod).getLabel(), 
       this.getSlaPeriod1(),getLabel(slaPeriod2, 
       periodList2),getLabel(slaGroup,groupList)); 
       if(BT.size()!=0) 
        this.setBtDisplay(true); 
       else 
        this.setNotFoundMsg(true); 
     } 
     else 
     { 
      if(this.slaGroup=="2" && slaView=="1") 
      { 
        UT=new SearchManager().searchUptimeTable 
        (slaBU,periodList.get(slaPeriod).getLabel(), 
          this.getSlaPeriod1(),getLabel(slaPeriod2, 
          periodList2),getLabel(slaGroup,groupList)); 
        if(UT.size()!=0) 
         this.setUtDisplay(true); 
        else 
         this.setNotFoundMsg(true); 
      } 
      else 
      { 
       if(this.slaGroup=="3" && slaView=="1") 
       { 
        TT=new SearchManager().searchTATTable(slaBU,periodList.get(slaPeriod).getLabel(), 
        this.getSlaPeriod1(),getLabel(slaPeriod2, 
        periodList2),getLabel(slaGroup,groupList)); 
        if(TT.size()!=0) 
         this.setTtDisplay(true); 
        else 
         this.setNotFoundMsg(true); 

       } 
       else 
       { 
        if(slaView=="2") 
        { 
         imageResult=new SearchManager().searchImage(slaBU, 
         periodList.get(slaPeriod).getLabel(), slaPeriod1, 
         slaPeriod2,getLabel(slaGroup,groupList),slaView); 
         this.setImageLocation(imageResult); 
         this.setViewImage(true); 
        } 
        else 
        { 
         this.setNotFoundMsg(true); 
        } 
       } 
      } 
    } 
     return("Success"); 
    } 


} 

如何正確提交表單?

+0

因此...很多...代碼...必須...刪除...樣板文件... * hnnnggh * – f1sh 2010-07-28 08:36:40

+0

@ f1sh:下次看到它時按'Ctrl + W'。 – BalusC 2010-07-28 11:48:09

+0

@BalusC你gr8! – Dejell 2010-07-28 13:18:12

回答

0

當表單沒有被提交時,有時可能是由於錯誤地使用了JSF組件。

我看到你正在使用

<h:selectOneMenu id="slaView" value="#{LoginForm.slaView}" required="true"> 
      <f:selectItems value="#{LoginForm.viewList}" /> 
     </h:selectOneMenu> 

它來源於:

viewList=ddC.getViewList(); 

和所選擇的項目進入一個字符串值。

請問您可以編寫代碼getViewList

如果項目被聲明爲int,則String - 比問題是slaView應該是int類型。

+0

當然......我爲所有的下降做了一個單獨的課。我正在調用方法來獲取下拉列表: List viewList = new ArrayList (); public List getViewList() { \t \t viewList.clear(); (new SelectItem(0,「Select」)); \t \t viewList.add(new SelectItem(1,「Table」)); \t \t viewList。add(new SelectItem(2,「Graph」)); \t \t return viewList; } 如果您需要我可以粘貼該類的整個代碼。 感謝您的回覆。 – 2010-07-28 09:15:30

+0

@Debarshi - 你可以在你的代碼中看到我的答案。 添加(新的SelectItem(2,「圖形」))第一個項目是int(2),第二個項目是String(「圖形」)。這意味着slaView也必須是int類型而不是String類型。 同樣,h:selectOnMenu的其餘值必須是int類型。 – Dejell 2010-07-28 09:32:57

+0

好的謝謝你的建議我正在嘗試。一旦完成,我會更新你。 – 2010-07-28 09:41:11

0

每當下拉值發生變化時,您都會在valueChangeListener方法中調用FacesContext.getCurrentInstance().renderResponse();。這將導致JSF生命週期的剩餘階段被跳過,直到呈現響應階段。由於在驗證階段調用valueChangeListener方法,因此會跳過更新模型值和調用操作階段。並且猜測是什麼,在調用操作階段將調用提交按鈕,但這已被跳過!

無論如何,創建動態依賴下拉菜單,其中的數據完全從服務器端檢索沒有任何先進的JavaScript和Ajax的幫助是一個真正的痛苦。考慮到跳過其他字段的驗證並保留其他字段的提交值,您必須考慮很多事項。所以也在JSF中。長話短說,這裏有一篇文章介紹瞭如何正確做到這一點:Populate child menu's

+0

親愛的Balus, 我是你的忠實粉絲。感謝您的建議和時間。看到問題是如果我刪除此語句FacesContext.getCurrentInstance()。renderResponse();我的價值觀正在選擇選擇一個菜單。使用jsf存在一個頁面緩存的大問題,你有解決方案嗎?我正在計劃的是使用js手動重置下拉菜單。它會是fyn嗎? – 2010-07-28 13:23:25

+0

您需要這一行,但要結合'immediate =「true」'和**組件綁定**。這樣做只適用於用於更新另一個更改下拉菜單的下拉菜單。另請參閱鏈接的文章以獲取有效的代碼示例。 – BalusC 2010-07-28 13:53:30

+0

好的,謝謝loooooot。 – 2010-07-28 14:04:57