• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dought about useBean and getProperty

 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

To use the <jsp:getProperty > action, is it required to define the bean using <jsp:useBean> ?

I am asking this question, because I found that the <jsp:getProperty> work on any scoped beans. I tested the following.



Here Person is valid bean.
After running this JSP file the output is narendra.

Any clarification please.

Thanks
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The jsp:getProperty tag is used as follows:
<jsp:getProperty name = "myName" property = "myProperty">
so it is seen that the name attribute has to be an id of some bean. Hence somewhere before the getProperty tag the useBean tag has to be there.
You can check the c:set tag to when is similar to this but only much cooler....
Hope this helps
Regards
Simon
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


so it is seen that the name attribute has to be an id of some bean. Hence somewhere before the getProperty tag the useBean tag has to be there.



I was also thinking in the same direction. But the above posted code excuted without error. I tested it on tomcat and Sn Java Application Server 8.1. I addition to this, if I try

<jsp:useBean id="pr" class="mypackage.Person">
<jsp:setProperty name="pr" property="name" value="narendra"/>
</jsp:useBean>

<% Person p = new Person();
p.setName("SomeName");
pageContext.setAttribute("pr", p);
%>

The in the same program, I use the following

<jsp:getProperty name="pr" property="name" />

It is printing "SomeName" not "narendra"

Thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic