views:

254

answers:

2
public class Controller implements Serializable
{

private Admin[] users;  
private String[] names;

public String[] getNames() {
    names = new String[] {"Joseph", "Lawson", "Shylet", "Norest"};
    return names;
}

public Admin[] getUsers()
{
    List<Admin> usersList = retrieve();
    users = new Admin[usersList.size()];
    int z = 0;



    for(int i = 0; i < usersList.size(); i++)
    {
      users[i] = new Admin();

      String id = usersList.get(i).getId();
      String password = usersList.get(i).getPassword();

      users[i].setId(id);
      users[i].setPassword(password);


    }
    return  users;
}
}

I have succesfully used jstl to loop through the string and display them on my jsp page, but I can't seem to do the same thing on my users array. I wonder what i am missing, I checked so much documentation but I can't seem to see examples on JavaBeans retrieving user defined array objects. Thanks for your help

A: 

You can create a custom tag which loops through your user-list. Read this tutorial for more details.

Roman
+1  A: 

If you managed to do the jstl over the strings you should be able to go over the Admins. Perhaps you need to add the admins properties as part of the loop. Something like this:

<c:forEach var="a" items="${thevarinyourresponse}">
  <div>${a.id} ${a.password}</div>
</c:forEach>

Note the Admin properties inside the loop. You need to use the correct properties for Admin and you need to create getters and setters for those properties like any other java bean.

rmarimon