HQL - List country and fetch all the state and currency - java

I wanted to list all countries to fetch all the respective state and currency.
ConfFacade.java
public Result<List<Country>> listCountries() {
try {
String HQL = "SELECT DISTINCT o FROM Ocountry o LEFT JOIN FETCH o.ostate, o.ocurrency";
List<Country> list = em.createQuery(HQL).getResultList();
return new Result(Status.SUCCESS, list);
} catch(Exception e) {
e.printStackTrace();
return new Result<>(Status.ERROR, Exception.GENERAL, e.getMessage());
}
}
ConfFacadeLocal.java
public interface ConfFacadeLocal {
public Result<List<Country>> listCountries();
}
This is the jsp that I use and code it:
listCountries.jsp
<%
try {
InitialContext ctx = new InitialContext();
ConfFacadeLocal confFacadeLocal = (ConfFacadeLocal)ctx.lookup("java:comp/env/tomin");
Result<List<Country>> result = confFacadeLocal.listCountries();
if(result.isUnsuccessful()) {
throw new Exception(result.getErrMsg());
}
List<Country> countryList = result.getObject();
if(countryList == null) {
throw new Exception("Error.");
}
out.print("OK");
%>
<table border="1" align="center" style="width:50%">
<thead>
<tr>
<th>country code</th>
<th>currency code</th>
<th>state id</th>
<th>state description</th>
</tr>
</thead>
<tbody><%
for (Ocountry country : countryList){ %>
<tr>
<td><%=country.getOccode()%></td>
<td><%=country.getOcurrency().getOcucode()%></td>
<td><%=country.getOstate().getOsid()%></td>
<td><%=country.getOstate().getOsdesc()%></td>
</tr><%
}
} catch (Exception e) {
e.printStackTrace();
out.print("Error: " + e.getMessage());
} %>
</tbody>
</table>
Here is the error that I get:
cannot find symbol
symbol: method getOstate()
location: variable country of type com.ejb.entities.conf.Country
PWC6197: An error occurred at line: 42 in the jsp file: /country/listCountries.jsp
PWC6199: Generated servlet error:
cannot find symbol
symbol: method getOstate()
location: variable country of type com.ejb.entities.conf.Country
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:129)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:299)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:392)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:453)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:625)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
Can anyone help to fix it?

From your JSP error logs, I guess you missed to declare the #listCountries method to the ConfFacadeLocal bean interface.
Adding the needed method declaration to the interface should resolve the issue:
public interface ConfFacadeLocal {
// other API methods ...
public Result<List<Country>> listCountries();
}

There (line 41):
<td><%=currency.getOcucode()%></td>
you are using the currency variable, which has not been declared.
It seems that currency is an attribute of the 'Country' class in you program, so maybe you should write instead
<td><%=country.getCurrency().getOcucode()%></td>
You have the same problem with the 'state' variable.

Related

JSP throwing Null Pointer Exception

