I am trying to use SpringMVC to handle a form but now I am stuck and I'm here to ask for your help.
When the user submit the form, my controller returns the jsp result page and the user can check what he filled in. In that result page I have 2 buttons, one to send definitively the form and one to modify it.
Here my problem : when I click on modify all the fields of the form are again empty and I would like to keep the value filled by the user.
My controller :
@Controller
@RequestMapping( "/adhesion" )
public class FormController {
//Send the form
@RequestMapping( method = RequestMethod.GET )
public String getFormulaire( @RequestParam( value = "user", required = false ) T_demande_adhesion User, Map<String, Object> model ) {
System.out.println( "user" + User ); //Null everytime
model.put( "user", User );
System.out.println( "Envoi formulaire !" );
return "formulaireAdhesion";
}
//Handle the form
@RequestMapping( method = RequestMethod.POST )
public String gestionAdhesion( @ModelAttribute( "formAdhesion" ) @Valid T_demande_adhesion user, BindingResult erreurForm, Map<String, Object> model )
throws ServletException, IOException {
final String CHEMIN_DOC_APP = "C:/DocumentsApp/";
// Form JSP page
final String FORMULAIRE_ADHESION = "formulaireAdhesion";
// Result page
final String AFFICHER_RESULT = "afficherResult";
// Objet de validation du formulaire
ValidationDmdAdhesion demandeAdhesion = new ValidationDmdAdhesion();
//Return AFFICHER_RESULT or FORMULAIRE_ADHESION
String resultat = demandeAdhesion.validationUser( user, erreurForm, model, FORMULAIRE_ADHESION, AFFICHER_RESULT, CHEMIN_DOC_APP );
//putting the object to the request
model.put( "user", user );
return resultat;
}
}
In JSP side I added the parameter 'User' in the request : '
<input type="button" value="Modifier" onclick="document.location.href='<c:url value="adhesion?user=${user}"/>';" class="boutonAdhesion" />
' But this send me a string and the url is :
/adhesion?user=com.user.entities.T_demande_adhesion@1dfe8158
When the user clicks on modifiy button (which is in the result page), I would like to get this object @ModelAttribute( "formAdhesion" ) @Valid T_demande_adhesion user
on the GET request to fill in the form, in purpose to avoid the user to put again the same informations.
Any help ?
An extract from the form :
<label for="nom">Nom <span class="requis">*</span></label><input type="text" id="nom" name="identite.nom" value="<c:out value ="${user.identite.nom}"/>" size="35" maxlength="30" />
<spring-ext:errors path="identite.nom" class="erreur" firstErrorOnly="true"/>
It's here : value="<c:out value ="${user.identite.nom}"/>
that I want to get the value of nom
.
Sorry for the English.
Frenchy.