Remember this post: here?
Well, that was the wrong way of sending a StringArrayArray from a Java (EJB 3.0) webservice to the client. In the mean time I managed to sent the StringArrayArray the correct way with the help of my projectmembers and a few other students.
This is the correct way to sent a StringArrayArray from server to client:
(This code describes how to get all users and iterate them to the JSP frontend, just like my previous post about this but now the "correct" way)
Client:
Import these packages:
import net.java.dev.jaxb.array.StringArray;
import net.java.dev.jaxb.array.StringArrayArray;
Put this code in your Servlet:
List<StringArray> data = ((StringArrayArray)port.getAllUsers()).getItem();
String[][] users = new String[data.size()][3];
for (int i = 0, n = data.size(); i < n; i++) {
StringArray list = data.get(i);
List<String> user = list.getItem();
for (int j = 0, m = user.size(); j < m; j++) {
users[i][j] = user.get(j);
}
uo.setList(users);
Auto generated from the client:
Folder: net/java/dev/jaxb/array
Classes:
public class ObjectFactory {}
public class StringArray {}
Public class StringArrayArray {}
Server:
Implement:
@WebMethod
@RolesAllowed ("beheerders")
public String[][] getAllUsers() {
final List<Gebruikers> list = entityManager.createQuery("select g from Gebruikers g").getResultList();
int i = 0;
String[][] tmp = new String[list.size()][3];
for (Gebruikers gebruiker : list) {
tmp[i][0] = ""+gebruiker.getId();
tmp[i][1] = ""+gebruiker.getNaam();
tmp[i][2] = ""+gebruiker.getRole();
System.out.println("-----------------> getAllUsers() ="+tmp.toString());
i++;
}
return tmp;
}
Interface:
String[][] getAllUsers();
Thats all you need to do to send the StringArrayArray from the server to the client.
If you want to know how to use a taglib to show the data on the JSP, I recommend you to visit the link here where i talked about it last time. (code included)
HappyFace
www.engineeringserver.com
Bookmark this page:
These icons link to social bookmarking sites where readers can share and discover new web pages.