• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Casting Exception

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When trying to create some JSF components dynamically I get this:

org.apache.jasper.JasperException: java.lang.ClassCastException: javax.faces.component.UINamingContainer cannot be cast to javax.faces.component.UIViewRoot

I have this:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>;
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>;

<!-- < %@ page import="web.IdeaBean" %>-->

<f:subview id="ideas">

<h:panelGrid id="ideaPanel" binding="#{ideaBean.ideaGrid}" columns="1">

<f:phaseListener binding="#{ideaBean}" type="web.IdeaBean"/>

</h:panelGrid>

</f:subview>


sandwiched into a parent JSP page which looks like this:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>

<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>;
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>;

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">;
<html>

<head>

<link rel="stylesheet" type="text/css" href="main.css"/>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Home</title>

</head>

<body>

<f:view>

<jsp:include page="header.jsp" />

<jsp:include page="ideas.jsp"/>

<jsp:include page="footer.jsp"/>

</f:view>

</body>

</html>



which references a backing bean that looks like this:


public class IdeaBean implements PhaseListener
{
private static final long serialVersionUID = 8855403672289106945L;

private String string = "This is just some useless string";

private HtmlPanelGrid ideaGrid;

public void handleNewIdea(Idea idea)
{
/* List<UIComponent> children = ideaGrid.getChildren();

HtmlOutputText child = new HtmlOutputText();

child.setValue("Hey world look at me!");

children.add(child);*/
}

public IdeaBean()
{

}

public String getString()
{
return this.string;
}

public void setString(String string)
{
this.string = string;
}

public HtmlPanelGrid getIdeaGrid()
{
return this.ideaGrid;
}

public void setIdeaGrid(HtmlPanelGrid ideaGrid)
{
this.ideaGrid = ideaGrid;
}

@Override
public void beforePhase(PhaseEvent pe)
{
/*List<UIComponent> ideaGridKids = ideaGrid.getChildren();

try
{
java.sql.ResultSet result = IDDBConnection.getResultSet("SELECT * FROM ideas");

while(result.next())
{
HtmlPanelGrid ideaPanel = new HtmlPanelGrid();
ideaPanel.setColumns(1);

if(Math.random()>=.5)
ideaPanel.setBgcolor("white");
else
ideaPanel.setBgcolor("Gray");

List<UIComponent> ideaPanelKids = ideaPanel.getChildren();

HtmlOutputText ideaText = new HtmlOutputText();
ideaText.setValue("Idea Text: "+result.getObject("idea_txt"));

HtmlOutputText ideaSummary = new HtmlOutputText();
ideaSummary.setValue("Idea Summary: "+result.getObject("idea_summary_txt"));

//HtmlGraphicImage image1 = new HtmlGraphicImage();
//HtmlGraphicImage image2 = new HtmlGraphicImage();
//HtmlGraphicImage image3 = new HtmlGraphicImage();

//add subcomponents to ideaPanel
ideaPanelKids.add(ideaText);
ideaPanelKids.add(ideaSummary);

//add ideaPanel to main page panel
ideaGridKids.add(ideaPanel);
}
}
catch(Exception e)
{
e.printStackTrace();
}*/
}

@Override
public void afterPhase(PhaseEvent pe)
{
List<UIComponent> children = ideaGrid.getChildren();

HtmlOutputText child = new HtmlOutputText();

child.setValue("AFTER PHASE!");

children.clear();

children.add(child);
}

@Override
public PhaseId getPhaseId()
{
return PhaseId.ANY_PHASE;
}
}
 
Dennis Hopfer
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I call the subview directly it works fine but if I call it as an include on a parent page I get the above exception. Not sure if you can't do dynamic stuff from within a subview or..?
 
Dennis Hopfer
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone want to weigh in on this? Tim do you have any ideas or wisdom?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried putting the <f:subview> tag arround the jsp:include, and removing the <f:subview> tags within the jsp being included. ie.:

 
Dennis Hopfer
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did as you suggested but still the same exception as before.


I started Eclipse using java (instead of javaw) and there's this in the cmd window:

No concrete part?
No concrete part?
No concrete part?


Alternatively I also removed everything from index.jsp's view except:



and, yes, it still crashes. This leads me to believe that somehow the hierarchy is being violated in my bean code's beforePhase method.


Full stack trace from logs:

[#|2010-12-07T21:11:50.715-0500|WARNING|oracle-glassfish3.0.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=25;_ThreadName=http-thread-pool-8080-(2);|StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.ClassCastException: javax.faces.component.UINamingContainer cannot be cast to javax.faces.component.UIViewRoot
at com.sun.faces.taglib.jsf_core.PhaseListenerTag.doStartTag(PhaseListenerTag.java:149)
at org.apache.jsp.ideas_jsp._jspx_meth_f_phaseListener_0(ideas_jsp.java from :177)
at org.apache.jsp.ideas_jsp._jspx_meth_h_panelGrid_0(ideas_jsp.java from :147)
at org.apache.jsp.ideas_jsp._jspx_meth_f_subview_0(ideas_jsp.java from :104)
at org.apache.jsp.ideas_jsp._jspService(ideas_jsp.java from :67)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:406)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:483)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:373)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:822)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:639)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:569)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:1010)
at org.apache.jsp.index_jsp._jspx_meth_f_subview_1(index_jsp.java from :285)
at org.apache.jsp.index_jsp._jspx_meth_f_view_0(index_jsp.java from :137)
at org.apache.jsp.index_jsp._jspService(index_jsp.java from :84)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:406)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:483)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:373)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:822)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:517)
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:488)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:336)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:314)
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:542)
at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:355)
at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:130)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)
 
Dennis Hopfer
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thought I had it figured but now it's just giving me another error. Does anyone have any dynamic JSF stuff that is spawned in a subview using a phaseListener?
 
Dennis Hopfer
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok LOL. I did have it figured out after all!

This DOES work:



This DOES NOT work:



So, it looks like you need the phaseListener anchored at the view level, not the subview level.
 
Look! I laid an egg! Why does it smell like that? Tiny ad, does this smell weird to you?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic