Quantcast
Channel: SCN : Popular Discussions - SAP Crystal Reports, version for Eclipse
Viewing all articles
Browse latest Browse all 893

Cannot pass parameter in JSF

$
0
0

I am writing a JSF page to get user input, and pass that input to Crystal Report (Crystal Report for Eclipse 2.0). I don't know why the parameterFields cannot load my parameter. Please help me!!!

My First page (rptDemo.xhtml):

<!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:f="http://java.sun.com/jsf/core">  <h:head>      <title>Crystal Report Demo</title>  </h:head>  <h:body>  <h1>Crystal Report for Eclipse 2.0 Demo</h1>  <h2>Using JSF 2.0 and JSF 1.2 to generate report</h2>  <h3>This input/select page use JSF 2.0, result page use JSF 1.2 </h3>      <f:view>          <h:form>              <table border="1">                  <tr>                      <td>No parameter passing to report</td>                      <td colspan="2"><h:commandButton value="Show report 1" action="#{reportBean.show1}"/> can show report normally</td>                  </tr>                  <tr>                      <td>Passing parameter to report<br/>(cannot pass parameter)</td>                      <td><h:inputText value="#{reportBean.inputText}"/></td>                      <td><h:commandButton value="Show report 2" action="#{reportBean.show2}"/></td>                  </tr>              </table>          </h:form>      </f:view>  </h:body>  </html>  

My second page (result page) for "Show Report 1 (rpt1.jsp)", this can run successfully:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>  <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>  <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>  <%@ taglib uri="http://www.businessobjects.com/jsf/crystalreportsviewers" prefix="bocrv" %>          <head><title>View Report 1</title>  </head>  <body>  <f:view>  <h:form>  <bocrv:reportPageViewer reportSource="#{reportBean.reportSource1}"  />   </h:form>  </f:view>  <body>  </html> 

 

My third page (result page) for "Show Report 2 (rpt2.jsp)", this has error, parameterFields seem cannot load parameter:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>  <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>  <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>  <%@ taglib uri="http://www.businessobjects.com/jsf/crystalreportsviewers" prefix="bocrv" %>          <head><title>View Report 2</title>  </head>  <body>  <f:view>  <h:form>  <bocrv:reportPageViewer reportSource="#{reportBean.reportSource2}" allowParameterPrompting="false"  parameterFields="#{reportBean.parameterFields}" />   </h:form>  </f:view>  <body>  </html> 

 

My report bean is:

package crDemo;    
import javax.faces.bean.ManagedBean;    
import com.crystaldecisions.reports.reportengineinterface.JPEReportSourceFactory;  
import com.crystaldecisions.sdk.occa.report.data.Fields;  
import com.crystaldecisions.sdk.occa.report.data.ParameterField;  
import com.crystaldecisions.sdk.occa.report.data.ParameterFieldDiscreteValue;  
import com.crystaldecisions.sdk.occa.report.data.Values;  
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;  
import com.crystaldecisions.sdk.occa.report.reportsource.IReportSourceFactory2;    
@ManagedBean  
public class ReportBean {      private Object reportSource1 = null;      private Object reportSource2 = null;      private String inputText = "";      private Fields<ParameterField> parameterFields = new Fields<ParameterField>();            public Object getReportSource1() {          return reportSource1;      }      public void setReportSource1(Object reportSource1) {          this.reportSource1 = reportSource1;      }      public Object getReportSource2() {          return reportSource2;      }      public void setReportSource2(Object reportSource2) {          this.reportSource2 = reportSource2;      }      public String getInputText() {          return inputText;      }      public void setInputText(String inputText) {          this.inputText = inputText;      }      public Fields<ParameterField> getParameterFields() {          return parameterFields;      }      public void setParameterFields(Fields<ParameterField> parameterFields) {          this.parameterFields = parameterFields;      }            public String show1() {          try {          // Instantiate the report object          String reportLocation;          reportLocation = "rpt/demo1.rpt";          IReportSourceFactory2 rptSrcFactory = new JPEReportSourceFactory();                        reportSource1 = rptSrcFactory.createReportSource(reportLocation, java.util.Locale.getDefault() );          } catch (ReportSDKException e) {              // TODO Auto-generated catch block              e.printStackTrace();          }          return "rpt1";      }            public String show2() {          try {          // Instantiate the report object          String reportLocation;          reportLocation = "rpt/demo2.rpt";          IReportSourceFactory2 rptSrcFactory = new JPEReportSourceFactory();          reportSource2 = rptSrcFactory.createReportSource(reportLocation, java.util.Locale.getDefault() );                    // Clear previous parameter          parameterFields.clear();            //Create a ParameterField object for each field that you wish to set.          ParameterField paramFieldOne = new ParameterField();            //You must set the report name. Set the report name to an empty string if your report does not contain a subreport; otherwise, the report name will be the name of the subreport          paramFieldOne.setReportName("");            //Create a Values object and a ParameterFieldDiscreteValue object for each parameter field you wish to set.          //If a ranged value is being set, a ParameterFieldRangeValue object should be used instead of the discrete value object.          Values valueOne = new Values();          ParameterFieldDiscreteValue paramFieldDVOne = new ParameterFieldDiscreteValue();            //----------- Initialize the parameter fields ----------            //Set the name and value for each parameter field that is added.          //Values for parameter fields are represented by a ParameterFieldDiscreteValue or ParameterFieldRangeValue object.          System.out.println("Input parameter = " + inputText);          paramFieldOne.setName("paramOne");  // "paramOne" is parameter name in my Crystal Report file (demo2.rpt)          paramFieldDVOne.setValue(inputText);            //Add the parameter field values to the Values collection object.          valueOne.add(paramFieldDVOne);            //Set the current Values collection for each parameter field.          paramFieldOne.setCurrentValues(valueOne);            //Add each parameter field to the Fields collection.          //The Fields object is now ready to be used with the viewer.          parameterFields.add(paramFieldOne);            } catch (ReportSDKException e) {              // TODO Auto-generated catch block              e.printStackTrace();          }          return "rpt2";      }  
}  

 

Here is runtime result:

https://public.bay.livefilestore.com/y1pigYkVz4Js_QEKhde3sLBYPuh4V2iGWCboJG3omrD6w5vwl1gOWhiMpfMcPFMzfENu7tLBpK-m1wwWb0mTYv7sg/run.png?psid=1

 

After enter some value, and click "Show report 2"

https://public.bay.livefilestore.com/y1pHsxtGjMgSla_sZlihB6Y7xB6kOyhcOMSwND5xgin5qV1sGw85K_SBJUFJUGt_OlOm7F2fwZ1FO_qVA25cxpmFA/Missing.png?psid=1


Viewing all articles
Browse latest Browse all 893

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>