2016-03-30 8 views
1

私はjspを入力データとオブジェクトのselectオプションに転送するアクションstruts 1を持っています。私もデバッグモードに従います。フォームBeanは更新された値を取りますが、表示されたJSPでは古いデータを保持していますか?デバッグは、updade formBeanを表示しますが、jspがstruts 1で更新されていません

JSP:

<table width="90%" border="0" cellspacing="0" cellpadding="3" 
      align="center"> 
      <tr> 
       <td width="22%" class="TableInfo"><bean:message 
         bundle="drive" key="etiquette.form.support" /></td> 
       <td width="40%" class="TableInfo"><span class="TabData"> 
           <html:select name="colisageForm" property="code" styleId="mySelect" onchange="submitGetSupport('${root}/getSupportAction.do?methode=getSupport');" > 
           <html:option value="0">--Select Support--</html:option> 
           <html:optionsCollection name="colisageForm" 
           property="listSupport" label="libelle" value="code" /> 
          </html:select> 
       </span></td> 
      </tr> 

      <!-- debut ce code cause un probleme quon on clique sur le button retour/CODE A ENLEVER 
      <tr> 
       <td width="22%" class="TableInfo"><bean:message 
         bundle="drive" key="etiquette.form.support" /></td> 
       <td width="40%" class="TableInfo"><span class="TabData"> 
           <html:select name="colisageForm" property="listSupport" styleId="mySelect1" onchange="charge1();"> 
           <logic:iterate id ="supp" name="colisageForm" property="listSupport" indexId="numIndex"> 
           <option value="${numIndex}"><bean:write name="supp" property="libelle" /></option> 
           </logic:iterate> 
        </html:select> 
       </span></td> 
      </tr>  --> 

      <!-- fin --> 


<nested:present name="colisageForm" property="supportCommande" > 
<!-- <bean:define id="supportCommande" name="colisageForm" property="listSupport[0]" ></bean:define> --> 
    ${supportCommande.code } 
    <tbody id="dimSupport" > 

      <tr> 
      <td width="40%" class="ChampTexteLibelle"><bean:message key="etiquette.form.quantite" bundle="drive"/> </td> 
       <td width="20%" class="TabData"><nested:text name="supportCommande" property="quantite" styleClass="ChampTexte" size="1" maxlength="4" /></td> 
      <td width="40%" class="ChampTexteLibelle"><bean:message key="etiquette.form.longueur" bundle="drive"/> </td> 
       <td width="20%" class="TabData"><nested:text name="supportCommande" property="longueur" styleClass="ChampTexte" size="1" maxlength="4" /></td> 

      </tr> 
      <tr> 
      <td width="40%" class="ChampTexteLibelle"><bean:message key="etiquette.form.largeur" bundle="drive"/> :</td> 
       <td width="20%" class="TabData"><nested:text name="supportCommande" property="largeur" styleClass="ChampTexte" size="1" maxlength="4" /></td> 
      <td width="40%" class="ChampTexteLibelle"><bean:message key="etiquette.form.hauteur" bundle="drive"/> :</td> 
       <td width="20%" class="TabData"><nested:text name="supportCommande" property="hauteur" styleClass="ChampTexte" size="1" maxlength="4" /></td> 

      </tr> 


      <tr> 
      <td width="40%" class="ChampTexteLibelle"><bean:message key="etiquette.form.poids" bundle="drive"/> :</td> 
       <td width="20%" class="TabData"><nested:text name="supportCommande" property="poids" styleClass="ChampTexte" size="1" maxlength="4" /></td> 


      </tr> 

    </tbody> 



</nested:present>   
</table> 

ACTION:

public ActionForward getSupport(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 
     ColisageForm cf = (ColisageForm) form; 
     ActionForward forward = mapping.getInputForward(); 
     // forward.setRedirect(true); 
     String code = cf.getCode(); 
     SupportCommande supportCommande = new SupportCommande(); 
     ArrayList<SupportCommande> list = cf.getListSupport(); 
     for (int i = 0; i < list.size(); i++) { 

      if (code.equals(list.get(i).getCode())) { 
       supportCommande = list.get(i); 

      } 

     } 
     // request.setAttribute("sc", supportCommande); 
     cf.setSupportCommande(supportCommande); 
     // return mapping.findForward("resterSupportCommande"); 

     // return mapping.findForward("resterSupportCommande"); 
     return forward; 

    } 

BEANFORM:

package com.brico.depot.drive.form; 

import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import java.util.Date; 
import java.util.HashSet; 
import java.util.Set; 

import javax.servlet.http.HttpServletRequest; 

import org.apache.struts.action.ActionForm; 
import org.apache.struts.action.ActionMapping; 

import com.brico.depot.bapi.DriveBapi; 
import com.brico.depot.drive.CommandeDrive; 
import com.brico.depot.drive.DriveEcranNumero; 
import com.brico.depot.drive.StatutCommande; 
import com.brico.depot.drive.SupportCommande; 
import com.brico.depot.logistique.Rayon; 
import com.brico.depot.session.UserBean; 

