• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to pass user defined objects as parameter

 
Sankar Yadalam
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to pass user defined objects to the managed bean. I have a page where i get an object after querying database. In the same page i have a link which links to another page. The other page uses the same object details. So i dont want to query the database again, instead i want to make use of the object that i already have with me.

I tried using f:param inside the commandlink which did not address my problem. I learnt that we can pass only strings using f:param.
So please suggest me if there is any other way to achieve my objective.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sankar Yadalam wrote:Hi,

I want to pass user defined objects to the managed bean.

Uhm, "user defined objects" sounds a bit silly. I think you rather mean non-String typed Java objects like Javabeans, DTO´s, VO´s and so on.

I have a page where i get an object after querying database. In the same page i have a link which links to another page. The other page uses the same object details. So i dont want to query the database again, instead i want to make use of the object that i already have with me.

I tried using f:param inside the commandlink which did not address my problem. I learnt that we can pass only strings using f:param.
So please suggest me if there is any other way to achieve my objective.

You know, the HTML response is one big String. The request parameters are Strings. You can only output and take Strings. Thanks to EL, JSF supports "automagic" coercion between String and Number or Boolean, dependent of the property type. But for any other object types you need to implement a custom javax.faces.convert.Converter which converts between String (or Number) and the desired Object type.

Alternatively you can store the desired object instance in session, but that has more impact. Better is to use Tomahawk´s t:saveState tag for this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!