Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Instantiate bean with complex object as parameter  RSS feed

 
William Bernadsson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to write a scriptless JSP. I have a complex object Product, and a ViewHelper bean. ViewHelper bean is JSP friendly representation of Product. I know there is Product object already stored in request attribute. useBean tag does allow only simple parameters, like Strings. I see 3 ways to make JSP scriptletless:
1. Instantiate ViewHelper in controller.
2. Write custom tag (they have access to request).
3. Pas product id as param to useBean. And then set up some sort of caching for Product (Product is AccessBean extended from entity EJB).

What would be the right way to instantiate ViewHelper?

Thanks
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36426
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William,
Welcome to JavaRanch!

Typically, a servlet sets values in the session/request and the scriptless JSP retrieves them. Can you pass the complex parameters in the servlet (Java code) and then just retrieve the already instantiated object in your JSP?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without information to the contrary, the correct answer is almost always "in the controller". The more complexity you keep from seeping into the JSP, the better off you are.
 
William Bernadsson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I am not frequent user of jsp:useBean tag. I wonder how much useful it is given it can take only simple types as parameters.
Also I am trying to play with unit testing and I am thinking how would I squeeze-in mock object implementation instead of the "real" one to anything instantiated with useBean.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Bernadsson:
Thank you. I am not frequent user of jsp:useBean tag. I wonder how much useful it is given it can take only simple types as parameters.
I am not sure what you mean by this. <jsp:useBean> takes no parameters at all. So what parameters are you referring to?

Are you are talking about properties of the beans that are instantiated (or bound) using the useBean action? If so, there are no restrictions to the property types.

Also I am trying to play with unit testing and I am thinking how would I squeeze-in mock object implementation instead of the "real" one to anything instantiated with useBean.
Testing anything in a JSP is hard. That's just one of the very many reasons to keep as much complexity out of JSPs as possible.
[ July 14, 2008: Message edited by: Bear Bibeault ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!