我有一个动作struts 1转发到带有输入数据和对象的select选项的jsp,我想当我更改select选项时同样的jsp中的日期也会改变,我按照调试模式将表单bean带到更新的值,但在显示jsp保留旧数据?
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>
行动:
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;
}
}
答案 0 :(得分:1)
为引用表单bean的任何操作调用reset()
方法。
您可以在struts-config.xml
中看到操作是否配置为使用表单,如果它具有name
属性。
如果它具有name属性但没有scope
属性,则默认范围是会话范围。
每次调用从session
范围中获取表单bean并使用reset()
方法初始化它的操作。然后它调用execute()
,您可以在其中修改值。
如果您在重新设置后没有使用值修改表单,那么它将保留旧值。如果要设置新值,请始终在reset()
方法中对属性使用空值。