public class ColisageForm extends ActionForm { 

    private static final long serialVersionUID = 1L; 
    private UserBean user; 
    private DriveBapi driveBapi; 
    private String numCommande; 
    private String statut; 
    private String code; 
    private String quantite; 

    private String rayon; 
    private String dateDebut; 
    private String dateFin; 
    private String buttLbl; 
    private ArrayList<StatutCommande> statutList = null; 
    private ArrayList<Rayon> listRayons; 
    private ArrayList<CommandeDrive> listCommandes; 
    private ArrayList<SupportCommande> listSupport = null; 
    private SupportCommande supportCommande = null; 

    public String getButtLbl() { 
     return buttLbl; 
    } 

    public void setButtLbl(String buttLbl) { 
     this.buttLbl = buttLbl; 
    } 

    /** 
    * Retourne la liste de statut de l'ecran Preparer 
    * 
    * @return Liste des statut pour l'ecran Preparer 
    */ 
    public ArrayList<StatutCommande> getStatutList() { 
     driveBapi = new DriveBapi(user); 
     if (this.statutList == null) { 
      statutList = (ArrayList<StatutCommande>) driveBapi.getListStatuts(DriveEcranNumero.ECRAN_COLISAGE); 

      if (statutList != null && statutList.size() > 0) { 
       Set<StatutCommande> statutListDedoublonnee = new HashSet<StatutCommande>(statutList); 
       statutList = new ArrayList<StatutCommande>(statutListDedoublonnee); 
      } 
     } 
     return statutList; 
    } 

    public void setStatutList(ArrayList<StatutCommande> statutList) { 
     this.statutList = statutList; 
    } 

    public ArrayList<Rayon> getListRayons() { 
     return listRayons; 
    } 

    public void setListRayons(ArrayList<Rayon> listRayons) { 
     this.listRayons = listRayons; 
    } 

    public String getNumCommande() { 
     return numCommande; 
    } 

    public void setNumCommande(String numCommande) { 
     this.numCommande = numCommande; 
    } 

    public String getStatut() { 
     return statut; 
    } 

    public void setStatut(String statut) { 
     this.statut = statut; 
    } 

    public String getRayon() { 
     return rayon; 
    } 

    public void setRayon(String rayon) { 
     this.rayon = rayon; 
    } 

    public String getDateDebut() { 
     return dateDebut; 
    } 

    public void setDateDebut(String dateDebut) { 
     this.dateDebut = dateDebut; 
    } 

    public String getDateFin() { 
     return dateFin; 
    } 

    public void setDateFin(String dateFin) { 
     this.dateFin = dateFin; 
    } 

    public ArrayList<CommandeDrive> getListCommandes() { 
     return listCommandes; 
    } 

    public void setListCommandes(ArrayList<CommandeDrive> listCommandes) { 
     this.listCommandes = listCommandes; 
    } 

    public ArrayList<SupportCommande> getListSupport() { 

     return listSupport; 
    } 

    public void setListSupport(ArrayList<SupportCommande> listSupport) { 
     this.listSupport = listSupport; 
    } 

    public String getCode() { 
     return code; 
    } 

    public void setCode(String code) { 
     this.code = code; 
    } 

    public String getQuantite() { 
     return quantite; 
    } 

    public void setQuantite(String quantite) { 
     this.quantite = quantite; 
    } 

    public SupportCommande getSupportCommande() { 
     return supportCommande; 
    } 

    public void setSupportCommande(SupportCommande supportCommande) { 
     this.supportCommande = supportCommande; 
    } 

    /** 
    * Recupere le User de la session 
    * 
    * @param mapping 
    *   ActionMapping 
    * @param request 
    *   parametre de la request 
    */ 
    public void reset(ActionMapping mapping, HttpServletRequest request) { 
     user = (UserBean) request.getSession(true).getAttribute("USERBEAN"); 
     this.listCommandes = null; 

     SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); 
     this.dateDebut = formatter.format(new Date(System.currentTimeMillis())); 
     this.dateFin = "31/12/9999"; 
     this.supportCommande = null; 
    } 

} 

答えて

1

reset()メソッドは、フォームBeanを参照するアクションに対して呼び出されます。

アクションがname属性の場合にフォームを使用するように設定されている場合は、struts-config.xmlに表示されます。

名前属性があり、属性がscopeではない場合、デフォルトスコープはセッションスコープです。

sessionスコープからフォームBeanを取得するアクションを呼び出すたびに、reset()メソッドで初期化するアクションを呼び出します。次に、値を変更できる​​を呼び出します。

リセットした後に値を使用してフォームを変更しなかった場合、古い値が保持されます。新しい値を設定する場合は、常にreset()メソッドのプロパティに空の値を使用します。

関連する問題