Results 1 to 15 of 15
  1. #1
    dennisbf is offline Member
    Join Date
    Sep 2011
    Posts
    17
    Rep Power
    0

    Default Problem using a list with piechart

    Hi guys, i'm having some trouble to create a piechart from a list

    primefaces version 3.0.M3
    tomcat version 7.0

    this is the error i'm getting

    Java Code:
    Sep 20, 2011 6:33:59 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
    SEVERE: Error Rendering View[/restrito/acao.xhtml]
    java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.primefaces.model.chart.PieChartModel
    this is where i call the list

    Java Code:
    <ui:composition>
    	<h:panelGrid width="100%">
    		<h:form id="graficosCarteira">
    			<h:panelGrid columns="2" width="100%">
    				<p:panel header="Composição carteira em % de quantidade"
    					toggleable="true" toggleSpeed="500">
    					<p:pieChart value="#{acaoBean.lista}" var="acaoVirtual"
    						categoryField="#{acaoVirtual.acao.sigla}"
    						dataField="#{acaoVirtual.acao.quantidade}" width="265px"
    						height="125px" style="estiloGrafico" />
    				</p:panel>
    				<p:panel header="Composição carteira em % de valor"
    					toggleable="true" toggleSpeed="500" style="margin-left:+10px;">
    					<p:pieChart value="#{acaoBean.lista}" var="acaoVirtual"
    						categoryField="#{acaoVirtual.acao.sigla}"
    						dataField="#{acaoVirtual.total}" width="265px" height="125px"
    						style="estiloGrafico" />
    				</p:panel>
    			</h:panelGrid>
    		</h:form>
    	</h:panelGrid>
    </ui:composition>
    and this is the list

    Java Code:
    public List<AcaoVirtual> getLista() {  
            FacesContext context = FacesContext.getCurrentInstance();  
            ContextoBean contextoBean = ContextoUtil.getContextoBean();  
            AcaoRN acaoRN = new AcaoRN();  
            try {  
                if (this.lista == null) {  
                    this.lista = acaoRN.listarAcaoVirtual(contextoBean.getUsuarioLogado());  
                }  
            } catch (RNException e) {  
                context.addMessage(null, new FacesMessage(e.getMessage()));  
            }  
            return this.lista;  
        }
    Can anyone tell me what i'm doing wrong?

    the AcaoVirtual is here:

    Java Code:
    public class AcaoVirtual {
    
    	private Acao	acao	= new Acao();
    	private float	ultimoPreco;
    	private float	total;
    
    	public Acao getAcao() {
    		return acao;
    	}
    
    	public void setAcao(Acao acao) {
    		this.acao = acao;
    	}
    
    	public float getUltimoPreco() {
    		return ultimoPreco;
    	}
    
    	public void setUltimoPreco(float ultimoPreco) {
    		this.ultimoPreco = ultimoPreco;
    	}
    
    	public float getTotal() {
    		return total;
    	}
    
    	public void setTotal(float total) {
    		this.total = total;
    	}
    }
    Thank you very much.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: Problem using a list with piechart

    java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.primefaces.model.chart.PieChartModel
    Where do you cast anything to a PieChartModel?

  3. #3
    dennisbf is offline Member
    Join Date
    Sep 2011
    Posts
    17
    Rep Power
    0

    Default Re: Problem using a list with piechart

    Quote Originally Posted by Norm View Post
    Where do you cast anything to a PieChartModel?
    H, Norm, thanks for you reply


    i think he's considering this
    Java Code:
     <p:pieChart value="#{acaoBean.lista}"
    as a cast, because, "lista" comes from a List, i don't really cast it.
    That's why i just don't understand this error.

    Thank you very much.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: Problem using a list with piechart

    Sorry, I'm restricted to java code only. That doesn't look like java.

  5. #5
    dennisbf is offline Member
    Join Date
    Sep 2011
    Posts
    17
    Rep Power
    0

    Default Re: Problem using a list with piechart

    Hi, Norm, thanks again for the reply

    the method who is been called from de JSF (Java Sever Faces) and using the Primefaces Framework, is in the 1st post i made as you can see
    Java Code:
    public List<AcaoVirtual> getLista() {  
            FacesContext context = FacesContext.getCurrentInstance();  
            ContextoBean contextoBean = ContextoUtil.getContextoBean();  
            AcaoRN acaoRN = new AcaoRN();  
            try {  
                if (this.lista == null) {  
                    this.lista = acaoRN.listarAcaoVirtual(contextoBean.getUsuarioLogado());  
                }  
            } catch (RNException e) {  
                context.addMessage(null, new FacesMessage(e.getMessage()));  
            }  
            return this.lista;  
        }
    and as you can see, there no casts

    Thank you.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: Problem using a list with piechart

    I still don't see the java code where a variable is cast to a PieChartModel.
    Is there generated source code where that happens?

  7. #7
    dennisbf is offline Member
    Join Date
    Sep 2011
    Posts
    17
    Rep Power
    0

    Default Re: Problem using a list with piechart

    hi, Norm, thanks again.
    I'm not sure if i get it.
    In any moment a made a cast to piechart, the only place i'm using it, is in the JSF, with the tag i posted

    my variables from my class AcaoBean are these ones:

    Java Code:
    	private AcaoVirtual			selecionada		= new AcaoVirtual();
    	private List<AcaoVirtual>	lista				= null;
    	private String					linkCodigoAcao	= null;
    thank you very much

    and this is my jsf where a create de pieChart
    Java Code:
    <ui:composition>
    	<h:panelGrid width="100%">
    		<h:form id="graficosCarteira">
    			<h:panelGrid columns="2" width="100%">
    				<p:panel header="Composição carteira em % de quantidade"
    					toggleable="true" toggleSpeed="500">
    					<p:pieChart value="#{acaoBean.lista}" var="acaoVirtual"
    						categoryField="#{acaoVirtual.acao.sigla}"
    						dataField="#{acaoVirtual.acao.quantidade}" width="265px"
    						height="125px" style="estiloGrafico" />
    				</p:panel>
    				<p:panel header="Composição carteira em % de valor"
    					toggleable="true" toggleSpeed="500" style="margin-left:+10px;">
    					<p:pieChart value="#{acaoBean.lista}" var="acaoVirtual"
    						categoryField="#{acaoVirtual.acao.sigla}"
    						dataField="#{acaoVirtual.total}" width="265px" height="125px"
    						style="estiloGrafico" />
    				</p:panel>
    			</h:panelGrid>
    		</h:form>
    	</h:panelGrid>
    </ui:composition>
    Last edited by dennisbf; 09-22-2011 at 01:44 AM.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: Problem using a list with piechart

    Does the jsf "code" generate java code that is compiled?
    Otherwise where is the "cast" being done?

  9. #9
    dennisbf is offline Member
    Join Date
    Sep 2011
    Posts
    17
    Rep Power
    0

    Default Re: Problem using a list with piechart

    hi, norm
    There is no cast, the JSF is just the view

    if i leave the piegraph part on JSF commented, the page opens, if i don't i get this error
    Last edited by dennisbf; 09-22-2011 at 02:11 AM.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: Problem using a list with piechart

    What happens to this code:
    Java Code:
    <ui:composition>
    	<h:panelGrid width="100%">
    		<h:form id="graficosCarteira">
    			<h:panelGrid columns="2" width="100%">
    				<p:panel header="Composição carteira em % de quantidade"
    					toggleable="true" toggleSpeed="500">
    					<p:pieChart value="#{acaoBean.lista}" var="acaoVirtual"
    						categoryField="#{acaoVirtual.acao.sigla}"
    						dataField="#{acaoVirtual.acao.quantidade}" width="265px"
    						height="125px" style="estiloGrafico" />
    				</p:panel>
    				<p:panel header="Composição carteira em % de valor"
    					toggleable="true" toggleSpeed="500" style="margin-left:+10px;">
    					<p:pieChart value="#{acaoBean.lista}" var="acaoVirtual"
    						categoryField="#{acaoVirtual.acao.sigla}"
    						dataField="#{acaoVirtual.total}" width="265px" height="125px"
    						style="estiloGrafico" />
    				</p:panel>
    			</h:panelGrid>
    		</h:form>
    	</h:panelGrid>
    It's not java. Is it converted to java source and compiled?
    What program does anything with the above code? What does it do with it?

  11. #11
    dennisbf is offline Member
    Join Date
    Sep 2011
    Posts
    17
    Rep Power
    0

    Default Re: Problem using a list with piechart

    Hi, Norm
    This is a part of a Stock page, whre you can see your Stock (from the graph that is not loading), you can add new Stocks, and you have a graph from YahooUtil.
    this jsf is called here, wich is the main page for stocks
    Java 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:h="http://java.sun.com/jsf/html"
    	xmlns:ui="http://java.sun.com/jsf/facelets">
    <ui:composition template="/templates/interna.xhtml">
    	<ui:define name="titulo">
        Cadastro de Ações
    	</ui:define>
    
    	<ui:define name="corpo">
    		<h:outputScript target="head">
    		var estiloGrafico = {
    			padding :20,
    			legend : {
    				display :"right",
    				spacing :10
    			}
    		};
    		</h:outputScript>
    
    		<ui:include src="acao_graficoscarteira.xhtml" />
    		<br />
    		<ui:include src="acao_edicao.xhtml" />
    		<br />
    		<ui:include src="acao_listagem.xhtml" />
    		<br />
    		<ui:include src="acao_graficos.xhtml" />
    	</ui:define>
    </ui:composition>
    </html>
    it is converted

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: Problem using a list with piechart

    None of that can execute. There is a program that reads it and does ????

  13. #13
    dennisbf is offline Member
    Join Date
    Sep 2011
    Posts
    17
    Rep Power
    0

    Default Re: Problem using a list with piechart

    It is a website actually
    And the graph suposed to open when you call the page
    "localhost:8080/FinanceiroWeb/restrito/acao.jsf"

    but, as the page load the graph, i'm getting this error.

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: Problem using a list with piechart

    It doesn't matter where the file is, there is a program that reads it and does something with it.

  15. #15
    dennisbf is offline Member
    Join Date
    Sep 2011
    Posts
    17
    Rep Power
    0

    Default Re: Problem using a list with piechart

    like the tomcat?
    hibernate?

Similar Threads

  1. List problem
    By Bulelakes in forum JDBC
    Replies: 7
    Last Post: 07-30-2010, 08:51 AM
  2. piechart not being drawn on a panel
    By dataprofiling in forum Java 2D
    Replies: 1
    Last Post: 03-27-2010, 12:33 PM
  3. assignment problem with List<T>
    By Newbie666 in forum New To Java
    Replies: 11
    Last Post: 01-21-2010, 01:12 PM
  4. Array List Problem
    By khamuruddeen in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 09:10 AM
  5. list problem
    By fareez in forum New To Java
    Replies: 3
    Last Post: 06-28-2007, 11:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •