Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

use bean tag  RSS feed

 
Kalpesh Soni
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A class has to be a proper bean to use in usebean tag ?
Also is it necessary to have default constructor ?
what if i need to construct an object used by usebean in some special way ?
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <jsp:useBean> tag assumes the bean is a 'proper' bean in the sense that it assumes the bean has a no-arg constructor.
If you are using the bean as a model in an MVC-type application, there is probably no need for any constructor arguments, just use setter methods to set properties.
But if you need to construct an object with a constructor argument(technically not a bean), you can do that using the standard <% .... %> tags. Just create the instance of the object as you would in any class. But that more or less defeats the purpose of the <jsp:useBean> tag, since it is intended to be an efficient way to use beans and using a lot of <% .... %> tags can quickly make the source code for your JSP look very cluttered.
 
Kalpesh Soni
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But that more or less defeats the purpose of the <jsp:useBean> tag, since it is intended to be an efficient way to use beans

so what else will usebean do apart from constructing the bean instance and using the object
does it use instance pools also ?
 
James Hobson
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The key thing useBean does, is allows you to talk to an Object without putting scriptlet in your JSP.
You can use
<jsp:getProperty name="beanInstanceName" property="propertyName" />
instead of
<%
out.print(beanInstance.getPropertyName());
%>
or whatever.
Of course you could easily write your own custom tags to do this, but useBean does it for you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!