I have the following exception at the time of running JSF program.
org.apache.jasper.JasperException: An exception occurred processing JSP page /pages/general/internalServerErrorPage.jsp at line 44
41: <link rel="shortcut icon" href="<%=request.getContextPath()%>/resources/images/infomindzicon.ico" type="image/x-icon" />
42: </head>
43: <body id="sscmsMainBody">
44: <h:form id="internalServerErrorPageForm" binding="#{ServerErrorBean.initForm}">
45: <rich:page id="richPage" theme="#{LayoutSkinBean.layoutTheme}"
46: width="#{LayoutSkinBean.layoutScreenWidth}"
47: sidebarWidth="0">
Caused by: javax.servlet.ServletException: javax.servlet.jsp.JspException: java.lang.IllegalStateException: Parent was not null, but this component not related
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
at org.apache.jsp.pages.general.internalServerErrorPage_jsp._jspService(internalServerErrorPage_jsp.java:207)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
What is the meaning of this exception and how can I resolve this?
Update: My code is below,
public HtmlForm getInitForm() {
validateSession();
return initForm;
}
The validate session method is
private void validateSession() {
HttpSession session = null;
try {
FacesContext facesContext = FacesContext.getCurrentInstance();
actionPanelRendered = false;
if (facesContext != null) {
session = (HttpSession) facesContext.getExternalContext().getSession(false);
if (session != null) {
if (session.getAttribute(SessionAttributes.USER_LOGIN_NAME.getName()) != null) {
actionPanelRendered = true;
}
}
}
} catch(Exception e) {
logger.info("Exception arise in server error bean");
e.printStackTrace();
}
}
It's thus coming from the following line:
<h:form id="internalServerErrorPageForm" binding="#{ServerErrorBean.initForm}">
You've bound the form to the bean for some unknown reason. The exception indicates that this component has a parent, but that this is actually not a parent at all as per the component tree in the JSP page. This in turn indicates that you're doing something like the following in the bean before or during the call of getInitForm() method:
form.setParent(someComponent);
If this is true, then you should remove this line.
Update: another possible cause is that you're forgotten to put a <f:view> around the HTML with the JSF components.
Update 2: one more cause is that you're binding multiple and physically different <h:form> components to one and same bean property. They should each be bound to their own unique property (or in this particular case, not be bound at all, this can be done better, see below).
Unrelated to the problem, as to your validateSession method, the entire method can be simplified to the following single EL expression in the view:
rendered="#{not empty user.name}"
assuming that SessionAttributes.USER_LOGIN_NAME equals to user.
Related
I try to validate a p:selectOneMenu using the validator attribute, but in the validate method the value of object is null. I don´t understand why it is null, somebody could help me. I´m using PrimeFaces 6.2.
My xhtml is:
<p:selectOneMenu id="somFieldType"
widgetVar="somFieldType"
converter="entityConverter"
required="false"
value="#{paramDetail.article_field_type}"
validator="#{detailArticleBean2.isTypeValid}"
... >
<f:selectItem itemLabel="#{i18n['avocado.general.seleccionar']}" itemValue="0"/>
<f:selectItem itemLabel="#{i18n['avocado.general.texto']}" itemValue="1"/>
...
</p:selectOneMenu>
In my bean I´m only printing the value:
public void isTypeValid(FacesContext ctx, UIComponent component, Object value) throws ValidatorException {
System.out.println(value.toString());
}
The console returns an error:
javax.el.ELException: /Ref/Art/artDetail.xhtml #165,67 validator="#{detailArticleBean2.isTypeValid}": java.lang.NullPointerException
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
I´d appreciate your help.
Your value is null, so you cannot apply .toString(). Use something like:
public void isTypeValid(FacesContext ctx, UIComponent component, Object value) throws ValidatorException {
if (value == null) {
// Value is unset; don't validate
return;
}
// Value is set; do validation
...
}
See also:
What is a NullPointerException, and how do I fix it?
I search for long time to this issue.But still i didn't get the solution.Kindly help me to this problem.
I have one JSP file and using struts for my application.When i try to load the page in browser it throws this error.
javax.servlet.jsp.JspException: No getter method for property reqKickOffMeet of bean org.apache.struts.taglib.html.BEAN.
Everything is fine.There is no case sensitive issue also .But this code is not working.Kindly help me to fix this.
JSP:
<TD class="fontclr1" colspan="2">Requirements Kick-off meeting:</TD>
<TD align="center"><html:select name="CdrQueryForm"
property="test0"
onchange="javascript:select('reqKickOffMeet','Requirements Kick-off meeting',this,1);">
<html:option value="EqualTo">Equal to</html:option>
<html:option value="GreaterThan">Greater than</html:option>
<html:option value="LessThan">Less than</html:option>
<html:option value="Between">Between</html:option>
</html:select></TD>
and my class file
private String reqKickOffMeet;
public String getReqKickOffMeet() {
return reqKickOffMeet;
}
public void setReqKickOffMeet(String reqKickOffMeet) {
this.reqKickOffMeet = reqKickOffMeet;
}
From the error it seems you are trying to load some property reqKickOffMeet from bean in the jsp. Check if the getter and setter methods are there in the class which holds this property.
Also you would like to check the signature of the getter and setters are correct.
Like
for property reqKickOffMeet
public String getReqKickOffMeet(){
return reqKickOffMeet;
}
public void setReqKickOffMeet(String reqKickOffMeet){
this.reqKickOffMeet = reqKickOfMeet;
}
Also if it still doesnt work, try renaming your variable to reqKickoffmeet (starting from smaller case and just one upper case letter in between)
I believe property element of html:select must match reqKickOffMeet. I had the same issue, my scenario was:
<html:select property="dontVerifyDependents" styleClass="body">
<html:options collection="dontVerifyDependentsOptions"
labelProperty="listValue" property="listId" />
</html:select>
Instead of dontVerifyDependents I had dontVerifyDependency and was getting the same error.
My class file:
private String dontVerifyDependents;
public void setDontVerifyDependents(String dontVerifyDependents) {
this.dontVerifyDependents = dontVerifyDependents;
}
public String getDontVerifyDependents() {
return dontVerifyDependents;
}
You should replace property="test0" for property="reqKickOffMeet".
Hope it works!
Im trying to set a list as an hidden variable in JSP and trying to access the same in controller.
This is my JSP,
<form:form id="TacReviewForm" commandName="taxReviewRequest" modelAttribute="taxReviewRequest" >
<form:hidden path="taxErrorDto" />
....................
---->
Where taxReviewRequest is the model and taxErrorDto is a list inside taxReviewRequest.
Now, I am trying to access the same in the controller class like below,
List<TaxErrorDto> taxErrorDto = (List<TaxErrorDto>)request.getAttribute("taxErrorDto");
System.out.println("!!!!!!!!!!!!!!!!!!!"+taxErrorDto);
Now when i try to print the same in the class it returns null.
Can someone help me with this please?
Tried --------------
URL in JS is: "${pageContext.request.contextPath}/otp/updateReviewDetail.html?taxReviewRequest=${taxReviewRequest}"
#RequestMapping(value = "/updateReviewDetail.html")
public ModelAndView launchReviewDetail(HttpServletRequest request, #RequestParam("taxReviewRequest") TaxReviewReqDto taxReviewRequest) {
List<TaxErrorDto> taxErrorDto = TaxReviewRequest.getTaxErrorDto();
...
}
Getting this error
[7/7/14 11:15:24:435 EDT] 00000084 webapp E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[meirpt]: com.ibm.ws.webcontainer.webapp.WebAppErrorReport: SRVE0295E: Error reported: 500
at com.ibm.ws.webcontainer.webapp.WebAppDispatcherContext.sendError(WebAppDispatcherContext.java:637)
at com.ibm.ws.webcontainer.srt.SRTServletResponse.sendError(SRTServletResponse.java:1187)
at com.ibm.ws.webcontainer.srt.SRTServletResponse.sendError(SRTServletResponse.java:1169)
at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:141)
at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:141)
at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:141)
In Spring we do that like this...I think it will help you.Thanks
public ModelAndView registerProcess(#ModelAttribute("taxReviewRequest") TaxReviewRequest taxReviewRequest)
{
List<TaxErrorDto> taxErrorDto = taxReviewRequest.getTaxErrorDto();
}
What I want to do is read a http-parameter on my login page, e.g. login.html?param=value, and then pass value to my AuthenticationProvider. My idea was to somehow save value in a hidden parameter, but I still don't know how to pass it on.
Is this possible? How do I go about to do it?
Edit: Following Sanath's advice and after doing some reading I was finally able to solve the problem -- look below if you're interested in how I did it.
I did the following and finally it worked like a charm.
In my bean configuration file I had to enter:
<http auto-config="true>
...
<form-login ... authentication-details-source-ref="myWebAuthDetSource"/>
...
</http>
<beans:bean id="myWebAuthDetSource" class="com.my.pack.age.MyWebAuthDetSource"/>
...
then I've set up my WebAuthenticationDetailsSource implementation like this:
public class MyWebAuthDetSource implements AuthenticationDetailsSource<HttpServletRequest, MyWebAuthDets> {
public MyWebAuthDetSource buildDetails (HttpServletRequest context) {
return new MyWebAuthDets(context);
}
}
then I've got my AuthenticationDetails implementation like:
public class MyWebAuthDets extends WebAuthenticationDetails {
private final String parameter;
public MyWebAuthDets(HttpServletRequest request) {
super(request);
this.parameter = request.getParameter("paramId");
}
}
And then I overlook the most simple fact, that the authentication process processes only what it gets on submit from the login form, so I simply had to add the following in login.jsp:
...
<form id="j_spring_security_check" ... >
<input type="hidden" name="paramID" value="${param['paramID']}" />
...
</form>
...
And that was all. Now I can add an authenticationProvider and get my parameter with .getDetails() from the authenticationToken.
Thanks again #Sanath.
I am working on a project that is accessing PostgreSQL with a jdbc driver and process this data through a middleware and finally displays/updates via jsp pages. Using Eclipse I created a Dynamic Web Project. Then I have written code for all back-end and middleware operations. I can access database from static context (I mean main method of java sources). I can also use my java resources (e.g displaying) from jsp if I don't call any methods that are accessing database. But when I try to access database, it doesn't work and gives me a null pointer exception.
<jsp:useBean id="user" class="dbActionManagement.UserData" scope="session"/>
<jsp:setProperty name="user" property="*"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>next page</title>
</head>
<body>
You entered<BR>
Name: <%= user.getUsername() %><BR>
Email: <%= user.getEmail() %><BR>
Age: <%= user.getAge() %><BR>
</body>
</html>
This gives me:
SEVERE: Servlet.service() for servlet [jsp] in context with path
[/GNYSweb] threw exception [java.lang.NullPointerException] with root
cause java.lang.NullPointerException at
dbActionManagement.OfficerManager.getTotalPoint(OfficerManager.java:494)
at dbActionManagement.UserData.getUsername(UserData.java:28) at
org.apache.jsp.NextPage_jsp._jspService(NextPage_jsp.java:80) at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown
Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown
Source) at java.lang.Thread.run(Unknown Source)
Also java class that I am using for this is UserData and method getUserName()
public String getUsername() {
int a = new OfficerManager().getTotalPoint("a");
return new Integer(a).toString();
}
OfficerManager has a default constructor and getTotalPoint is
public int getTotalPoint(String officerId){
int point = 0;
ResultSet results = null;
try {
if(DBConnection.db.isClosed()){ // problem is caused by this line
DBConnection.connect();
}
Statement sql = DBConnection.db.createStatement();
String sqlText = "select point from officers ";
sqlText += " where sicilno = '" + officerId + "'";
results = sql.executeQuery(sqlText);
} catch (SQLException e) {
e.printStackTrace();
}
if(results != null)
try {
while(results.next()){
point = (int) results.getDouble("point");
}
} catch (SQLException e) {
e.printStackTrace();
}
return point;
}
I have added postgreSQL jdbc driver to my build path. Also I included same jdbc driver in the lib folder of Tomcat. Also I am using an instance of Tomcat v7.0 at localhost and the location of this is [workspace metadata]
I understand the problem, it is basically I was trying to reach Connection object that is null. I use static objects for accessing database, I forgot to initialize them before using. There are several solutions for this, the most basic one is to write another method in UserData class called startConnection()
public void startConnection(){
new DBConnection("myDBName", "myUserName", "myPassword");
}
and call this method from jsp pages
...
<body>
<% user.startConnection(); %>
Name: <%= user.getUsername() %><BR>
</body>
...
That way I can initialize my DBConnection class instances properly before using them. Thanks for your help.
Avoid checking if the db is closed before connection is created, comment out:
//if(DBConnection.db.isClosed()){ // problem is caused by this line
DBConnection.connect();
// }
And then close the connection after using it and when an exception occurs. Your exception block should be changed to;
catch (SQLException e)
{
e.printStackTrace();
if((DBConnection !=null) && DBConnection.db !=null && !DBConnection.db.isClosed())
{
BConnection.db.close();
}
}
And also close it in the try block straight after usage.
As rule of thumb - alway check if the connection is not null before attempt closing it.
try doing something like this:
if((DBConnection !=null) && DBConnection.db !=null && DBConnection.db.isClosed())
{
DBConnection.connect();
}