1

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). 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?

the first page (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):

<%@ 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):

 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):

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:

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):

<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> 
Accollativo
  • 1,537
  • 4
  • 32
  • 56
  • 1
    1) Please post only relevant parts of your code; 2) anagraficaVDR, that is the most relevant Java part we need to see, is missing; 3) Are you sure you can post (presumably) private/copyrrighted code in the wild like this ? Be careful... – Andrea Ligios Feb 26 '14 at 15:39
  • 1) ok 2) anagraficaVDR is just a bean (of Anagrafica type) autogenerated with hibernate with inside other bean or String /Date/Integer value and just getter and setter 3) I removed the most sensitive parts, technically this could be anything. – Accollativo Feb 26 '14 at 15:47
  • Autogenerated *when* ? When called by the JSP ? – Andrea Ligios Feb 26 '14 at 16:06
  • Sorry, there was a misunderstang. It's just a simple bean, (that I've generated from hibernate). – Accollativo Feb 26 '14 at 16:13
  • Yes, but you call it in the JSP, and I can't find it in the Action (I can see there is a Getter but not the property nor where it is initialized, if it is) – Andrea Ligios Feb 26 '14 at 16:20
  • It's inside RegisterAction (InserimentoDatiAction extends it). It's just declared in this way: private Anagrafica anagraficaVDR = new Anagrafica(); – Accollativo Feb 26 '14 at 16:27
  • I added the RegisterAction. – Accollativo Feb 26 '14 at 16:35
  • Some variables are just referenced from JSPs and could be initialized from JSPs. – Roman C Feb 26 '14 at 20:04
  • But: 1) how do I save the values of jsp fields? At the moment I save it in the 2nd jsp, but when validation fails, I don't arrive to the second jsp, so the fields are not saved. 2) When validation fails, some methods are triggered? I need to pass by the prepare() of InserimentoDatiAction to repopulate the list too. – Accollativo Feb 27 '14 at 09:54
  • How is your input result defined ? Is it a redirectAction ? – Andrea Ligios Feb 27 '14 at 10:55
  • I doesn't understand so good. I pass from the first jsp to the second with the only button in the jsp, when I click on it, the prepare() of InviaRichiestaAction is called, and after its execute() – Accollativo Feb 27 '14 at 11:12
  • in your struts.xml, how is INPUT result defined for your second action ? – Andrea Ligios Feb 27 '14 at 12:24
  • Input point to the first jsp (I added part of struts.xml). – Accollativo Feb 27 '14 at 13:19
  • That's it. I'm gonna answer – Andrea Ligios Feb 27 '14 at 13:21
  • Ahhh... you mean that input must go to the second jsp and after back again to the first? Why didn't I think on it? :D – Accollativo Feb 27 '14 at 13:23
  • Mmno, you should pass by action1 before going to first jsp, while you are going to first jsp from (a not-reached) action2 – Andrea Ligios Feb 27 '14 at 13:38

1 Answers1

1

Action1 extends the one containing the AnagraficaVDR used to set the value;

Action2 extends simply ActionSupport, it doesn't know anything about an object called 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.

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...)

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. With the solution provided above, it will reset all to AnagraficaVDR values, not the just entered values.

Then you should find another way, simpler and effective, like

  • populating your Action1 properties from AnagraficaVDR in the first Action execute (or prepare) method,
  • remove all value="%{AnagraficaVDR.something" from your tags in JSP1.*

*NOTE: this is based on your previous question code, where the tag had 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.

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • Thanks, your second way works, I just doesn't understand if I'm using it or a mix between both :) So, correct me if I'm wrong, in InserimentoDatiAction I add all variables that now are missing (eg: cognome) and in execute() write something like cognome = getAnagraficaVDR().getCognome(); this for all the fields (and also I've to remove value="%{AnagraficaVDR.something"), right? – Accollativo Feb 27 '14 at 15:06
  • 1
    Yes. Both ways work, it's up to you; you could also avoid having all that variables, pointing directly to the list of entities, or to a list of DTO. – Andrea Ligios Feb 27 '14 at 15:38
  • But (another question lol!) instead of the hidden field in jsp, is it cleaner and faster to put an object (eg: anagrafica) in the session? – Accollativo Feb 27 '14 at 17:02
  • I follow your suggest (removing value="...") and all works, except the checkboxlist. When I insert only 1 check, and I go to the second page and then back to the first, I've correctly one item checked. Instead when I choose more the one check, and go to the second and then back to the first, no check are showed. But if I debug, 2 (or more) items are present when is called getApplicazioniSelezionate() (the method return a string with the ids, eg: "2, 5, 6"). I tried too using a string array instead of a simple string, but doesn't work too. – Accollativo Mar 04 '14 at 10:30
  • Checkboxes are handled in a particular way in Struts2. Ensure you have the CheckboxInterceptor (and that it is before the ParamsInterceptor), and take a look at this: http://stackoverflow.com/a/21292722/1654265 – Andrea Ligios Mar 04 '14 at 10:34
  • BTW I've seen now that you are using a checkboxlist, setting the value with `applicazioniSelezionateDefault`. You must ensure that that variable is correctly populated even in case of INPUT result... – Andrea Ligios Mar 04 '14 at 10:36
  • No, I removed the row value="applicazioniSelezionateDefault" like you suggested. Now when I go back to the first page it's called getApplicazioniSelezionate() that return correctly the string with the items checked (eg.: "1, 2, 3"). The strange thing is that it works only if I check just one item. – Accollativo Mar 04 '14 at 11:14