为什么我不能使用返回值“success”导航到我的managedBean到另一个页面?

时间:2012-08-15 12:39:44

标签: jsf tomcat

我正在使用Eclipse使用JSF,Hibernate和Tomcat服务器。我在一个名为“ListeAutoTPEs.jsp”的jsp页面中,当提交表单时,会调用一个方法(它从jrxml文件创建一个PDF)但是无法访问我提到的页面“test2.htm”在“成功”导航案例中的tha faces-config

我的faces-config.xml页面:

<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces 
 Config   1.0//EN"
                              "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
<faces-config>
 <managed-bean>
  <managed-bean-name>login</managed-bean-name>
  <managed-bean-class>com.axentis.jsf.LoginBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
 </managed-bean>
 <managed-bean>
  <managed-bean-name>traitement</managed-bean-name>
  <managed-bean-class>com.axentis.jsf.TraitementBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
  <managed-property>
   <property-name>executed</property-name>
   <property-class>java.lang.Boolean</property-class>
   <value>false</value>
  </managed-property>
 </managed-bean>
 <managed-bean>
  <managed-bean-name>autorisation</managed-bean-name>
  <managed-bean-class>com.axentis.jsf.AutoBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
  <managed-property>
   <property-name>ack</property-name>
   <property-class>java.lang.String</property-class>
   <value>ns</value>
  </managed-property>
 </managed-bean>
 <managed-bean>
  <managed-bean-name>match</managed-bean-name>
  <managed-bean-class>com.axentis.jsf.MatchBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
  <managed-property>
   <property-name>transac</property-name>
   <property-class>java.lang.String</property-class>
   <value>1</value>
  </managed-property>
 </managed-bean>
 <managed-bean>
  <managed-bean-name>trans</managed-bean-name>
  <managed-bean-class>com.axentis.jsf.TransacTelecolBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
 </managed-bean>
 <navigation-rule>
  <from-view-id>/login.jsp</from-view-id>
  <navigation-case>
   <from-outcome>ConSuccess</from-outcome>
   <to-view-id>/Accueil.jsp</to-view-id>
  </navigation-case>
  <navigation-case>
   <from-outcome>Erreur</from-outcome>
   <to-view-id>/login.jsp</to-view-id>
  </navigation-case>
 </navigation-rule>
 <navigation-rule>
  <from-view-id>/listeDeTousLesCom.jsp</from-view-id>
  <navigation-case>
   <from-outcome>success</from-outcome>
   <to-view-id>/listeDeTousLesCom.jsp</to-view-id>
  </navigation-case>
  <navigation-case>
   <from-outcome>erreur</from-outcome>
   <to-view-id>/error.jsp</to-view-id>
  </navigation-case>
 </navigation-rule>
 <navigation-rule>
  <from-view-id>/jsp/ListeAutoTPEs.jsp</from-view-id>
  <navigation-case>
   <from-outcome>success</from-outcome>
   <to-view-id>/test2.htm</to-view-id>
   <redirect/>
  </navigation-case>

  <navigation-case>
   <from-outcome>erreur</from-outcome>
   <to-view-id>/error.jsp</to-view-id>
  </navigation-case>
 </navigation-rule>
 <navigation-rule>
  <from-view-id>/Matching.jsp</from-view-id>
  <navigation-case>
   <from-outcome>success</from-outcome>
   <to-view-id>/Matching.jsp</to-view-id>
  </navigation-case>
  <navigation-case>
   <from-outcome>erreur</from-outcome>
   <to-view-id>/error.jsp</to-view-id>
  </navigation-case>
 </navigation-rule>
 <navigation-rule>
  <from-view-id>/listeTransacTelecol.jsp</from-view-id>
  <navigation-case>
   <from-outcome>success</from-outcome>
   <to-view-id>/listeTransacTelecol.jsp</to-view-id>
  </navigation-case>
  <navigation-case>
   <from-outcome>erreur</from-outcome>
   <to-view-id>/error.jsp</to-view-id>
  </navigation-case>
 </navigation-rule>
</faces-config>

我的managedBean:

public String toutLesAuto(){
String url = "jdbc:oracle:thin:@10.5.3.136:1521:orcl";
String login = "mawarid";
String password = "mawarid";
Connection connection = null;  
 try {
 // - Connexion à la base
 System.out.println("je suis dans le bean de traitement");
Driver monDriver = new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(monDriver);
connection = DriverManager.getConnection(url, login, password);
System.out.println("connection réussie");

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
ServletContext servletContext = (ServletContext) externalContext.getContext();
String absoluteDiskPath = servletContext.getRealPath("/");

// récupération des données saisies par le client

AutoBean auto = (AutoBean) FacesContext.getCurrentInstance().getExternalContext().
getSessionMap().get("autorisation");
if (auto!=null)
System.out.println("les donnée saisi par le clients sont : n° de la carte
"+auto.getNumCarte()+"  son code réponse  "+auto.getCodeRep()+" et la date saisie est
 : "+auto.getDate()+" le uméro d'autorisation est : "+auto.getNumAuto());
else 
System.out.println("le bean AutoBean n'a pas été instancié"); 

// - Chargement et compilation du rapport

JasperDesign jasperDesign = JRXmlLoader.load(absoluteDiskPath+"\\rapports  
\\ListeAuto.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

// - Paramètres à envoyer au rapport

String date="%";
String numCarte="%";
String numTpe="%";
String codeRep="%";
String numCommerçant="%";
String numAuto="%";
String mntDem="%";
String ack="%";
if(auto.getDate()!="")
date =auto.getDate();
if (auto.getNumCarte()!="")
numCarte=auto.getNumCarte();
if (auto.getCodeRep()!="")
codeRep=auto.getCodeRep();
if (auto.getNumAuto()!="");
numAuto=auto.getNumAuto();
if (auto.getNumCom()!="")
numCommerçant=auto.getNumCom();
if (auto.getNumTpe()!="")
numTpe=auto.getNumTpe();
if (auto.getAck()!=null)
ack=auto.getAck();

Map parameters = new HashMap();
parameters.put("date",date);
parameters.put("numCarte",numCarte);
parameters.put("numTpe",numTpe);
parameters.put("codeRep",codeRep);
parameters.put("numCommercant",numCommerçant);
parameters.put("numAuto",numAuto);
parameters.put("mntDem",mntDem);


// - Execution du rapport

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, 
 parameters,connection);
System.out.println("execution du rapport réussie");
// - Création du rapport au format PDF



JasperExportManager.exportReportToPdfFile(jasperPrint,absoluteDiskPath+"\\rapports
\\ListeAuto.pdf");
System.out.println("impression réussie");


if (auto!=null)
System.out.println("les donnée saisi par le clients sont : n° de la carte
 '"+numCarte+"'  " +"son code réponse  '"+codeRep+"' et la date saisie est  
  :'"+date+"' le uméro d'autorisation est : '"+numAuto+"l'accusé est : "+ack);



// popup to download the file


 response.reset(); 
 response.setContentType("application/xml"); 
 response.setHeader("Content-disposition", "attachment; filename=\"liste des    
 autorisations.pdf\"");

 byte[] buf = new byte[1024];
 try{

 System.out.println("le chemain "+absoluteDiskPath);
 String realPath =absoluteDiskPath+"\\rapports\\ListeAuto.pdf";
 File file = new File(realPath);
 long length = file.length();
  BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
 ServletOutputStream out = response.getOutputStream();
  response.setContentLength((int)length);
 while ((in != null) && ((length = in.read(buf)) != -1)) {
 out.write(buf, 0, (int)length);
    }
     in.close();
    out.close();
    }catch (Exception exc){
    exc.printStackTrace();
    } 

    // fin de la boite de dialogue
     this.setExecuted(true);
     System.out.println("je vais faire le return");
     return "success";
       // facesContext.responseComplete();





        } catch (JRException e) {
        e.printStackTrace();
        return "erreur";
        } catch (SQLException e) {
        e.printStackTrace();
        return "erreur";
        } 
        finally {
            try {

                connection.close();
            } catch (SQLException e) {

                e.printStackTrace();
            }
        }

  }

我的JSP页面“ListeAutoTPEs.jsp”

 <h:commandButton value="télécharger" action="#{traitement.toutLesAuto}" >

2 个答案:

答案 0 :(得分:0)

我想您无法转发到纯HTML文件。也许您可以将test2.htm更改为JSP页面并尝试改为:

<navigation-case>
    <from-outcome>success</from-outcome>
    <to-view-id>/test2.jsp</to-view-id>
    <redirect/>
</navigation-case>

所有其他导航规则是否按预期工作?

答案 1 :(得分:0)

导航规则从id中提及/listeTransacTelecol.jsp。哪个与ListeAutoTPEs.jsp不匹配。

我不确定是否允许转发到HTML,我自己也没试过。