Results 1 to 4 of 4

Thread: how to initialize and add data into list in the jsp view?

Hybrid View

  1. #1

    Default how to initialize and add data into list in the jsp view?

    my model class is like this:

    Manager.java
    Code:
    class Manager {
    
    	int mgrId;
    	String name;
    	Set<Emp> employees;
    
    // getter-setter methods	
    }
    Emp.java
    Code:
    class Emp {
    
    	int empId;
    	String name;
    	String department;
    
    // getter-setter methods	
    }
    my jsp page is like this:

    create_manager.jsp
    Code:
    <form:form modelAttribute="manager">
    
    Manager Name: <form:input path="${manager.name}" maxlength="32" />
    
    <table>
    	<tr>
    		<th>Emp Name</th>
    		<th>Salary</th>
    		<th>Department</th>
    		<th>&nbsp;</th>
    	</tr>
    
    	<tr>
    	
                 <td><form:input path="${what shall i write here?}" /></input></td>
    	<td><form:input path="${what shall i write here?}" /></input></td>
    	<td><form:input path="${what shall i write here?}" /></input></td>
    	<td><input type="button" value="Add New Employee" />
    
     	</tr>
    
    </table>
    
    </form:form>
    how to initialize Set<Emp> employees object in the above jsp view? what shall be the bindings. please help.

  2. #2

    Default

    no responses? i guess, i failed to explain my problem properly.

    let me try again:

    i have a List object inside the model class. The List is null initially. how shall i write a jsp page that will let user to add multiple objects to List?

    the problem is, if i wants to get the value of a String object of model class, i can write something like this:

    <form:input path="${manager.name}" />

    but, how can i do the same for List object of model class? please help.

  3. #3
    Join Date
    May 2012
    Posts
    2

    Default

    I have the same problem... could anybody help? I have tried to make default initialization in the pojo class. but in jsp there is still empty list.

  4. #4
    Join Date
    May 2012
    Posts
    2

    Default

    i have made this in my form controller:

    HTML Code:
    @RequestMapping(method = RequestMethod.GET)
    	public String showForm(ModelMap model) {
    		Client client = new Client();
    		HashSet<Parent> parents = new HashSet<Parent>();
    		parents.add(new Parent());
    		parents.add(new Parent());		
    		client.setParents(parents);		
    		
    		System.out.println(client.getParents().size());
    		model.addAttribute("addClient", client);
    		
    		ArrayList<ClientGroup> groups = (ArrayList<ClientGroup>)groupServis.getListGroups();
    		
    		model.addAttribute("groups", groups);
    		
    		return "addClientForm";
    	}
    but in jsp there is still parents size = 0
    <c:out value="${fn:length(client.parents)}"/>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •