Thursday 15 January 2015

spring - How to populate a form:select and select a default value? -


I have an edit user form that has a subset of ( username, last name .. ) And one of the select countries, I am having problems with this selection because I do not know the best way to populate it. I've tried populating success with jquery , but I can not choose a default value via commandName

  & Lt; Form: form method = "POST" commandName = "user" action = "registerUser.html" & gt; & Lt; Form: Errors Path = "*" cssClass = "errorblock" element = "div" /> & Lt; Spring: Message code = "app.user.username" /> & Lt; Form: Input Path = "User Name" /> & Lt; Form: Errors path = "username" cssClass = "error" /> gt; & Lt; Br / & gt; & Lt; Spring: Message code = "app.user.firstname" /> & Lt; Form: input type = "text" path = "first name" /> & Lt; Form: Errors path = "first name" cssClass = "error" /> gt; & Lt; Br / & gt; & Lt; Spring: Message code = "app.user.password" /> & Lt; Form: input type = "password" path = "password" /> & Lt; Form: Errors path = "password" cssClass = "error" /> gt; & Lt; Br / & gt; & Lt; Spring: Message code = "app.user.repassword" /> & Lt; Form: input type = "password" path = "confirmation password" /> gt; & Lt; Form: Errors Path = "Confirm Password" cssClass = "error" /> gt; & Lt; Br / & gt; & Lt; Spring: Message code = "app.user.email" /> & Lt; Form: input type = "text" path = "email" /> & Lt; Form: Errors path = "email" cssClass = "error" /> gt; & Lt; Br / & gt; & Lt; Spring: Message code = "app.user.country" /> & Lt; Form: Select path = "iso code" item = "$ {country list}" & gt; & Lt; Form: errors path = "iso code" cssClass = "error" /> gt; & Lt; Br / & gt; & Lt; Input type = "submit" value = "envir" /> & Lt; / Form: Form & gt;   

I have taken a look at this, so I have tried with a map, but I do not know how to fix the data in JSS as it would be used in the tutorials. Is a SimpleFormController but I do not want to have a SimpleFormController code for each form. It is my controller to return the approach of this form and I have another to submit. Public string record UserHandler (modelmap model) throws an exception {model.addAttribute ("user", new user ());

  @RequestMapping (method = RequestMethod.GET, value = "/ editUserForm"); Maps & lt; String, map & lt; String, string & gt; & Gt; ReferenceData = New Hashmap & lt; String, map & lt; String, string & gt; & Gt; (); Maps & lt; String, string & gt; Country = New LinkedHash & lt; String, string & gt; (); Country.Put ("US", "United Stated"); Country.put ("China", "China"); Country.Put ("SG", "Singapore"); Country.put ("MY", "Malaysia"); reference data. Input ("country list", country); Return "EditUserForm"; }   

Is it possible to give reference data to JSP to access from the form? Select

  & lt; Spring: Message code = "app.user.country" /> & Lt; Form: Select path = "iso code" item = "$ {country list}" & gt; & Lt; Form: errors path = "iso code" cssClass = "error" /> gt; & Lt; Br / & gt; Besides this, you do not have to use the shell to select. Personally I use simple list with beans, in which I have selection options.  

Listing public class {Private string ID; Private string name;

  Public listingoption (string id, string name) {this.id = id; This.name = name; } Public listingoption () {} public string getId () {return ID; } Public Zero Set ID (string id) {this.id = id; } Public string getName () {return name; } Public Zero Setname (string name) {this.name = name; }   

}

In your controller

  list & lt; List operation & gt; Selection Options = New List & lt; List operation & gt; (); // Select your option option.   

Then insert the IoO code object into the model with the desired model, then mark the value as the spring management selected.

your jsp

   Gt;    

No comments:

Post a Comment