Discussions

EJB design: passing data from session beans to client/shielding entity acces

  1. A little confused on how best to pass back rows of data (10+ columns) to client from session bean so that the client does not need to access the remote interface of the entity or session again to access the data attributes. Here's the breakdown:

    client calls session Bean remote interface method like:
    sessionRemoteInt.getOrderDetail(Cart cart);

    client gets back say a vector v with the details. Normally I could do something like:

    --begin loop--
    v.elementAt(i)getItemName();
    v.elementAt(i)getItemNumber();

    ..more stuff
    --end loop--

    but I'm going back to the entity bean in this case (either directly from say a jsp page or even a java bean/servlet. How should I do this loop in a session bean and pass it back to the client so I can do get from the client and already have the data stored (in say a vector, array of strings, etc). Any info or snippets of code would be helpful

    thanks--
    zman
  2. I think that it will be ideal if you use XML here. Return XML document from session bean, SAX parse it in client.
  3. You could create a ValueObject class to represent the row. The session bean creates these from the data in the entity bean, puts them into some kind of collection and passes them back to the client.
    The XML approach would work but why go through the hassle of creating and parsing XML just for the sake of it? I don't want to get into a debate about XML here but a lot of people seem to want to use it every time you pass data about when in some cases it's just overkill.
  4. This guy is going to output the data from the session bean. He uses JSP/servlets - that means he is going to output in HTML/XHTML/WML. And that means he is going to use templates (if he is not going than I am sorry :) ). Using XSL-T and XML you will get one of the best solutions for output templating. That's why I wrote about XML. In case of Swing client, I would use VO's for sure...