aspose file tools*
The moose likes JSF and the fly likes JSF and Mysql connectivity giving error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF and Mysql connectivity giving error" Watch "JSF and Mysql connectivity giving error" New topic
Author

JSF and Mysql connectivity giving error

Waqar Azam
Greenhorn

Joined: Feb 27, 2013
Posts: 6
Hello Experts i am new to JSF, and i am creating a simple database access which just simply prints the database table on the page ... but i cannot access my manged bean class in my jsf page... everytime i run the code the error it shows is {/index.xhtml @12,71 value="#{cityController.allCity}": Target Unreachable, identifier 'cityController' resolved to null} i am attaching my code please have a look at it
CityBean.java


Dbase.java


CityController.java


index.xhtml
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16140
    
  21

Welcome to the JavaRanch, Waqar!

In JSF, you do not normally code Controllers. The Controller part of JSF is the FacesServlet and the support code that implements the various View Template Language elements.

Your NullPointerException comes from naming your CityController (which is actually a Model) with the name "CityController". If you must call it a Controller, call it "cityController" as required by both POJO coding conventions and because that's what your View Template is calling it.

You'll still fail, however, because you have no property access methods. So the EL reference to property "allCity" will not resolve.


Customer surveys are for companies who didn't pay proper attention to begin with.
Waqar Azam
Greenhorn

Joined: Feb 27, 2013
Posts: 6
Tim Holloway wrote:Welcome to the JavaRanch, Waqar!

In JSF, you do not normally code Controllers. The Controller part of JSF is the FacesServlet and the support code that implements the various View Template Language elements.

Your NullPointerException comes from naming your CityController (which is actually a Model) with the name "CityController". If you must call it a Controller, call it "cityController" as required by both POJO coding conventions and because that's what your View Template is calling it.

You'll still fail, however, because you have no property access methods. So the EL reference to property "allCity" will not resolve.


Thanks Tim for giving your time... but i very new to JSF .. would you like elaborate your answer further.... should i rename my "CityController" or what??
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16140
    
  21

You should study up on JavaBeans and POJOs. JSF is based on them, as are many other popular Java technologies.

Until you understand how they work, you can't really understand how JSF works.

What you name the bean isn't really important to JSF, but, as I said, in JSF, you almost never write your own Controller code, so it's not really correct to name a bean "xxxxController". The software won't care, but it mis-informs people reading the code.
Waqar Azam
Greenhorn

Joined: Feb 27, 2013
Posts: 6
Tim Holloway wrote:You should study up on JavaBeans and POJOs. JSF is based on them, as are many other popular Java technologies.

Until you understand how they work, you can't really understand how JSF works.

What you name the bean isn't really important to JSF, but, as I said, in JSF, you almost never write your own Controller code, so it's not really correct to name a bean "xxxxController". The software won't care, but it mis-informs people reading the code.


thanks for the advise ... i will try to follow your advice....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF and Mysql connectivity giving error