• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting Bean Property of type TestClass

 
Raul Martinez
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Raul Martinez
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic