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

jsp:getProperty  RSS feed

 
Cameron Park
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a question about <jsp:getProperty>. When we use the tag we do <jsp:getProperty name="thisBean" property="thisProperty"> . What I am confused about is does this work when there is no variable defined within the bean named "thisProperty", but there is a getThisProperty() accessor?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dunno - why don't you try an example and report back to the class?
Bill
 
Cameron Park
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill, if my newbie question offended you I am very sorry. I always thought the property variables in JavaBeans are public so JSP can set and get these properties. But the example I am studying
public class LanguageBean {
private String name;
private String language;
public LanguageBean() {}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setLanguage(String language) {
this.language = language;
}
public String getLanguage() {
return language;
}
public String getLanguageComments() {
if (language.equals("Java")) {
return "The king of OO languages.";
} else if (language.equals("C++")) {
return "Rather too complex for some folks' liking.";
} else if (language.equals("Perl")) {
return "OK if you like incomprehensible code.";
} else {
return "Sorry, I've never heard of " + language + ".";
}
}
}
And
<jsp:useBean id="languageBean" scope="page" class="LanguageBean">
<jsp:setProperty name="languageBean" property="*"/>
</jsp:useBean>
<html>
<head>
<title>useBean action test result</title>
</head>
<body>
<h1>useBean action test result</h1>
<p>Hello, <jsp:getProperty name="languageBean" property="name"/>.</p>
<p>Your favorite language is <jsp:getProperty name="languageBean" property="language"/>.</p>
<p>My comments on your language:</p>
<p><jsp:getProperty name="languageBean" property="languageComments"/></p>
</body>
</html>
Not only are both name and language are both private, there is no property called languageBean either.
Sorry for having offended you.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was certainly not offended! I was suggesting that you experiment because I don't know the answer!
What actually happens when you execute that JSP? Do you get the output of your getLanguageComments method? Which JSP engine are you working with.
Bill
 
Cameron Park
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSP works well with the bean. Bill, isn't it a convention that the property variables in a JavaBean be made public and that is the way JSP can access them?
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

nope, the property variables in a JavaBean are private and the JSP accesses them thru the public get and set methods.
regds.
- satya
 
Cameron Park
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Satya, Bill.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!