IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JSF Java Discussion :

l'exception : java.lang.IllegalStateException:


Sujet :

JSF Java

  1. #1
    Membre du Club
    Profil pro
    Étudiant
    Inscrit en
    Avril 2009
    Messages
    83
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2009
    Messages : 83
    Points : 58
    Points
    58
    Par défaut l'exception : java.lang.IllegalStateException:
    Bonjour tous le monde
    dans une page "report.jsf" j'ai un commandLink :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <html:commandLink action="report" actionListener="#{Report.loadPDF}" title="telecharger le fichier en format PDF" style="text-decoration :none ;">
    loadPDF est une méthode permettant de télécharger un fichier situé sur le serveur ,et il retourn une chaine "report" qui utiliser dans les règles du navigation ;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    <navigation-rule>
            <from-view-id>/report.jsf</from-view-id>
            <navigation-case>
                <from-outcome>report</from-outcome>
                <to-view-id>/report.jsf</to-view-id>
            </navigation-case>
        </navigation-rule>
    bon , lorsque j'exécute mon application au sein du Jboss4.2.3GA j'obtient ma page "report.jsf" et lorsque je click sue le commandlink j'arrive a télécharger mon fichier mais dans les logs du Jboss ya une exception :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
     
    17:10:52,890 ERROR [lifecycle] JSF1054: (Phase ID: RENDER_RESPONSE 6, View ID: /report.jsp) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@17779f2]
    17:10:52,890 ERROR [[FacesServlet]] "Servlet.service()" pour la servlet FacesServlet a généré une exception
    java.lang.IllegalStateException: Impossible d'utiliser faire-suivre (forward) après que la réponse ait été envoyée
            at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:302)
            at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
            at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:410)
            at com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:473)
            at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:141)
            at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)
            at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
            at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
            at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
            at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
            at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
            at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
            at java.lang.Thread.run(Thread.java:619)
    pouvez vous m'indiquer la source de cette exception ??
    merci d'avance

  2. #2
    Rédacteur

    Profil pro
    Inscrit en
    Juin 2003
    Messages
    4 184
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 4 184
    Points : 5 059
    Points
    5 059
    Par défaut
    ajoute une redirection dans la navigation rule


  3. #3
    Membre du Club
    Profil pro
    Étudiant
    Inscrit en
    Avril 2009
    Messages
    83
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2009
    Messages : 83
    Points : 58
    Points
    58
    Par défaut
    bonjour ,
    merci sniper pour ta réponse,
    j'ai ajouter <redirect/> dans le faces-config :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
        <navigation-rule>
            <from-view-id>/report.jsf</from-view-id>
            <navigation-case>
                <from-outcome>report</from-outcome>
                <to-view-id>/report.jsf</to-view-id>
                <redirect/>
            </navigation-case>
        </navigation-rule>
    mais j'obtiens toujours l'exception précédente

  4. #4
    Rédacteur

    Profil pro
    Inscrit en
    Juin 2003
    Messages
    4 184
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 4 184
    Points : 5 059
    Points
    5 059
    Par défaut
    tu peux montrer le code de la méthode loadPDF.

  5. #5
    Membre du Club
    Profil pro
    Étudiant
    Inscrit en
    Avril 2009
    Messages
    83
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2009
    Messages : 83
    Points : 58
    Points
    58
    Par défaut
    le code de la méthode loadPDF est le suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
     public String  loadPDF(ActionEvent event) throws IOException{
            String context = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("Report");
            String nomfichier =(String) reportmodel.getRowData();
            String reportPath =context+"\\"+nomfichier+".pdf";
            File file = new File(reportPath);
            FileInputStream in = new FileInputStream(file);
            BufferedInputStream fileInBuf = new BufferedInputStream(in);
            FileInputStream fis = new FileInputStream(file);
            final int BUF_SIZE = 4096;
            byte buf[] = new byte[BUF_SIZE];
            int length = 0;
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
     
            while ((length = fileInBuf.read(buf)) > 0) {
                    baos.write(buf, 0, length);
            }
            byte[] fileData = new byte[(int) file.length()];
            fileData = baos.toByteArray();
            HttpServletResponse response = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
            response.setHeader("Content-disposition", "attachment;filename="+nomfichier+".pdf");
            response.setContentLength(fileData.length);
            response.getOutputStream().write(fileData);
            response.setContentType("application/pdf");
            response.getOutputStream().flush();
            response.getOutputStream().close(); 
            return "report";
        }

  6. #6
    Rédacteur

    Profil pro
    Inscrit en
    Juin 2003
    Messages
    4 184
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 4 184
    Points : 5 059
    Points
    5 059
    Par défaut
    la méthode pour l'actionListener doit être de type void,
    et ajoute responseComplete

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
     
    public void loadPDF(ActionEvent event) throws IOException{
     
    context.responseComplete();
     
    }

  7. #7
    Membre du Club
    Profil pro
    Étudiant
    Inscrit en
    Avril 2009
    Messages
    83
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2009
    Messages : 83
    Points : 58
    Points
    58
    Par défaut
    merci Sniper37 pour tes conseils, j'ai modifié le type de retour de la méthode loadPDF et j'ai ajouté le "context.responsecomplete;" mais le problème rèside encore , la meme exception est déclenché?
    merci

  8. #8
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    tu ne devrais plus avoir cette erreur avec le responseComplete car il dit a jsf d'arreter le travail. Accessoirement met ton code dans un action plutot qu'un actionlistener. c'est plus adapté. Et la regle de navigation en sert à ren puisque tu a déjà envoyé le contenu.

  9. #9
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    42
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 42
    Points : 46
    Points
    46
    Par défaut
    Si tu veut rester dans la meme page, tu n'es pas obligé de faire une regle de navigation, donc essai d'enlever ça de votre faces-config.xml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    <navigation-rule>
            <from-view-id>/report.jsf</from-view-id>
            <navigation-case>
                <from-outcome>report</from-outcome>
                <to-view-id>/report.jsf</to-view-id>
            </navigation-case>
        </navigation-rule>
    puis enleve aussi le paramatre "ActionEvent event" dans ta fonction loadPDF, et met a la fin un ( return "" ; )



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
     public String  loadPDF() throws IOException{
            String context = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("Report");
            String nomfichier =(String) reportmodel.getRowData();
            String reportPath =context+"\\"+nomfichier+".pdf";
            File file = new File(reportPath);
            FileInputStream in = new FileInputStream(file);
            BufferedInputStream fileInBuf = new BufferedInputStream(in);
            FileInputStream fis = new FileInputStream(file);
            final int BUF_SIZE = 4096;
            byte buf[] = new byte[BUF_SIZE];
            int length = 0;
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
     
            while ((length = fileInBuf.read(buf)) > 0) {
                    baos.write(buf, 0, length);
            }
            byte[] fileData = new byte[(int) file.length()];
            fileData = baos.toByteArray();
            HttpServletResponse response = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
            response.setHeader("Content-disposition", "attachment;filename="+nomfichier+".pdf");
            response.setContentLength(fileData.length);
            response.getOutputStream().write(fileData);
            response.setContentType("application/pdf");
            response.getOutputStream().flush();
            response.getOutputStream().close(); 
            return "";
        }

  10. #10
    Membre du Club
    Profil pro
    Étudiant
    Inscrit en
    Avril 2009
    Messages
    83
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2009
    Messages : 83
    Points : 58
    Points
    58
    Par défaut
    Bonjour ,
    merci tchize et arthurs pour vos conseils, j'ai suivi vos renseignement et la tous ça marche ;
    donc si voici le code de la méthode loadPDF qui permet de télécharger un fichier PDF qui se situe dans le serveur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
     public String  loadPDF() throws IOException{
           String context = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("Report");//report c'est un paramètre que j'ai déclarer dans le web.xml ce paramètre contient le chemin du répértoire contenant mon fichier PDF
            String nomfichier =(String) reportmodel.getRowData();
            String reportPath =context+"\\"+nomfichier+".pdf";
            File file = new File(reportPath);
            FileInputStream in = new FileInputStream(file);
            BufferedInputStream fileInBuf = new BufferedInputStream(in);
            FileInputStream fis = new FileInputStream(file);
            final int BUF_SIZE = 4096;
            byte buf[] = new byte[BUF_SIZE];
            int length = 0;
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
     
            while ((length = fileInBuf.read(buf)) > 0) {
                    baos.write(buf, 0, length);
            }
            byte[] fileData = new byte[(int) file.length()];
            fileData = baos.toByteArray();
            HttpServletResponse response = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
            response.setHeader("Content-disposition", "attachment;filename="+nomfichier+".pdf");
            response.setContentLength(fileData.length);
            response.getOutputStream().write(fileData);
            response.setContentType("application/pdf");
            response.getOutputStream().flush();
            response.getOutputStream().close();
            FacesContext.getCurrentInstance().responseComplete();
            return "";
     
        }
    merci encore pour vos conseils

  11. #11
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    42
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 42
    Points : 46
    Points
    46
    Par défaut
    c'est super

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 7
    Dernier message: 17/11/2013, 15h27
  2. L'exception : java.lang.IllegalStateException
    Par nadhir84 dans le forum JSF
    Réponses: 1
    Dernier message: 19/07/2011, 09h00
  3. [System.load] Exception java.lang.UnsatisfiedLinkError avec unknown file type
    Par jemini_fr dans le forum API standards et tierces
    Réponses: 6
    Dernier message: 05/02/2007, 13h52
  4. probleme Tomcat java.lang.IllegalStateException
    Par lulululucie dans le forum Tomcat et TomEE
    Réponses: 3
    Dernier message: 29/12/2006, 11h53
  5. Resoudre exception java.lang,OutOfMemory
    Par Battosaiii dans le forum Langage
    Réponses: 9
    Dernier message: 02/08/2006, 17h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo