connect jsp with oracle database - oracle

I wrote the following code to fetch data from my oracle database and show the result using JSP:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# page import="java.io.*,java.util.*,java.sql.*"%>
<%# page import="javax.servlet.http.*,javax.servlet.*" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<head>
<title>SELECT Operation</title>
</head>
<body>
<sql:setDataSource var="snapshot" driver="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:#localhost:1521:orcl"
user="hr" password="Hrone699"/>
<sql:query dataSource="${snapshot}" var="result">
SELECT No from Client;
</sql:query>
<table border="1" width="100%">
<tr>
<th>No</th>
<th>Client</th>
<th>Information Collection Date</th>
<th>Payment Notice Date</th>
</tr>
<c:forEach var="row" items="${result.row}">
<tr>
<td><c:out value="${row.No}"/></td>
<td><c:out value="${row.Client}"/></td>
<td><c:out value="${row.INFOCOLLECTINGDATE}"/></td>
<td><c:out value="${row.PAYMENTNOTICEISSUEDATE}"/></td>
</tr>
</c:forEach>
</table>
</body>
But I am getting the following error:
An Error Occurred:
SELECT No from Client; : ORA-00911: invalid character
With the following Stack Trace:
javax.servlet.ServletException:
SELECT No from Client;
: ORA-00911: invalid character
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:951)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:886)
at org.apache.jsp.dataBaseConnect_jsp._jspService(dataBaseConnect_jsp.java:111)
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 com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:630)
at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:363)
at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:153)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:253)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
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: java.sql.SQLException: ORA-00911: invalid character
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:330)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:287)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:753)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:218)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:812)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1050)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:853)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1155)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3414)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3459)
at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doEndTag(QueryTagSupport.java:257)
at org.apache.jsp.dataBaseConnect_jsp._jspx_meth_sql_query_0(dataBaseConnect_jsp.java:172)
at org.apache.jsp.dataBaseConnect_jsp._jspService(dataBaseConnect_jsp.java:88)
... 52 more

Just remove semicolon(";") from sql statement because oracle driver don't required to end sql statement with semicolon but you have to mention semicolon(";") when you are working with MySQL DataBase(mysql-connector driver)

Related

Struts 1.....how to set scope for multiple page in dis as how to set same list scope for /delete.do link

<%#page import="com.details.EmpDetails"%>
<%#page import="java.util.ArrayList"%>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%#taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%#taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Employee Details</title>
</head>
<body>
<%-- <%ArrayList<EmpDetails> a = (ArrayList<EmpDetails>)request.getAttribute("emp"); %> --%>
<table border="1" width="100%">
<tr>
<th>Emp ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Salary</th>
<th>Address</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<logic:iterate id="emp" name="list">
<tr align="center">
<td><bean:write name="emp" property="empId"/></td>
<td><bean:write name="emp" property="name" /></td>
<td><bean:write name="emp" property="lname" /></td>
<td><bean:write name="emp" property="sal" /></td>
<td><bean:write name="emp" property="address" /></td>
<td><form method="post">
<button>Edit</button>
</form></td>
<td>
<form id="frm" action="delete.do" method="post">
<input type="hidden" name="del" value=<bean:write name="emp" property="empId"/>>
<input type="Submit" value="Delete">
</form>
</td>
</tr>
</logic:iterate>
</table>
</body>
</html>
Error for this page
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "list" in any scope
how to set scope for multiple page in dis as how to set same list scope for /delete.do link
can u please tell any solution for this code to set list scope for overall session or application so that i can access it from anywhere
no need to answer this question i got my answer
ANSWER
you have to use httpsession to setAttribute for whole session then we can use list anywhere in whole application

org.apache.jasper.JasperException: An exception occurred processing JSP page using spring and hibernate

org.apache.jasper.JasperException: An exception occurred processing JSP page /person.jsp at line
</c:if>
<tr> <td> <form:label path="name">
<spring:message text="Name"/>
</form:label></td>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:574)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:471)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

get the MovieRecommendation throw exception

i use spring data neo4j to work,i have a repository to recommend movie,i think cypher have not problem,and i can get the recommendation,but i can not get the value of Movie.title and rating ,why it shows movie id not property to the recommendation.class,in my log and error info you can see,why ?
i have severl similar problems,it seems cant get the value in jsp?help me thank you very much .heart man
recommendation.class
package com.oberon.fm.domain;
import org.springframework.data.neo4j.annotation.QueryResult;
#QueryResult
public class MovieRecommendation {
Movie movie;
int rating;
the repository
#Query("match (user:User {login: {0}})-[r:RATED]->(movie)<-[r2:RATED]-(other)-[r3:RATED]->(otherMovie) "
+ " where r.stars >= 3 and r2.stars >= r.stars and r3.stars >= r.stars "
+ " with otherMovie, avg(r3.stars) as rating, count(*) as cnt"
+ " order by rating desc, cnt desc"
+ " return otherMovie limit 10")
List<MovieRecommendation> getRecommendations(String login);
my controller
#RequestMapping(value = "/user", method = RequestMethod.GET)
public String profile(Model model, HttpServletRequest request) {
// User user=populator.getUserFromSession();
HttpSession session = request.getSession(false);
User user = (User) session.getAttribute("user");
model.addAttribute("user", user);
if (user != null) {
List<MovieRecommendation> mr = movieRepository.getRecommendations(user.getLogin());
model.addAttribute("recommendations", mr);
}
return "user/index";
}
index.jsp
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<%--#elvariable id="user" type="com.oberon.fm.domain.User"--%>
<%--#elvariable id="recommendations"type="java.util.List<com.oberon.fm.domain.MovieRecommendation>"--%>
<%--#elvariable id="recommendation"type="com.oberon.fm.domain.MovieRecommendation"--%>
<html>
<head>
<title>Profile</title>
<link rel="stylesheet" type="text/css" href="/Web/css/style.css"/>
</head>
<body>
<div class="span-third">
<h2>Your recommendations</h2>
</div>
<div class="span-third last">
<h2>${fn:length(recommendations)}</h2>
</div>
<ul class="rated-movies-list span-all last">
<c:choose>
<c:when test="${not empty recommendations}">
<c:forEach items="${recommendations}" var="recommendation">
<c:set var="movie" value="${recommendation.movie}"/>
<c:set var="stars" value="${recommendation.rating}"/>
<li>
<h4> <a href="<c:url value="/movies/${movie.id}" />"><c:out value="${movie.title}"/>
(${movie.year}) - "${movie.tagline}"</a>
<img class="rating" alt="${stars} stars" src="<c:url value="/images/rated_${stars}.png" />"/>
</h4>
</li>
</c:forEach>
</c:when>
<c:otherwise>
There are no recommendations for you, perhaps you have to add some friends?
</c:otherwise>
</c:choose>
</ul>
<div class="break"></div>
</div>
</div>
i can get the length of recommendation
log and error info
16:19:32.403 [http-nio-8080-exec-8] DEBUG o.s.w.b.a.s.HandlerMethodInvoker - Invoking request handler method: publicjava.lang.String com.oberon.fm.controller.UserController.profile(org.springframework.ui.Model, javax.servlet.http.HttpServletRequest)
16:19:32.403 [http-nio-8080-exec-8] DEBUG o.s.t.jta.JtaTransactionManager - Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
16:19:32.404 [http-nio-8080-exec-8] DEBUG o.s.d.n.s.q.CypherQueryEngineImpl - Executing cypher query: match (user:User {login: {0}})-[r:RATED]->(movie)<-[r2:RATED]-(other)-[r3:RATED]->(otherMovie) where r.stars >= 3 and r2.stars >= r.stars and r3.stars >= r.stars with otherMovie, avg(r3.stars) as rating, count(*) as cnt order by rating desc, cnt desc return otherMovie limit 10 params {0=micha}
16:19:32.739 [http-nio-8080-exec-8] DEBUG o.s.t.jta.JtaTransactionManager - Initiating transaction commit
16:19:32.740 [http-nio-8080-exec-8] DEBUG c.o.fm.controller.UserController - ()()()()()()()()()()()[com.oberon.fm.domain.MovieRecommendation#bc5162, com.oberon.fm.domain.MovieRecommendation#1b8ceab]
16:19:32.740 [http-nio-8080-exec-8] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'user/index'
16:19:32.740 [http-nio-8080-exec-8] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
16:19:32.740 [http-nio-8080-exec-8] DEBUG o.s.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'user/index'; URL [/pages/user/index.jsp]] in DispatcherServlet with name 'context'
16:19:32.740 [http-nio-8080-exec-8] DEBUG o.s.web.servlet.view.JstlView - Added model object 'user' of type [com.oberon.fm.domain.User] to request in view with name 'user/index'
16:19:32.740 [http-nio-8080-exec-8] DEBUG o.s.web.servlet.view.JstlView - Added model object 'recommendations' of type [java.util.ArrayList] to request in view with name 'user/index'
16:19:32.740 [http-nio-8080-exec-8] DEBUG o.s.web.servlet.view.JstlView - Added model object 'org.springframework.validation.BindingResult.user' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'user/index'
16:19:32.740 [http-nio-8080-exec-8] DEBUG o.s.web.servlet.view.JstlView - Forwarding to resource [/pages/user/index.jsp] in InternalResourceView 'user/index'
16:19:33.838 [http-nio-8080-exec-8] DEBUG o.s.web.servlet.DispatcherServlet - Error rendering view [org.springframework.web.servlet.view.JstlView: name 'user/index'; URL [/pages/user/index.jsp]] in DispatcherServlet with name 'context'
org.apache.jasper.JasperException: An exception occurred processing JSP page /pages/user/index.jsp at line 86
83: <c:choose>
84: <c:when test="${not empty recommendations}">
85: <c:forEach items="${recommendations}" var="recommendation">
86: <c:set var="movie" value="${recommendation.movie}"/>
87: <c:set var="stars" value="${recommendation.rating}"/>
88: <li>
89: <h4> <a href="<c:url value="/movies/${movie.id}" />"><c:out value="${movie.title}"/>:
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568) ~[jasper.jar:8.0.15]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470) ~[jasper.jar:8.0.15]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) ~[jasper.jar:8.0.15]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) ~[jasper.jar:8.0.15]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.15]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721) ~[catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466) ~[catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391) ~[catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318) ~[catalina.jar:8.0.15]
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168) ~[spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303) ~[spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618) [servlet-api.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.15]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.15]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.15]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) [catalina.jar:8.0.15]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.15]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) [catalina.jar:8.0.15]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [catalina.jar:8.0.15]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.15]
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) [catalina.jar:8.0.15]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.15]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537) [catalina.jar:8.0.15]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085) [tomcat-coyote.jar:8.0.15]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658) [tomcat-coyote.jar:8.0.15]
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222) [tomcat-coyote.jar:8.0.15]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556) [tomcat-coyote.jar:8.0.15]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513) [tomcat-coyote.jar:8.0.15]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_05]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_05]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.15]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_05]
Caused by: org.apache.jasper.el.JspPropertyNotFoundException: /pages/user/index.jsp(86,26) '${recommendation.movie}' Property 'movie' not found on type com.oberon.fm.domain.MovieRecommendation
at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:120) ~[jasper.jar:8.0.15]
at org.apache.jsp.pages.user.index_jsp._jspx_meth_c_005fset_005f3(index_jsp.java:879) ~[na:na]
at org.apache.jsp.pages.user.index_jsp._jspx_meth_c_005fforEach_005f2(index_jsp.java:818) ~[na:na]
at org.apache.jsp.pages.user.index_jsp._jspx_meth_c_005fwhen_005f2(index_jsp.java:782) ~[na:na]
at org.apache.jsp.pages.user.index_jsp._jspx_meth_c_005fchoose_005f2(index_jsp.java:746) ~[na:na]
at org.apache.jsp.pages.user.index_jsp._jspService(index_jsp.java:171) ~[na:na]
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) ~[jasper.jar:8.0.15]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) [servlet-api.jar:na]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) ~[jasper.jar:8.0.15]
... 49 common frames omitted
You need to have getters for jsp el expressions, it won't recognize public properties.
Change your MovieRecommendation class (and possibly others) to something like this:
#QueryResult
public class MovieRecommendation {
Movie movie;
int rating;
Movie getMovie() { .... }
int getRating() {....}

Spring tiles jsp table records from other class

I try to configure spring with tiles and create a website - one to mane relation -> Klient - Pobyt and got a question regarding configuration.
I have got a class Klient and a class Pobyt, I also set up a view, but I am getting a null pointer exception when using = ${klient.idKlienta} in order to connect a klient to a list of pobyt`s.
I am getting a org.postgresql.util.PSQLException:- Error in postgresSQL syntax.
Using a concrete value in sql works fine.
Any idea what is wrong?
Could yoy help?
Here is the .jsp:
<%#page language="Java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<html >
<head>
<title>Insert title here</title>
</head>
<body>
<sql:setDataSource var="postgres" driver="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/MAS_PRO" user="postgres"
password="qwe" scope="session" />
<sql:query dataSource="${postgres}" var="result">
SELECT * from Pobyt
where idklienta=${klient.idKlienta} // when entering an existing id fe. 1 it works fine
</sql:query>
<table border="1" width="100%">
<tr>
<th>Id Pobytu</th>
<th>Data od</th>
<th>do</th>
<th>Id klienta</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.idpobytu}"/></td>
<td><c:out value="${row.datazameldowania}"/></td>
<td><c:out value="${row.datawymeldowania}"/></td>
<td><c:out value="${row.idklienta}" /></td>
</tr>
</c:forEach>
</table>
</body>
</html>
PobytBean and KlientBean:
public class PobytBean {
private Integer idPobytu;
private Date dataZameldowania;
private Date dataWymeldowania;
private Integer idKlienta;
public class KlientBean {
private Integer idKlienta;
private String imie;
private String nazwisko;
private String nrTelefonu;
private String eMail;
Klient and Pobyt
#Entity
#Table(name = "Klient")
public class Klient implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue
#Column(name="idKlienta")
private Integer idKlienta;
#Column(name = "imie")
private String imie;
#Column(name = "nazwisko")
private String nazwisko;
#Column(name = "nrTelefonu")
private String nrTelefonu;
#Column(name = "eMail")
private String eMail;
#Entity
#Table(name = "Pobyt")
public class Pobyt implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue
#Column(name = "idPobytu")
private Integer idPobytu;
#Column(name = "dataZameldowania")
#Temporal(TemporalType.DATE)
private Date dataZameldowania;
#Column(name = "dataWymeldowania")
#Temporal(TemporalType.DATE)
private Date dataWymeldowania;
#ManyToOne
#JoinColumn(name="idKlienta", insertable=false, updatable=false)
public Klient klient;
private Integer idKlienta;
Here is the .jsp from where I try to get to the concrete list of pobyts
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Pobyty</title>
</head>
<body>
<h1>Lista klientow</h1>
<c:if test="${!empty klienci}">
<table align="left" border="1">
<tr>
<th>Klient id</th>
<th>Imie</th>
<th>Nazwisko</th>
<th>Nr Telefonu</th>
<th>e-Mail</th>
<th>Akcja</th>
</tr>
<c:forEach items="${klienci}" var="klient">
<tr>
<td><c:out value="${klient.idKlienta}" /></td>
<td><c:out value="${klient.imie}" /></td>
<td><c:out value="${klient.nazwisko}" /></td>
<td><c:out value="${klient.nrTelefonu}" /></td>
<td><c:out value="${klient.eMail}" /></td>
<td>Otwórz</td>
</tr>
</c:forEach>
</table>
</c:if>
</body>
</html>
Update:
SEVERE: Servlet.service() for servlet jsp threw exception
org.postgresql.util.PSQLException: org.postgresql.util.psqlexception error syntax error at end of input
(Position 44)
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2101)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1834)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:510)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:386)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doEndTag(QueryTagSupport.java:224)
at org.apache.jsp.WEB_002dINF.views.openKlient_jsp._jspx_meth_sql_005fquery_005f0(openKlient_jsp.java:202)
at org.apache.jsp.WEB_002dINF.views.openKlient_jsp._jspService(openKlient_jsp.java:91)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
at org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:684)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:678)
at org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
at org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
at org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
at org.apache.tiles.renderer.impl.ChainedDelegateAttributeRenderer.write(ChainedDelegateAttributeRenderer.java:76)
at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:336)
at org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:210)
at org.apache.tiles.template.InsertAttributeModel.end(InsertAttributeModel.java:126)
at org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:311)
at org.apache.jsp.WEB_002dINF.views.mainTemplate_jsp._jspx_meth_tiles_005finsertAttribute_005f3(mainTemplate_jsp.java:180)
at org.apache.jsp.WEB_002dINF.views.mainTemplate_jsp._jspService(mainTemplate_jsp.java:94)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:241)
at org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:222)
at org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:690)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:644)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:627)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:321)
at org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:124)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
And the "server is complaining" about:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.tiles.impl.CannotRenderException: ServletException including path '/WEB-INF/views/mainTemplate.jsp'.
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:659)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
org.apache.tiles.impl.CannotRenderException: ServletException including path '/WEB-INF/views/mainTemplate.jsp'.
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:692)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:644)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:627)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:321)
org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:124)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
I tried to search for logs and what I have found is:
Tomcat log:
0:0:0:0:0:0:0:1 - - [22/Feb/2014:18:34:40 +0100] "GET /MAS_Koncowy/welcome.html HTTP/1.1" 200 1786
0:0:0:0:0:0:0:1 - - [22/Feb/2014:18:34:43 +0100] "GET /MAS_Koncowy/klienci.html HTTP/1.1" 200 2441
0:0:0:0:0:0:0:1 - - [22/Feb/2014:18:34:44 +0100] "GET /MAS_Koncowy/openKlient.html?id=1 HTTP/1.1" 500 17745
In Pg_log I have found what I`ve already posted:
2014-02-22 18:43:36 CET error syntax error at end of input (Position 44)
2014-02-22 18:43:36 CET Query:
SELECT * from Pobyt
where idKlienta =
So the problem is the idKlienta is not passed to the query? How can I solve it?

AJax Callback fails (NPE) on selectoneitem

Used this StackOverflow answer to try an implement a submitless form. The page consists of a selectomenu control and a table. On change of the selection I wish to refresh the table body. The page loads without issues, but when the selection is made I get the following error occurs:
10:22:48,241 ERROR [[FacesServlet]] Servlet.service() for servlet FacesServlet threw exception: java.lang.NullPointerException
at com.sun.faces.context.PartialViewContextImpl.createPartialResponseWriter(PartialViewContextImpl.java:441) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.context.PartialViewContextImpl.access$300(PartialViewContextImpl.java:71) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.context.PartialViewContextImpl$DelayedInitPartialResponseWriter.getWrapped(PartialViewContextImpl.java:582) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.context.PartialResponseWriter.startDocument(PartialResponseWriter.java:115) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:199) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:123) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:505) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:445) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:636) [rt.jar:1.6.0_18]
I'm using JBoss-AS-7.1.1, and the selectonmenu looks like this:
<h:selectOneMenu id="ship"
value="#{shipManager.current}">
<f:selectItems value="#{shipManager.list}"
var="ship"
itemValue="#{ship}"
itemLabel="#{ship.name}" />
<f:ajax listener="#{shipManager.changeShip}" />
</h:selectOneMenu>
If I remove the ajax component then no issues although (of course) the shipManager is not updated.
Once I have the selection made I would then like to add the renderer part to refresh my table body.
Many thanks for any help given.
Steve
As requested here is my XHTML code:
<?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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Voyage Cruises</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link type="text/css" rel="stylesheet" media="all" href="/css/screen.css"/>
<link type="text/css" rel="stylesheet" media="all" href="/css/cruise.css"/>
<script src="http://open.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js"></script>
<script src="js/map.js" ></script>
<script src="js/cruise.js" ></script>
</h:head>
<h:body>
<div id="page">
<div id="float-map">
<div id="map"></div>
</div>
<h:form id="ship-form">
<div id="ship-controls">
<div class="float-ctrls">
<img src="/images/action_search.png" alt="Find Ports"/>
</div>
<div>
<span id="ship-selector" >
<h:selectOneMenu id="ship"
value="#{shipManager.current}">
<f:selectItems value="#{shipManager.list}"
var="ship"
itemValue="#{ship}"
itemLabel="#{ship.name}" />
<f:ajax execute="ship" render="#form" listener="#{shipManager.changeShip}" />
</h:selectOneMenu>
</span>
<select id="month" />
<select id="year" />
<br />
<span class="input-container"><b>Tonnage:</b><input id="tonnage" type="text" size="6" value="30,277" /></span>
<span class="input-container"><b>Audit Time:</b><input id="audit" type="text" size="2" value="6" /></span>
<span class="input-container"><b>Fleet:</b><input id="fleet" type="text" size="20" value="P&O" /></span>
</div>
</div>
<table class="cruise">
<thead>
<tr>
<th class="date">Date</th>
<th class="port">Port</th>
<th class="arrive">Arrive</th>
<th class="depart">Depart</th>
</tr>
</thead>
<tbody>
<ui:repeat var="cruise"
value="#{cruiseManager.list}"
varStatus="table">
<tr class="#{table.even ? 'even' : 'odd'}">
<td class="date">
<h:outputFormat value="{0, date,d MMM}">
<f:param value="#{cruise.date}" />
</h:outputFormat>
</td>
<h:panelGroup rendered="#{null != cruise.port}">
<td class="port">#{cruise.port.name}</td>
<td class="arrive">
<h:outputFormat rendered="#{null != cruise.arrival}"
styleClass="#{cruise.arrivalEstimated ? 'est-time' : 'act-time'}"
value="{0, date,HH:mm}">
<f:param value="#{cruise.arrival}" />
</h:outputFormat>
</td>
<td class="depart">
<h:outputFormat rendered="#{null != cruise.departure}"
styleClass="#{cruise.departureEstimated ? 'est-time' : 'act-time'}"
value="{0, date,HH:mm}">
<f:param value="#{cruise.departure}" />
</h:outputFormat>
</td>
</h:panelGroup>
<h:panelGroup rendered="#{null == cruise.port}">
<td class="at-sea" colspan="3">At Sea</td>
</h:panelGroup>
</tr>
</ui:repeat>
</tbody>
</table>
</h:form>
</div>
</h:body>
</html>
And the ShipManager:
package com.nutrastat.voyager.web;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.AjaxBehaviorEvent;
import com.nutrastat.voyager.db.HarbourMasterLocal;
import com.nutrastat.voyager.db.ShipEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
#ManagedBean
#ViewScoped
public class ShipManager
implements Serializable {
static final long serialVersionUID = -3017226836104715117L;
private transient final Logger log;
private ShipEntity currentShip;
#EJB
private HarbourMasterLocal harbourMaster;
public ShipManager() {
log = LoggerFactory.getLogger(getClass());
}
public ShipEntity getCurrent() {
if (log.isInfoEnabled())
log.info("getCurrent(): " + currentShip);
return currentShip;
}
public void setCurrent(ShipEntity ship) {
if (log.isInfoEnabled())
log.info("setCurrent(" + currentShip + "): " + ship);
currentShip = ship;
}
public void changeShip(AjaxBehaviorEvent evt) {
if (log.isInfoEnabled())
log.info("Ship now: " + currentShip);
}
public List<ShipEntity> getList() {
try {
return harbourMaster.listShips();
} catch (Exception cause) {
log.error("Getting the list of ships", cause);
return new ArrayList<ShipEntity>(0);
}
}
}
Your stack trace looks incomplete in that it doesn't actually refer to your code(which is where I'd expect the npe be thrown). That notwithstanding, your select menu doesn't have a converter, so any other problems aside, your form would probably still not save or register the selection
Implement a JSF converter and declare it on that selectonemenu. This is mandatory when a select type component needs to select and save complex POJO types You can look at this example
Try to get rid of that gigantic <h:form/> in your markup. There are too many other components in that form that could be causing you problems. Break the components into smaller chunks in separate forms
If the scope of your bean is #RequestScoped then change it to #ViewScoped , in general ajax better be done with #ViewScoped... cause new instance of the bean created upon each submit...
#ManagedBean(name="shipManager")
#ViewScoped
Also Make sure that the changeShip method takes AjaxBehaviorEvent as the parameter
(ie)
public void changeShip (AjaxBehaviorEvent event){
//** do your stuf
}
and also specidy the execute and Render attributes inside f:Ajax
<f:ajax execute="ship" render="#form" listener="#{shipManager.changeShip}" />

Resources