Announcement Announcement Module
Collapse
No announcement yet.
how to initialize and add data into list in the jsp view? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      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.

      Comment


      • #4
        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)}"/>

        Comment

        Working...
        X