Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt regarding Beans

 
Raj Menon
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

A bean class is defined as below

public class BeanX{

public BeanX(){
}
public String getAll(){
return something;
}

}

No private variable is defined and also any setter method.

Can we call that method in the JSP like below?

<jsp:useBean id="x" class="BeanX"/>
<jsp:getProperty name="x" property="all"/>



Thanks in Advance..

[ August 08, 2007: Message edited by: Rajesh Kodali ]
[ August 10, 2007: Message edited by: Rajesh Kodali ]
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens when you try it?
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajesh

It won't work.
Forget about the private variable.
You don't even have the setter method for that property.
As the propert is a private variable, It doesn't matter to the other component, wheher they really exit or not. You can work even without having them in reallity. And make the user to realise as if they actually exit.

But you can't use <jsp:setProperty> in your jsp without having corresponding setter method in you bean.
It's surely gonna give you Runtime exception.

Regards,
Khushhal
 
Raj Menon
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kushal,

I mistakenly put it as
<jsp:setProperty ... /> (I've edited my first post now)
but actually it is
<jsp:getProperty .../>.

In this case what will be the result?
 
Promod kumar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it out and it works. If you use getProperty, you should have get method and if you are using setProperty you should have a set method. It is not required to have the instance variable.
 
Raj Menon
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Promod for clarifying the doubt
 
Promod kumar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem. Good luck on your exam.
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this <jsp:setProperty ... /> and <jsp:getProperty .../> stuff is on the exam.

Good luck
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic