This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 1520
    
  22

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: 1520
    
  22

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!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How can we set integer or other type values in standard action jsp:useBean...jsp:setProperty?
 
Similar Threads
org.apache.jasper.JasperException: Can't find a method to write property
can't find information in property"access" in a bean of type 'ministry.LoginBeans'
Problem using Java Beans
JSP useBean attribute
org.apache.jasper.JasperException: java.lang.NullPointerException