• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can we set integer or other type values in standard action jsp:useBean...jsp:setProperty?

 
Swagato Bhatta
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take a look at the three codes below.

* Here all I am trying to do is set two properties (name and empID) of two beans (Person and Employee) to string value "Swagato" and the integer value 10.
* Then on the same page get those values printed back .


Here are the two beans




When I try to run/deploy it in Tomcat, I get nullpointerexception as in below



How can I set integer values for empID? If let us say that in the web.xml file we have disabled the expressions, then how can we do it?

I am more interested to know how can we set any type of values for empID... let us say arrays, lists, ArrayList, or my defined type

What I am really trying to know is that if there are ways to use other than String types and standard actions?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2531
112
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Swagato,

You are getting a NullPointerException because in your second setProperty you are referring to a bean with name employee, but you only have a bean with name person. So if you change:


into


it should work well.

Regards,
Frits
 
Swagato Bhatta
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frits Walraven wrote:Hi Swagato,

You are getting a NullPointerException because in your second setProperty you are referring to a bean with name employee, but you only have a bean with name person. So if you change:


into


it should work well.

Regards,
Frits


What about the 2nd class Employee that extends Person. Is the Employee class not a bean? So why employee bean not found?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2531
112
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are actually instantiating (creating an object) of class foo.Employee, but you are "upcasting" it to a Person (with the type attribute). If you want to create another object foo.Person then you need another line of code:



After these lines you will have created two beans: one Person identified with name person and one Employee with identified with name employee
Regards,
Frits
 
Swagato Bhatta
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frits Walraven wrote:You are actually instantiating (creating an object) of class foo.Employee, but you are "upcasting" it to a Person (with the type attribute). If you want to create another object foo.Person then you need another line of code:



After these lines you will have created two beans: one Person identified with name person and one Employee with identified with name employee
Regards,
Frits


Thanks.. I think I somewhat understand it now!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic