File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes How can we set integer or other type values in standard action jsp:useBean...jsp:setProperty? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "How can we set integer or other type values in standard action jsp:useBean...jsp:setProperty?" Watch "How can we set integer or other type values in standard action jsp:useBean...jsp:setProperty?" New topic
Author

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

Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72
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?


Working on my SCWCD so I can be a J2EE consultant earning millions of dollars and showing everyone I can
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1715
    
  25

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

Joined: Nov 08, 2008
Posts: 72
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
Bartender

Joined: Apr 07, 2010
Posts: 1715
    
  25

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

Joined: Nov 08, 2008
Posts: 72
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can we set integer or other type values in standard action jsp:useBean...jsp:setProperty?