简体   繁体   English

Struts2验证,验证失败时重新填充所有字段

[英]Struts2 validation, repopulate all the fields when validation fails

I have 2 pages, the first where the user insert the data, and the second where the user confirm the data (or can go back to the edit page). 我有2页,第一页是用户插入数据的页面,第二页是用户确认数据的页面(或可以返回到编辑页面)。 The problem is that when validation fails, all the values in fields are erased. 问题是,当验证失败时,将删除字段中的所有值。 Somebody suggested to use prepare(), but It's a lot of work to copy all the fields, does it exist a faster way to repopulate all the fields? 有人建议使用prepare(),但是复制所有字段需要很多工作,是否存在一种更快的方式来填充所有字段?

the first page (formDatiUtente.jsp): 第一页(formDatiUtente.jsp):

<%@ page language="java" contentType="text/html;"
     import="java.util.*,it.alm.bean.*,it.alm.delegate.*;"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="${pageContext.request.contextPath}/css/stile1.css" rel="stylesheet" type="text/css" />
<title>Registrazione account</title>

<script type="text/javascript" src="${pageContext.request.contextPath}/js/scriptFormUtente.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/scriptDWR.js"></script>
<script type='text/javascript' src='/gestUtenzeLDAP/dwr/engine.js'></script>
<script type='text/javascript' src='/gestUtenzeLDAP/dwr/util.js'></script>
<script type='text/javascript' src='/gestUtenzeLDAP/dwr/interface/DwrAjaxServiceImplEnti.js'></script>
<script type='text/javascript' src='/gestUtenzeLDAP/dwr/interface/DwrAjaxServiceImplTipoUfficio.js'></script>
<script type='text/javascript' src='/gestUtenzeLDAP/dwr/interface/DwrAjaxServiceImplUfficio.js'></script>
<script type='text/javascript' src='/gestUtenzeLDAP/dwr/interface/ComboBean.js'></script>

</head>

<body>
<jsp:include page="header.jsp"/> 
<s:actionerror />

<s:form name="formDatiUtente" action="inviaRichiesta.action" method="post" theme="simple" validate="true">

    <%
        String pathContest=request.getContextPath();
        //Collection clRichAna = (ArrayList)request.getAttribute("clRichAna");
        //String totRich=(clRichAna!=null?""+clRichAna.size():"0");

        //Collection comuni = (ArrayList)request.getAttribute("comuni");
        List <Comune> comuni = CreazioneUtenzaDelegate.getInstance().getComuni();
    %>


<center>
<s:fielderror></s:fielderror>
<table width="48%" class="LISTA" border="0" cellPadding="3" cellSpacing="5" align="center">
                <tr>
                    <td width="35%">
                        <p class="testodx">
                            <s:text name="label.cognome" />
                        </p>
                    </td>
                    <td align="right">
                        <p class="testosx">
                            <s:textfield name="cognome" id="idCognome"
                            size="30" value="%{anagraficaVDR.cognome}" />
                        </p>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <p class="testodx"><s:text  name="label.nome" /></p>
                    </td>
                    <td align="left">
                        <s:textfield name="nome" id="idNome" size="30" value="%{anagraficaVDR.nome}" />
                    <td>
                </tr>
                <tr>
                    <td>
                        <p class="testodx"><s:text name="label.dataNascita" /></p>
                    </td>
                    <td>
                        <s:date name="%{anagraficaVDR.dataNascita}" format="dd/MM/yyyy" var="dataFormattata" />
                        <s:textfield name="dataNascita" size="12"
                            value="%{#dataFormattata}" />
                        <br>
                            <p class="testosuggerimento">
                                <s:text name="label.ddmmyyyy" />
                            </p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p class="testodx"><s:text name="label.qualifica" /></p> 
                    </td>
                    <td>    
                        <s:select 
                            style=" width : 207px;"
                            list="listaQualifiche"
                            listKey="idQualifica"
                            listValue="descrizione"
                            name="qualificaSelezionata"
                            value="%{anagraficaVDR.qualifica.idQualifica}"
                             />
                    </td>
                </tr>




                <tr>
                    <td> 
                        <p class="testodx"> Comune: </p>
                    </td>
                    <td>
                        <s:select 
                            headerKey="-1" headerValue="Seleziona..."
                            style=" width : 207px;"
                            id="idListaComuni"
                            list="listaComuni"
                            listKey="codComune"  
                            listValue="descrizione"
                            onChange="setReloadEnti()"
                            name="comuneSelezionato"
                            value="%{anagraficaVDR.ufficio.comune.codComune}"
                             />
                   </td>
                <tr>
                    <td>
                        <p class="testodx">Ente:</p>
                    </td>
                    <td>
                        <s:select 
                            list="listaEnte" 
                            listKey="idValue"  
                            listValue="value"
                            name="ente" 
                            onChange="setReloadTipoUfficio()" 
                            id="identi" 
                            value="%{anagraficaVDR.ufficio.tipoufficio.ente.idEnte}"
                            style=" width : 207px;"
                            />
                    </td>
                </tr>
                <tr>
                    <td>                        
                        <p class="testodx">Tipo Ufficio:</p>
                    </td>
                    <td>
                        <s:select 
                            list="listaTipoUffici" 
                            listKey="idValue"  
                            listValue="value"
                            name="tipoufficio" 
                            onChange="setReloadUfficio()" 
                            id="idtipouff" 
                            value="%{anagraficaVDR.ufficio.tipoufficio.idTipoUfficio}"
                            style=" width : 207px;"/> 
                    </td>
                </tr>
                <tr>
                    <td>
                        <p class="testodx">Ufficio:</p>
                    </td>
                    <td> 
                        <s:select 
                            list="listaUffici"
                            listKey="idValue"  
                            listValue="value"
                            name="ufficio" 
                            id="iduff" 
                            value="%{anagraficaVDR.ufficio.idufficio}"
                            style=" width : 207px;"/> 
                    </td>
                 </tr>






                <tr>
                    <td>
                        <p class="testodx"><s:text name="label.telefono_Ufficio_reparto" /></p>
                    </td>
                    <td>
                        <s:textfield name="telefono" id="idTelefono_Ufficio_reparto" size="30" value="%{anagraficaVDR.telefono}"/>
                    </td>
                </tr>
                <tr>
                    <td>
                       <p class="testodx"><s:text name="label.email" /></p>
                    </td>
                    <td>
                       <s:textfield name="email" id="idEmail" size="30" value="%{emailVDR}"/>
                       <s:text name="label.@" />
                        <s:select 
                            headerKey="-1" headerValue="Seleziona..."
                            list="dominiMail"
                            listKey="descrizione"  
                            listValue="descrizione"
                            name="ilTuodominio_Email" 
                            value="ilTuodominio_EmailVDR" />
                    </td>
                </tr>
                <tr>
                    <td>
                       <p class="testodx"><s:text name="label.confermaEmail" /></p>
                    </td>
                    <td>
                       <s:textfield name="confermaEmail" id="idConfermaEmail" size="30" value="%{emailVDR}" onfocus="disabilitaIncolla()"/>
                       <s:text name="label.@" />
                        <s:select 
                            headerKey="-1" headerValue="Seleziona..."
                            list="dominiMail"
                            listKey="descrizione"
                            listValue="descrizione"
                            name="ilTuodominio_EmailConferma" 
                            value="ilTuodominio_EmailVDR" />
                    </td>
                </tr>
                <tr>
                    <td>
                       <p class="testodx"><s:text name="label.ip" /></p>
                    </td>
                    <td>
                       <s:textfield name="ip" id="idIp" size="30" value="%{anagraficaVDR.ip}"/>
                       <br> 
                       <p class="testosuggerimento"> <s:text name="label.testoip" /></p>
                    </td>
                </tr>
                <tr>
                    <td class="right">
                        <s:text name="label.checkbox" />
                    </td>
                    <td class="left">
                        <s:checkboxlist list="listaApplicazioni"
                            listKey="idApplicazione"
                            listValue="descrizione" 
                            name="applicazioniSelezionate"
                            value="applicazioniSelezionateDefault" 
                            cssStyle="vertical"/>                   
                    </td>
                </tr>

</table>
<br>
<s:if test="!gestioneAmministratore">
    <s:submit method="execute" cssClass="bottone" key="label.invia" align="center" />
</s:if>    
</center>  

</s:form>
</body>
</html>

That after the submit go here (visualizzaDatiRichiesta.jsp), I use hidden value to copy the data when the user go back to the previous page (it's not the best way I suppose, but I inherit part of the code from a co-worker): 在提交到此处(visualizzaDatiRichiesta.jsp)之后,当用户返回上一页时,我使用隐藏值复制数据(这不是我想的最好方法,但是我从同事那里继承了部分代码):

<%@ page language="java" contentType="text/html;"
    import="java.util.*,it.alm.bean.*,it.alm.delegate.*;"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="${pageContext.request.contextPath}/css/stile2.css" rel="stylesheet" type="text/css" />
<title>Riepilogo dati richiesta</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/scriptFormUtente.js"></script>
</head>
<% String pathContest=request.getContextPath();
%>
<body>
<jsp:include page="headerGenerico.jsp"/> <br><br><br>
<s:actionerror />

<s:form action="registrazione.action" method="post" theme="simple">

    <s:hidden name="anagraficaVDR.cognome" value="%{cognome}" />

    <s:hidden name="anagraficaVDR.nome" value="%{nome}" />
    <s:hidden name="anagraficaVDR.dataNascita" value="%{dataNascita}" />
    <s:hidden name="anagraficaVDR.qualifica.idQualifica" value="%{qualificaSelezionata}" />
    <s:hidden name="anagraficaVDR.telefono" value="%{telefono}" />
    <s:hidden name="anagraficaVDR.email" value="%{email}" />
    <s:hidden name="anagraficaVDR.ip" value="%{ip}" />

    <s:hidden name="comuneSelezionatoVDR" value="%{comuneSelezionato}" />
    <s:hidden name="enteSelezionatoVDR" value="%{ente}" />  
    <s:hidden name="tipoUfficioSelezionatoVDR" value="%{tipoufficio}" />    
    <s:hidden name="ufficioSelezionatoVDR" value="%{ufficio}" />    
    <s:hidden name="anagraficaVDR.ufficio.comune.codComune" value="%{comuneSelezionato}" />
    <s:hidden name="anagraficaVDR.ufficio.tipoufficio.ente.idEnte" value="%{ente}" />   
    <s:hidden name="anagraficaVDR.ufficio.tipoufficio.idTipoUfficio" value="%{tipoufficio}" />  
    <s:hidden name="anagraficaVDR.ufficio.idufficio" value="%{ufficio}" />  


    <s:hidden name="qualificaSelezionataDescrizioneVDR" value="%{qualificaSelezionataDescrizione}" />
    <s:hidden name="descrizioneTipoUfficioEUfficioVDR" value="%{descrizioneTipoUfficioEUfficio}" />
    <s:hidden name="ilTuodominio_EmailVDR" value="%{ilTuodominio_Email}" />

    <s:hidden name="applicazioniSelezionateVDR" value="%{applicazioniSelezionate}" />
    <s:hidden name="applicazioniSelezionateDescVDR" value="%{applicazioniSelezionateDesc}" />
<center>
<div class= "divCornicePrimoBlocco">
<table width="900"   class="PRIMORIQUADRO1" border="0" cellspacing="5" cellpadding="0">
     <tr>
         <th align="center" colspan="2">
            <h3>Riepilogo dati richiesta</h3>
         </th>
      </tr>
     <tr >
        <td>
        <s:text name="label.cognome2"/><p class="testoColorato"><s:property value="cognome"/></p>
         <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.............................................................................................................................</p>
        </td>
     </tr>
     <tr>
         <td>
          <s:text name="label.nome2" /><p class="testoColorato"><s:property value="nome"/></p>
          <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;..................................................................................................................................</p>
        </td>
     </tr>
     <tr>
        <td>
          <s:text name="label.dataNascita2" ></s:text><p class="testoColorato1"><s:date format="dd/MM/yyyy" name="dataNascita"/></p>
          <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.....................................................................................................................</p>
        </td>
     </tr> 
     <tr>
     <td>
          <s:text name="label.qualifica2"></s:text><p class="testoColorato"><s:property value="qualificaSelezionataDescrizione"/></p>
          <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;..............................................................................................................................</p>
        </td>
     </tr>
     <tr>
       <td>
        <s:text name="label.ufficio_Reparto_di_appartenenza2" /><p class="testoColorato2"><s:property value="descrizioneTipoUfficioEUfficio"/></p>
          <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.......................................................................................</p>
       </td>
      </tr>
       <tr>
         <td>
           <s:text name="label.telefono_Ufficio_reparto2" /><p class="testoColorato2"><s:property value="telefono"/></p>
             <p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.........................................................................................................</p>
         </td>
      </tr>
       <tr>
         <td >
            <s:text name="label.email2" /><p class="testoColorato"><s:property value="email"/>@<s:property value="ilTuodominio_EmailDesc"/></p>
              <p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.................................................................................................................................</p>
         </td>
      </tr>
       <tr>
         <td>
            <s:text name="label.ip2" /><p class="testoColorato3"><s:property value="ip"/></p>
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;................................................................................</p>
         </td>
       </tr>
       <tr>
         <td>
           <s:label>Applicativo richiesto</s:label><p class="testoColorato2"><s:property value="applicazioniSelezionateDesc"/></p>
           <p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.............................................................................................................</p>
         </td>
       </tr>
  </table>
 </div><br>
 <div align="right">

   <s:submit  value="Crea documento" class="bottoneConferma" action="stampaRichiestaPdf" onClick="javascript:creaDocumentoPdf();"/>&nbsp;
   <s:submit  id="idBottoneConferma" value="Conferma" class="bottoneConferma" action="inserisciRichiestaInDB" disabled="true"/>&nbsp;

   <s:submit value="Modifica dati richiesta" class="bottoneModifica" action="inserimentoDati" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 </div>
</center>

</s:form>
</body>
</html>

So, let's pass to the action, this is relative to the first jsp (this extend another action): 因此,让我们转到该动作,这是相对于第一个jsp而言的(这扩展了另一个动作):

 public class InserimentoDatiAction extends RegisterAction implements Preparable {

    private static final long serialVersionUID = 1L;

    public InserimentoDatiAction()
    {
    }

    public String execute() 
    {
        refreshDWR();

        return "success";

    }

    public void refreshDWR()
    {
        String idComune = null;
        try
        {
            idComune = getAnagraficaVDR().getUfficio().getComune().getCodComune();
        }
        catch (NullPointerException e)
        {
            //qualche campo � incompleto, le combobox non vengono caricate
        }

        if ( idComune != null)
        {
            DwrAjaxServiceImplEnti dwrEnte = new DwrAjaxServiceImplEnti();
            this.setListaEnte( dwrEnte.get_Ente( idComune ) );
            String idEnte = getAnagraficaVDR().getUfficio().getTipoufficio().getEnte().getIdEnte();
            if ( idEnte != null)
            {
                DwrAjaxServiceImplTipoUfficio dwrTipoUff = new DwrAjaxServiceImplTipoUfficio();
                this.setListaTipoUffici( dwrTipoUff.get_TipoUfficio(idComune, idEnte) );
                String idTipoUff = getAnagraficaVDR().getUfficio().getTipoufficio().getIdTipoUfficio();
                if ( idTipoUff != null)
                {
                    DwrAjaxServiceImplUfficio dwrUff = new DwrAjaxServiceImplUfficio();
                    this.setListaUffici( dwrUff.get_Ufficio(idComune, idEnte, idTipoUff));
                }
            }
        }
    }

    @Override
    public void prepare() throws Exception 
    {
        this.setDominiMail( CreazioneUtenzaDelegate.getInstance().getEmails() );
        this.setListaComuni( CreazioneUtenzaDelegate.getInstance().getComuni() );
        this.setListaApplicazioni( CreazioneUtenzaDelegate.getInstance().getApplicazioni() );
        this.setListaQualifiche( CreazioneUtenzaDelegate.getInstance().getQualifiche() );
        this.getSession().put("listaApplicazioni", this.getListaApplicazioni());
        this.getSession().put("listaQualifiche", this.getListaQualifiche());
    }

    public boolean isGestioneAmministratore()
    {
        return false;
    }

}

This is relative to the second jsp (the confirmation page): 这是相对于第二个jsp(确认页面)而言的:

public class InviaRichiestaAction extends ActionSupport implements Preparable, SessionAware 
{

    private static final long serialVersionUID = 1L;

    private String cognome;
    private String nome;
    private Date dataNascita;

    private List<Qualifica> listaQualifiche;
    private String qualificaSelezionata;
    private String qualificaSelezionataDescrizione;

    private String comuneSelezionato;
    private String ente;
    private String tipoufficio;
    private String ufficio;


    private String telefono;
    private String email;
    private String confermaEmail;
    private String ilTuodominio_Email;
    private String ilTuodominio_EmailConferma;

    private String ip;

    private String applicazioniSelezionate;
    private String applicazioniSelezionateDesc;
    private String identi;

    private static List<ComboBean> listaTipoUfficio = new ArrayList<ComboBean>();
    private static List<ComboBean> listaUfficio = new ArrayList<ComboBean>();

    //questo blocco di variabili anche se non è usato sta qui 
    //per non generare errori di validazione:
    private List<Comune> listaComuni = new ArrayList<Comune>();
    private List<ComboBean> listaEnte = new ArrayList<ComboBean>();
    private List<Email> dominiMail = new ArrayList<Email>();
    private List<ComboBean> listaTipoUffici = new ArrayList<ComboBean>();
    private List<ComboBean> listaUffici = new ArrayList<ComboBean>();
    private List<Applicazione> listaApplicazioni;


    private Map<String, Object> session;

    public String execute() 
    {       
        qualificaSelezionataDescrizione = BeanCopyUtil.getDescriptionFromBeanList(listaQualifiche, qualificaSelezionata, "getIdQualifica", "getDescrizione");
        setApplicazioniSelezionateDesc(BeanCopyUtil.getDescriptionFromBeanList(listaApplicazioni, applicazioniSelezionate, "getIdApplicazione", "getDescrizione"));
        return "success";
    }

    @Override
    public void prepare() throws Exception 
    {
        listaQualifiche = (List<Qualifica>) this.getSession().get("listaQualifiche");       
        listaApplicazioni = (List<Applicazione>) session.get("listaApplicazioni");
    }

    public String getDescrizioneTipoUfficioEUfficio()
    {
        String descrizioneTipoUfficioEUfficio = "";
        if (listaTipoUfficio!=null && !listaTipoUfficio.isEmpty())
        {
            Iterator<ComboBean> it1 = listaTipoUfficio.iterator();
            while (it1.hasNext())
            {
                ComboBean elem = it1.next();
                if (elem.getIdValue().equals(tipoufficio))
                {
                    descrizioneTipoUfficioEUfficio += elem.getValue();
                    break;
                }
            }
            if (!listaUfficio.isEmpty())
            {
                it1 = listaUfficio.iterator();
                while (it1.hasNext())
                {
                    ComboBean elem = it1.next();
                    if (!elem.getValue().trim().isEmpty() && elem.getIdValue().equals(ufficio))
                    {
                        descrizioneTipoUfficioEUfficio += " - " + elem.getValue();
                        break;
                    }
                }
            }
        }
        return descrizioneTipoUfficioEUfficio;
    }

[...a lot of boring getter and setter...]

}

The superclass of InserimentoDatiAction: InserimentoDatiAction的超类:

public class RegisterAction extends ActionSupport implements SessionAware {
    private static final long serialVersionUID = 1L;

    private Anagrafica anagraficaVDR = new Anagrafica();

    private String comuneSelezionatoVDR;
    private String ilTuodominio_EmailVDR;
    private String applicazioniSelezionateVDR;

    private List<Email> dominiMail;
    private List<Comune> listaComuni;
    private List<Applicazione> listaApplicazioni;
    private List<Qualifica> listaQualifiche;

    private List<ComboBean> listaEnte = new ArrayList<ComboBean>();
    private String enteSelezionatoVDR;
    private List<ComboBean> listaTipoUffici = new ArrayList<ComboBean>();
    private String tipoUfficioSelezionatoVDR;
    private List<ComboBean> listaUffici = new ArrayList<ComboBean>();
    private String ufficioSelezionatoVDR;

    private String qualificaSelezionataDescrizioneVDR;
    private String descrizioneTipoUfficioEUfficioVDR;
    private String applicazioniSelezionateDescVDR;

    private Map<String, Object> session;
[...other less important stuff...]
}

part of struts.xml, formDatiUtente is the first jsp, visualizzaDatiRichiesta is the second (confirmation jsp): struts.xml的一部分,formDatiUtente是第一个jsp,visualizzaDatiRichiesta是第二个(确认jsp):

<action name="inserimentoDati"
    class="it.alm.action.InserimentoDatiAction">
    <result name="success">/jsp/creazioneUtenza/formDatiUtente.jsp</result>
</action>
<action name="inviaRichiesta"
    class="it.alm.action.InviaRichiestaAction">
    <result name="success">/jsp/creazioneUtenza/visualizzaDatiRichiesta.jsp</result>
    <result name="input">/jsp/creazioneUtenza/formDatiUtente.jsp</result>
    <result name="backToMenuAdmin">/jsp/pannelloDiGestione/menu.jsp</result>           
</action> 

Action1 extends the one containing the AnagraficaVDR used to set the value; Action1扩展了包含用于设置值的AnagraficaVDR的那个;

Action2 extends simply ActionSupport, it doesn't know anything about an object called AnagraficaVDR. Action2只是对ActionSupport的扩展,它对名为AnagraficaVDR的对象一无所知。

When you post the form to Action2, and it fails validation, INPUT result returns the first JSP, without the first Action backing its data. 当您将表单发布到Action2时,如果表单未能通过验证,则INPUT结果将返回第一个JSP,而第一个Action不会备份其数据。

You have to rethink the mechanism a bit: 您必须重新考虑一下该机制:

  • if you want to repopulate the first JSP with the ORIGINAL values from AnagraficaVDR, you have to provide AnagraficaVDR to Action2 too (maybe by declaring two actions in struts.xml pointing to two methods of the same action containing AnagraficaVDR...) 如果您想用AnagraficaVDR的ORIGINAL值重新填充第一个JSP,您也必须提供AnagraficaVDR到Action2(也许通过在struts.xml中声明两个动作,指向包含AnagraficaVDR的相同动作的两个方法...)

But this is generally avoided, because if I've changed 10 fields from their original values, and one of them is failing the validation, I want it to return my 10 ALTERED values, to be able to change only the failing one. 但这通常是可以避免的,因为如果我从其原始值中更改了10个字段,并且其中之一失败了验证,我希望它返回我的10个ALTERED值,以便仅更改失败的值。 With the solution provided above, it will reset all to AnagraficaVDR values, not the just entered values. 使用上面提供的解决方案,它将全部重置为AnagraficaVDR值,而不是刚刚输入的值。

Then you should find another way, simpler and effective, like 然后,您应该找到另一种更简单有效的方法,例如

  • populating your Action1 properties from AnagraficaVDR in the first Action execute (or prepare) method, 在第一个Action执行(或准备)方法中,从AnagraficaVDR填充Action1属性,
  • remove all value="%{AnagraficaVDR.something" from your tags in JSP1.* value="%{AnagraficaVDR.something"的标签中删除所有value="%{AnagraficaVDR.something" 。*

*NOTE: this is based on your previous question code, where the tag had name="properties" and value="%{AnagraficaVDR.properties}" *注意:这是基于您之前的问题代码,其中标记的name="properties" and value="%{AnagraficaVDR.properties}"

This way the first action will populate the values from AnagraficaVDR only the first time, then keeping the entered values in case of SUCCESS or INPUT. 这样,第一个操作将仅第一次填充AnagraficaVDR中的值,然后在成功或输入的情况下保留输入的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM