You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by "Marcelo Flores A." <ma...@aditiva.com> on 2002/09/27 15:39:14 UTC
jsp:getProperty
I need help...
I'm have data of javabeans than have other javabeans with attribute.
class MyClass1
{
String name;
MyClass2 myClass2;
}
class MyClass2
{
String name2;
}
how I have across sintax tag the name2' s value only with object MyClass1
<jsp:getProperty name="MyClass1" property="name2"> throw a error.
I don't know how do it----
help me
Atte. Marcelo Flores
marcelo.flores@aditiva.com
Re: jsp:getProperty
Posted by Roberto Mannai <ro...@poste.it>.
As Thomas suggests, try:
<jsp:getProperty name="MyClass1" property="myClass2.name2">
PS:
sorry, I speak Italian :-)
----- Original Message -----
From: "Marcelo Flores A." <ma...@aditiva.com>
To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
Sent: Friday, September 27, 2002 3:54 PM
Subject: Re: jsp:getProperty
but not exist some tag than do it without the necessity of add a method in
MyClass1 ?
Thank you, Roberto...
PD: Do you speak spanish ?
Atte. Marcelo Flores
marcelo.flores@aditiva.com
Aditiva S.A.
----- Original Message -----
From: Roberto Mannai
To: Tag Libraries Users List
Sent: Friday, September 27, 2002 9:44 AM
Subject: Re: jsp:getProperty
Did you write the get method in MyClass1?
you could:
class MyClass1
{
String name;
private MyClass2 myClass2 = new MyClass2() ;
public String getName2(){
return myClass2.name2; //if name2 is public, else "return
myClass2.getName2();"
}
}
----- Original Message -----
From: "Marcelo Flores A." <ma...@aditiva.com>
To: <ta...@jakarta.apache.org>
Sent: Friday, September 27, 2002 3:39 PM
Subject: jsp:getProperty
I need help...
I'm have data of javabeans than have other javabeans with attribute.
class MyClass1
{
String name;
MyClass2 myClass2;
}
class MyClass2
{
String name2;
}
how I have across sintax tag the name2' s value only with object MyClass1
<jsp:getProperty name="MyClass1" property="name2"> throw a error.
I don't know how do it----
help me
Atte. Marcelo Flores
marcelo.flores@aditiva.com
--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: jsp:getProperty
Posted by "Marcelo Flores A." <ma...@aditiva.com>.
boys yours have a example with this than will could send me.
please....
Thank you
Atte. Marcelo Flores
marcelo.flores@aditiva.com
Aditiva S.A.
----- Original Message -----
From: Shawn Bayern
To: Tag Libraries Users List
Sent: Friday, September 27, 2002 10:36 AM
Subject: Re: jsp:getProperty
On Fri, 27 Sep 2002, Marcelo Flores A. wrote:
> but not exist some tag than do it without the necessity of add a
> method in MyClass1 ?
Yes, all JSTL tags let you use the expression language that Thomas
described. And the expression language will be a standard part of JSP as
of version 2.0.
Shawn
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: jsp:getProperty
Posted by Shawn Bayern <ba...@essentially.net>.
On Fri, 27 Sep 2002, Marcelo Flores A. wrote:
> but not exist some tag than do it without the necessity of add a
> method in MyClass1 ?
Yes, all JSTL tags let you use the expression language that Thomas
described. And the expression language will be a standard part of JSP as
of version 2.0.
Shawn
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: jsp:getProperty
Posted by "Marcelo Flores A." <ma...@aditiva.com>.
but not exist some tag than do it without the necessity of add a method in MyClass1 ?
Thank you, Roberto...
PD: Do you speak spanish ?
Atte. Marcelo Flores
marcelo.flores@aditiva.com
Aditiva S.A.
----- Original Message -----
From: Roberto Mannai
To: Tag Libraries Users List
Sent: Friday, September 27, 2002 9:44 AM
Subject: Re: jsp:getProperty
Did you write the get method in MyClass1?
you could:
class MyClass1
{
String name;
private MyClass2 myClass2 = new MyClass2() ;
public String getName2(){
return myClass2.name2; //if name2 is public, else "return
myClass2.getName2();"
}
}
----- Original Message -----
From: "Marcelo Flores A." <ma...@aditiva.com>
To: <ta...@jakarta.apache.org>
Sent: Friday, September 27, 2002 3:39 PM
Subject: jsp:getProperty
I need help...
I'm have data of javabeans than have other javabeans with attribute.
class MyClass1
{
String name;
MyClass2 myClass2;
}
class MyClass2
{
String name2;
}
how I have across sintax tag the name2' s value only with object MyClass1
<jsp:getProperty name="MyClass1" property="name2"> throw a error.
I don't know how do it----
help me
Atte. Marcelo Flores
marcelo.flores@aditiva.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: jsp:getProperty
Posted by Roberto Mannai <ro...@poste.it>.
Did you write the get method in MyClass1?
you could:
class MyClass1
{
String name;
private MyClass2 myClass2 = new MyClass2() ;
public String getName2(){
return myClass2.name2; //if name2 is public, else "return
myClass2.getName2();"
}
}
----- Original Message -----
From: "Marcelo Flores A." <ma...@aditiva.com>
To: <ta...@jakarta.apache.org>
Sent: Friday, September 27, 2002 3:39 PM
Subject: jsp:getProperty
I need help...
I'm have data of javabeans than have other javabeans with attribute.
class MyClass1
{
String name;
MyClass2 myClass2;
}
class MyClass2
{
String name2;
}
how I have across sintax tag the name2' s value only with object MyClass1
<jsp:getProperty name="MyClass1" property="name2"> throw a error.
I don't know how do it----
help me
Atte. Marcelo Flores
marcelo.flores@aditiva.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: jsp:getProperty
Posted by Hans Bergsten <ha...@gefionsoftware.com>.
Marcelo Flores A. wrote:
> I need help...
>
> I'm have data of javabeans than have other javabeans with attribute.
>
> class MyClass1
> {
> String name;
> MyClass2 myClass2;
> }
>
> class MyClass2
> {
> String name2;
> }
>
> how I have across sintax tag the name2' s value only with object MyClass1
>
> <jsp:getProperty name="MyClass1" property="name2"> throw a error.
>
> I don't know how do it----
I know you've already received a number of answers, but since each one
just gives you a piece of the solution, let me give it a try as well.
First, <jsp:getProperty> and JSTL can not access public fields in a
class, only bean getter methods. So no matter if you want to use JSTL
or not, you need to expose all data you want to access through getter
methods. Depending on what makes sense for your application, you can
expose "name2" directly in MyClass1:
1)
class MyClass1 {
String name;
MyClass2 myClass2;
...
public String getName() {return name;}
public String getName2() {return myClass2.name;} // public field
}
or expose MyClass2 in MyClass1, and then expose "name2" in MyClass 2:
2)
class MyClass1 {
String name;
MyClass2 myClass2;
...
public String getName() {return name;}
public String getMyClass2() {return myClass2}
}
class MyClass2 {
String name2;
...
public String getName2() {return name2;}
}
Without JSTL, you can now get "name2" like this:
1)
<jsp:useBean id="myClass1" class="com.foo.MyClass1" />
<jsp:getProperty name="myClass1" property="name2" />
2)
<jsp:useBean id="myClass1" class="com.foo.MyClass1" />
<%
// Must use scripting to get MyClass2 first
MyClass2 myClass2 = myClass1.getMyClass2();
// Must save in a JSP scope for getProperty to find it
pageContext.setAttribute("myClass2", myClass2);
%>
<jsp:getProperty name="myClass2" property="name2" />
With JSTL, case 2) it's much easier:
1)
<jsp:useBean id="myClass1" class="com.foo.MyClass1" />
<c:out value="${myClass1.name2}" />
2)
<jsp:useBean id="myClass1" class="com.foo.MyClass1" />
<c:out value="${myClass1.myClass2.name2}" />
For details about using JSTL, see <http://java.sun.com/products/jsp/jstl/>
I hope this helps,
Hans
--
Hans Bergsten hans@gefionsoftware.com
Gefion Software http://www.gefionsoftware.com
JavaServer Pages http://TheJSPBook.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>