I keep getting a Null Pointer Exception, and I can't tell from the stack trace exactly what is causing it. It seems to point to line 83 in DisplayAccounts.jsp but the file is only 48 lines long...
After logging in, the LoginServlet is supposed to direct user to DisplayAccounts.jsp
Any help would be greatly appreciated. I can't seem to figure it out.
DisplayAccounts.jsp:
<h1>Customer Accounts</h1>
<table>
<tr>
<th>Account Number</th>
<th>Customer ID</th>
<th>Account Type</th>
<th>Account Balance</th>
</tr>
<% ArrayList accounts = (ArrayList)session.getAttribute("customer.list");
for(int i = 0; i < accounts.size(); i++) {
Account account = (Account)accounts.get(i); %>
<tr>
<td><% out.print(account.getAcctNo());%></td>
<td><% out.print(account.getcID());%></td>
<td><% out.print(account.getType());%></td>
<td><% out.print(account.getBalance());%></td>
</tr>
<% } %>
</table>
LoginServlet.java :
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String id;
String pw;
int idDB;
String pwDB;
HttpSession session;
try{
id = request.getParameter("custID");
pw = request.getParameter("pswd");
System.out.println("ID: " + id);
System.out.println("Password: " + pw);
idDB = Integer.parseInt(id);
Customer c1 = new Customer();
c1.selectDB(idDB);
pwDB = c1.getCustPassword();
// Add user to session
session = request.getSession();
session.setAttribute("customer", c1);
System.out.println("User added to session");
if (pw.equals(pwDB)){
// Send user to account look up page
RequestDispatcher rd = request.getRequestDispatcher("DisplayAccount.jsp");
rd.forward(request, response);
}
else{
// Send user to error page
RequestDispatcher rd = request.getRequestDispatcher("ErrorPage.jsp");
rd.forward(request, response);
}
}
catch(ServletException e){
System.out.println("A Servlet Excpetion has occured");
System.out.println(e.getMessage());
System.out.println(e.getStackTrace());
}
catch(IOException e){
System.out.println("An IO Exception has occured");
System.out.println(e.getMessage());
}
catch(Exception e){
System.out.println("An error has occurred.");
System.out.println(e.getMessage());
}
}
Exception Stack Trace:
Info: A Servlet Excpetion has occured
Info: java.lang.NullPointerException
Info: java.lang.NullPointerException
at org.apache.jsp.DisplayAccount_jsp._jspService(DisplayAccount_jsp.java:83)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:575)
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:546)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:428)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:378)
at Chatt_Bank.LoginServlet.processRequest(LoginServlet.java:45)
at Chatt_Bank.LoginServlet.doPost(LoginServlet.java:80)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:748)
Here
ArrayList accounts = (ArrayList)session.getAttribute("customer.list");
accounts is null. You haven't set a HttpSession parameter with a name of customer.list using
HttpSession#setAttribute(String name, Object o)
(setAttribute) inside your LoginServlet#processRequest method. So, when
if (pw.equals(pwDB)){
You're forwarding to DisplayAccount.jsp without that value.
You need to add
session.setAttribute("customer.list", customerList);
You cannot do what you want to do, you need another attribute
session.setAttribute("customerList", c1.list); // or c1.getList() if you have a getter

Java MySQLSyntaxErrorException? Why is my SELECT statement incorrect?

This is my code for a web application that connects to a mySQL database. It is supposed to display the entire contents of one table in the database using a drop down menu on another page. I have another .jsp that does basically the same thing with a different SQL statement that performs a search operation, that works as it is supposed to. I figured that if anything I would have a problem with procedural generation of the output html tables, but I am getting a com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException exception for the mySQL statement syntax.
<%--
Document : display
Created on : Nov 22, 2018, 11:43:54 AM
Author : Scott
--%>
<%#page import="java.sql.*" %>
<%
try {
Class.forName("com.mysql.jdbc.Driver");
} catch(ClassNotFoundException e) {
System.out.println("Unable to load driver class!");
}
%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Henry Books</title>
</head>
<body>
<h1>Henry Books Store Database Table View </h1>
<%!
public class Table {
String URL = "jdbc:mysql://localhost:3306/HenryBooks?autoReconnect=true&useSSL=false";
String USERNAME = "root";
String PASSWORD = "SAvick4078100";
Connection connection = null;
PreparedStatement viewTable = null;
ResultSet resultSet = null;
public Table(){
try{
connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
viewTable = connection.prepareStatement(
"SELECT * FROM ?"
);
} catch (SQLException e) {
e.printStackTrace();
}
}
public ResultSet getTable(String tableSelection) {
try{
viewTable.setString(1, tableSelection);
resultSet = viewTable.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
return resultSet;
}
}
%>
<%
String tableSelect = new String();
//recieves input value from dropdown menu name "table option" in index.jsp
if(request.getParameter("table option") != null) {
tableSelect = request.getParameter("table option");
}
Table view = new Table();
ResultSet tableView = view.getTable(tableSelect);
ResultSetMetaData rsMetaData = tableView.getMetaData();
int cols = rsMetaData.getColumnCount();
String[] colNames = new String[cols];
for(int i = 0; i < cols; i++) {
colNames[i] = rsMetaData.getColumnName(i+1); //i+1 because the column name index in the ResultSetMetaData begins at 1, not 0
}
%>
<table border="1">
<thead>
<tr>
<% for(int i = 0; i < cols; i++) { %>
<th><%= tableView.getString(colNames[i])%></th>
<% } %>
</tr>
</thead>
<tbody>
<% while(tableView.next()) { %>
<tr>
<% for(int i = 0; i < cols; i++) { %>
<td><%= tableView.getString(colNames[i])%></td>
<% } %>
</tr>
<% } %>
</tbody>
</table>
</body>
</html>
However, I am receiving these error messages and I am not sure what is wrong with my SQL syntax here.
Severe: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Author'' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2495)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1903)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2011)
at org.apache.jsp.display_jsp$Table.getTable(display_jsp.java:36)
at org.apache.jsp.display_jsp._jspService(display_jsp.java:113)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:748)
Warning: StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.display_jsp._jspService(display_jsp.java:114)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:748)
using
"SELECT * FROM ?"
for dynamically adding table name will lede to query being
SELECT * FROM 'TABLE_NAME'
instead append table name dynamically by just contacting the string like this:
"SELECT * FROM "+tableName
where tableName will be a variable of type string.

Why do i get an EJB java.rmi.MarshalException: CORBA MARSHAL exception?

