wood burning stoves*
The moose likes JSP and the fly likes Setting Bean Property of type TestClass Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Setting Bean Property of type TestClass" Watch "Setting Bean Property of type TestClass" New topic
Author

Setting Bean Property of type TestClass

Raul Martinez
Greenhorn

Joined: Mar 01, 2004
Posts: 17
My sitation " Setting Property of Bean in JSP"

The Bean:


The JSP:

[TOMCAT ERROR]
Unable to convert string '<% new test.TestClass("Test 1",99); %>' to class test.TestClass for attribute testClass: java.lang.IllegalArgumentException: Property Editor not registered with the PropertyEditorManager
[/TOMCAT ERROR]
I know the setProperty syntax is correct (hmmm) for datatype such as int, Int, etc. But how do I set the attibute of a certain bean, wherein this attribute is an instance of a class? (TestClass in this case)
jm


Learning new things, I LIKE!<p>---certification---<br />none so far, experience (considerable, yeah)
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
try

You can't use codeblocks like you're attempting.
You could use

but that would get translated into something like

which is not what you want I think.
[ March 11, 2004: Message edited by: Jeroen Wenting ]

42
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
In your code, Tomcat is trying to perform type coversion for you. However, it cannot convert TestClass to String, and thus it throws an Exception.
Since the value should be in string literal, while now it is an object, the type conversion fails.
In your case, you should not use the setProperty to set the object into the bean, instead you can do the following:

Nick.
[ March 11, 2004: Message edited by: Nicholas Cheung ]

SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Raul Martinez
Greenhorn

Joined: Mar 01, 2004
Posts: 17
Originally posted by Jeroen Wenting:
You can't use codeblocks like you're attempting.
You could use

but that would get translated into something like

which is not what you want I think.
[ March 11, 2004: Message edited by: Jeroen Wenting ][/QB]

This is what I want. thanks also, nick!
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Hi Raul,
If the toString() method is what you need, you can simply change your code to:

In addition, since the container will directly call Object.toString() on your object, if you need customize the string you get, you can override the toString() method in your class.

Nick.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Setting Bean Property of type TestClass