Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JSF
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Paul Clapham
Ron McLeod
Jeanne Boyarsky
Tim Cooke
Sheriffs:
Liutauras Vilda
paul wheaton
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Carey Brown
Frits Walraven
Bartenders:
Piet Souris
Himai Minh
Forum:
JSF
JSF web application nul pointer exception
shadman kudchikar
Greenhorn
Posts: 13
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Please help my website gives null pointer exception when i submit my form
My index.xhtml page
<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html"> <h:head> <title>Facelet Title</title> </h:head> <h:body> <h:form> <h:outputLabel for="product" > <h:outputText value="Product Name" ></h:outputText> </h:outputLabel> <h:inputText value="#{user.pname}" id="product" ></h:inputText> <h:commandButton value="Inser" action="#{user.insert}" ></h:commandButton> </h:form> </h:body> </html>
my newManagedJSFbean
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import javax.inject.Named; import javax.enterprise.context.Dependent; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; /** * * @author Keep Smiling */ @ManagedBean(name="user") @RequestScoped public class NewJSFManagedBean { String pname=""; /** * Creates a new instance of NewJSFManagedBean */ public NewJSFManagedBean() { } // Add business logic below. (Right-click in editor and choose // "Insert Code > Add Business Method") public String getPname() { return pname; } public void setPname(String pname) { this.pname = pname; } public String insert() throws ClassNotFoundException, SQLException { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:adb"); PreparedStatement ps=c.prepareStatement("INSERT INTO product(pname) VALUES(?)"); ps.setString(1,pname); ps.executeUpdate(); return "success"; } }
my faces config page
<?xml version='1.0' encoding='UTF-8'?> <faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"> <navigation-rule > <from-view-id> index.xhtml </from-view-id> <navigation-case> <from-outcome > success </from-outcome> <to-view-id> welcome.xhtml </to-view-id> </navigation-case> </navigation-rule> </faces-config>
Tim Holloway
Saloon Keeper
Posts: 25483
180
I like...
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can you post the stack trace from your server log? Lots of things can cause an NPE. We need the log to help us figure out which thing it was.
Sometimes the only way things ever got fixed is because people became uncomfortable.
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Navigation problems with primefaces tree
Newbie Navigation Question
JSF2 Error
Target Unreachable, identifier resolved to null (JSF 2.0)
java.lang.IndexOutOfBoundsException
More...