I'm trying to add items using a JSP page which has a couple of images too. I declared the variables to retrieve images as strings so i can get the URL and store the url in the database.
I'm using EJB and JPA for database purposes.
my code for the servlet
ItemDetails id;
ItemBeanRemote ib;
#Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String id = request.getParameter("id");
String name = request.getParameter("name");
double price = Double.valueOf(request.getParameter("price"));
String imgurl = request.getParameter("imgurl");
String imgurl2 = request.getParameter("imgurl2");
String location = request.getParameter("loc");
id = new ItemDetails(id, name, price, imgurl, imgurl2, location);
ib.addItem(id);
response.sendRedirect("View.jsp");
}
#Override
public void init() {
try {
Context initial = new InitialContext();
ib = (ItemBeanRemote) initial.lookup("itembean");
} catch (Exception ex) {
System.err.println("Caught an exception:");
ex.printStackTrace();
}
//ejb class that has the code to the addItem method
#Override
public void addEvent(ItemDetails details) {
try {
tblItem utt = new tblItem(details.getItemID(),details.getItemName(),
details.getPrice(),details.getImgUrl(),details.getImgUrl2(),details.getLocation());
em.persist(utt);
} catch (Exception ex) {
throw new EJBException(ex);
}
//item details is a class is a POJO with getters and setters
//tblItem is the java class that was created using an entity manager which has auto generated code from JPA.
And the exception
javax.ejb.EJBException: java.rmi.MarshalException: CORBA MARSHAL 1330446343 No; nested exception is:
org.omg.CORBA.MARSHAL: ----------BEGIN server-side stack trace----------
org.omg.CORBA.MARSHAL: FINE: 00810007: Underflow in BufferManagerReadStream after last fragment in message vmcid: OMG minor code: 7 completed: No
at com.sun.proxy.$Proxy154.endOfStream(Unknown Source)
at com.sun.corba.ee.impl.encoding.BufferManagerReadStream.underflow(BufferManagerReadStream.java:122)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_1.grow(CDRInputStream_1_1.java:111)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_2.alignAndCheck(CDRInputStream_1_2.java:126)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_long(CDRInputStream_1_0.java:433)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.readValueTag(CDRInputStream_1_0.java:1672)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:918)
at com.sun.corba.ee.impl.encoding.CDRInputObject.read_value(CDRInputObject.java:518)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$14.read(DynamicMethodMarshallerImpl.java:383)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.readArguments(DynamicMethodMarshallerImpl.java:450)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:171)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.SharedCDRClientRequestDispatcherImpl.marshalingComplete(SharedCDRClientRequestDispatcherImpl.java:119)
at com.sun.corba.ee.impl.protocol.ClientDelegateImpl.invoke(ClientDelegateImpl.java:258)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:198)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:150)
at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(CodegenStubBase.java:226)
at com.olympics2016.beans.__EventBeanRemote_Remote_DynamicStub.addEvent(com/olympics2016/beans/__EventBeanRemote_Remote_DynamicStub.java)
at com.olympics2016.beans._EventBeanRemote_Wrapper.addEvent(com/olympics2016/beans/_EventBeanRemote_Wrapper.java)
at com.olympics2016.servlets.AddEventServlet.doPost(AddEventServlet.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
----------END server-side stack trace---------- vmcid: OMG minor code: 7 completed: No
Marshal Exception can occur due to one of the reasons as below :
1) when remote method call is done and no marshaling is done of Java Object and thus the argument or return value will not reach to remote method or to server.
2) If the protocol we are using in RMI is of different versions at sender and receivers side.

I need help identifying where my null pointer exception is coming from

I am using PrimeFaces 4.0, NetBeans associated with two xhtml pages. The xhtml renders a select one radio menu from which the user may select an experiment about which they'd like more information. When they do, I'd like for the xhtml to pass the experiment back to java as a string. After the user hits submit, I'd like another xhtml page to open from which the user can further narrow their search criteria. As of right now, when the user clicks submit, there is a null pointer exception. Also, using System.out.println(), I can see that java is not getting the string back from the web page as my Glassfish server output prints (in part) : "Info: nullaaaaaaaaaaaaaaaaaaaaa". It doesn't print the other println() at all.
XHTML portion
<h:form>
<h:panelGrid>
<p:selectOneRadio id="Test" value="Please Selecte a Test">
<p:ajax update="Test" partialSubmit="#{targetBeantFranz.selectedNameOfExperiments}"/>
<f:selectItems value="#{targetBeantFranz.nameofexperiments}" />
</p:selectOneRadio>
<h:commandButton value="Select" action="open" />
</h:panelGrid>
</h:form>
and here are the affected Java methods (The entire JAVA file is much, much longer than this):
#ManagedBean(name = "targetBeantFranz", eager = true)
#SessionScoped
public class TargetBeanFranz implements Serializable {
public String selectedNameOfExperiments;
private final Map<String, String> nameofexperiments;
public TargetBeanFranz() throws SQLException {
nameofexperiments = new HashMap<String, String>();
XYexpdataServiceAdapter xydata = new XYexpdataServiceAdapterImpl();
List<String> dbnameofexperiments = xydata.getNameofexperiments();
for (String ta : dbnameofexperiments) {
nameofexperiments.put(ta, ta);
}
}
public String getSelectedNameOfExperiments() {
System.out.println(selectedNameOfExperiments + "aaaaaaaaaaaaaaaaaaaaa");
return selectedNameOfExperiments;
}
public void setSelectedNameOfExperiments(String selectedNameOfExperiments) {
System.out.println(selectedNameOfExperiments + "bbbbbbbbbbbbbbbbbbbbbbbbb");
this.selectedNameOfExperiments = selectedNameOfExperiments;
}
}
public Map<String, String> getNameofexperiments() {
return nameofexperiments;
}
}
ETA: My stacktrace looks like this:
java.lang.NullPointerException
at javax.faces.component.SelectItemsIterator$MapIterator.next(SelectItemsIterator.java:346)
at javax.faces.component.SelectItemsIterator$MapIterator.next(SelectItemsIterator.java:315)
at javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:155)
at javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:64)
at javax.faces.component.SelectUtils.matchValue(SelectUtils.java:86)
at javax.faces.component.UISelectOne.validateValue(UISelectOne.java:153)
at javax.faces.component.UIInput.validate(UIInput.java:983)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1249)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at org.primefaces.component.layout.Layout.processValidators(Layout.java:233)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:745)
Check this article for further info about JSF UI component <h:selectOneMenu> .
it might be the case that u need to initialize in the bean's constructor: selectedNameOfExperiments

Pass value of same component as parameter to p:ajax listener: "PropertyNotFoundException"

I already typed the value within the brackets ('06717-100'), and the method is working, but I don't know how to pass the value of that same component as a parameter. I want the user to type a zipcode in a p:inputMask, and when focus is lost (or - would be better - when the maximum length of the field is reached) the method for searching it in the database is called.
<h:form id="frm">
<h:panelGrid>
<p:outputPanel autoUpdate="true"
id="pnl">
<p:inputMask id="txtCep"
mask="99999-999"
placeholder="Digite o CEP"
value="#{cepMB.cep.cep}">
<p:ajax event="blur"
listener="#{cepMB.busca('06717-100')}"
process="#this"
update="frm:pnl" />
</p:inputMask>
And below is the code of method busca:
public void busca(String cep) {
Cep c = this.cepRepository.findByCep(cep);
if(c.getId() != null) {
this.cep = c;
}
}
I'm using JSF 2.2, PrimeFaces 4.0, GlassFish 4.0 and Hibernate 4.3.1 with JPA 2.1.
Stacktrace:
AdvertĂȘncia: javax.el.PropertyNotFoundException: /principal.xhtml #59,31 value="#{cepMB.cep.cep}": Target Unreachable, 'null' returned null
javax.faces.FacesException: javax.el.PropertyNotFoundException: /principal.xhtml #59,31 value="#{cepMB.cep.cep}": Target Unreachable, 'null' returned null
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:270)
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1193)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:744)
Caused by: javax.el.PropertyNotFoundException: /principal.xhtml #59,31 value="#{cepMB.cep.cep}": Target Unreachable, 'null' returned null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at org.primefaces.util.ComponentUtils.getConverter(ComponentUtils.java:124)
at org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:183)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046)
at javax.faces.component.UIInput.validate(UIInput.java:976)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1249)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:552)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1689)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIForm.visitTree(UIForm.java:371)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:399)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:263)
... 33 more
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, 'null' returned null
at com.sun.el.parser.AstValue.getTarget(AstValue.java:192)
at com.sun.el.parser.AstValue.getType(AstValue.java:86)
at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201)
at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93)
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
... 50 more
#{cepMB.cep} refers to entity Cep, and #{cepMB.cep.cep} refers to public String getCep() of Cep.
Change your JSF code to:
<p:inputMask id="txtCep"
mask="99999-999"
placeholder="Digite o CEP"
value="#{cepMB.cep.cep}">
<p:ajax event="blur"
listener="#{cepMB.busca(cepMB.cep.cep)}"
process="#this"
update="frm:pnl" />
</p:inputMask>
Also, make sure your cep field in your cepMB is always initialized with a right not null value:
#ManagedBean
#ViewScoped
public class CepMB {
Cep cep;
#PostConstruct
public void init() {
cep = new Cep();
}
//rest of your getters, setters, code...
}

Categories

Resources