I have created a component and a service like that, you can found them at here (sorry no SVN yet) :
http://keyintegrity.com/download/servicehub-src-beta-2.tar.tar.gz<http://keyintegrity.com/download/servicehub-src-beta-1.0.tar.gz> JavaSource/org/keyintegrity/servicehub/csulengine/components/JasperReport.jwc : -------------------------------- *<?xml* version="1.0" encoding="UTF-8"*?>**<!-- ** Copyright 2005 The Key Integrity.* * Licensed under the Apache License, Version 2.0 (the "License");** you may not use this file except in compliance with the License.** You may obtain a copy of the License at* * http://www.apache.org/licenses/LICENSE-2.0* * Unless required by applicable law or agreed to in writing, software** distributed under the License is distributed on an "AS IS" BASIS,** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.** See the License for the specific language governing permissions and** limitations under the License.**-->* *<!DOCTYPE *component-specification PUBLIC "-//Apache Software Foundation//Tapestry Specification 4.0//EN" "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd"*>**<component-specification* class="org.keyintegrity.servicehub.csulengine.components.JasperReport" allow-body="no" allow-informal-parameters= "no"*>* *<description>* JasperReports *</description>* *<property* name="jasperPrint"*/>* *<parameter* name="compiledDesign"*>* *<description>* A path to compiled report design file (*.jasper). One of compiledDesign or reportDesign parameters must be provided. If both then reportDesign is ignored. *</description>* *</parameter>* *<parameter* name="reportDesign"*>* *<description>* A path to jasper report design file (*.jrxml). One of compiledDesign or reportDesign parameters must be provided. If both then reportDesign is ignored. *</description>* *</parameter>*** *<parameter* name="scope" default-value="literal:session"*>* *<description>* Defines the report scope (the availability of the report resources like images etc.). May be "shared" - shared between different sessions or "session". *</description>* *</parameter>* *<parameter* name="reportName" default-value="literal:report"*/>* *<parameter* name="reportParameters"*/>* *<parameter* name="dataSourceProvider"*>* *<description>* JRDataSourceProvider *</description>* *</parameter>* *<inject* property="resourceService" object="service:servicehub.csulengine.services.Resource"*/>* *<inject* property="sharedResourceProvider" type="state" object="shared-resource-provider"*/>* *<inject* property="sessionResourceProvider" type="state" object="session-resource-provider"*/>* *</component-specification>* ----------------------------------------------- This component works with Jasperreports, it's sample output is here : http://keyintegrity.com/files/jasperreport.gif It uses so called Resource service that allows to provide secure access to IWebResource via URL using ResourceProviders. ----------------------------- package org.keyintegrity.servicehub.csulengine.services; /** * A type of [EMAIL PROTECTED] org.keyintegrity.servicehub.csulengine.services.IResource} that may be accessed over * [EMAIL PROTECTED] org.keyintegrity.servicehub.csulengine.services.ResourceService} * * @author Dmitry I. Gusev <[EMAIL PROTECTED]> * */ public interface IWebResource extends IResource { /** * Mime type of resource data. May be null. */ public String getContentType(); /** * Resource data. */ public byte[] getData(); } -------------------------------- Here is an example of placing a report to your page: ------------------------------------------ *<page* jwcid="@Csul:page" type="home" description="JasperReports Tag Example"*>* *<section* jwcid="@Csul:section" name="JasperReport Overview"*>* *<JasperReport* jwcid="@Csul:JasperReport" reportDesign="/jasperreports/report.jrxml" reportParameters="ognl:reportParameters" dataSourceProvider="ognl:dataSourceProvider" */>* *</section>* *</page> * ------------------------------------------ You can find more information in the sources (there are a module with the reporting example : WebContent/WEB-INF/modules/reporting/). 2006/1/26, Patrick Casey <[EMAIL PROTECTED]>: > > > They are; I should have mentioned that. I'm likely to still be on > 3.0 for at least the next few months. > > --- Pat > > > -----Original Message----- > > From: Cliff Zhao [mailto: [EMAIL PROTECTED] > > Sent: Wednesday, January 25, 2006 1:22 PM > > To: Tapestry users > > Subject: Re: Wiring up an Export service > > > > Are these Tapestry 3 or 4? They seems to be Tapestry 3. > > > > > > On 1/25/06, Patrick Casey <[EMAIL PROTECTED]> wrote: > > > > > > > > > Steve, > > > > > > Probably the easiest way to invoke a service is to link > directly > > > to > > > it rather than use a directlink, have the page listener fire, and then > > > invoke the service. So what I'd recommend is that you see if you can > use > > > the > > > existing ServiceLink component to invoke your service or, alternately, > > > > just > > > write your own "PDFLink" component. > > > > > > Here as a model is a service of mine that prints BIRT reports > > (I'm > > > not including all the dependencies but you an see the code flow). Also > > > > attached is the ReportLink component that links to it. > > > > > > 1: The report Link jwc and .html > > > > > > <?xml version="1.0" encoding="UTF-8"?> > > > <!DOCTYPE component-specification PUBLIC > > > "-//Apache Software Foundation//Tapestry Specification 3.0//EN" > > > " http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd"> > > > <!-- generated by Spindle, http://spindle.sourceforge.net --> > > > > > > <component-specification class=" components.ReportLink" > > > allow-body="yes" > > > allow-informal-parameters="yes"> > > > > > > <description>add a description</description> > > > <parameter name="reportName" required="yes" type="java.lang.String > " > > > direction="in"/> > > > <parameter name="keys" required="no" type=" java.lang.String[]" > > > direction="in" /> > > > <parameter name="values" required="no" type="java.lang.String[]" > > > direction="in" /> > > > <parameter name="pdf" required="no" type="boolean" direction="in" > /> > > > </component-specification> > > > > > > <span jwcid="@Any" element="a" href="ognl:getLink()"> > > > <span jwcid="@RenderBody" /> > > > </span> > > > > > > 2: The ReportLink .java (which constructs the link to the > > service) > > > > > > package components; > > > > > > import org.apache.tapestry.BaseComponent; > > > import org.apache.tapestry.IRequestCycle; > > > import org.apache.tapestry.engine.IEngineService; > > > import org.apache.tapestry.engine.ILink ; > > > > > > import services.ReportServer; > > > > > > public abstract class ReportLink extends BaseComponent { > > > private String fReportName; > > > private String fText; > > > private boolean fPdf = false; > > > private String[] fKeys; > > > private String[] fValues; > > > > > > public boolean isPdf() { > > > return fPdf; > > > } > > > > > > public void setPdf(boolean pdf) { > > > fPdf = pdf; > > > } > > > > > > public String[] getKeys() { > > > return fKeys; > > > } > > > > > > public void setKeys(String[] keys) { > > > fKeys = keys; > > > } > > > > > > public String getReportName() { > > > return fReportName; > > > } > > > > > > public void setReportName(String reportName) { > > > fReportName = reportName; > > > } > > > > > > public String[] getValues() { > > > return fValues; > > > } > > > > > > public void setValues(String[] values) { > > > fValues = values; > > > } > > > > > > public String getLink() { > > > IRequestCycle cycle = getPage().getRequestCycle(); > > > IEngineService service = > > > cycle.getEngine().getService(ReportServer.SERVICE_NAME); > > > > > > Object[] parms = new Object[4]; > > > parms[0] = fReportName; > > > parms[1] = fKeys; > > > parms[2] = fValues; > > > parms[3] = fPdf; > > > ILink link = service.getLink(cycle, this, parms); > > > return link.getAbsoluteURL (); > > > } > > > > > > public String getText() { > > > return fText; > > > } > > > > > > public void setText(String text) { > > > fText = text; > > > } > > > > > > } > > > > > > 3: The Service Itself > > > > > > package services; > > > > > > import java.io.IOException; > > > import java.util.Date; > > > import java.util.HashMap; > > > > > > import javax.servlet.ServletException; > > > > > > import message.SystemMessage; > > > import navigation.Gallileo; > > > > > > import org.apache.tapestry.IComponent; > > > import org.apache.tapestry.IRequestCycle; > > > import org.apache.tapestry.engine.AbstractService; > > > import org.apache.tapestry.engine.IEngineServiceView; > > > import org.apache.tapestry.engine.ILink; > > > import org.apache.tapestry.request.ResponseOutputStream; > > > import org.eclipse.birt.report.engine.api.HTMLRenderOption ; > > > > > > import presentation.Visit; > > > > > > import reports.ReportManager; > > > import security.GateKeeper; > > > import servlet.MyServlet; > > > import utils.DateUtils ; > > > > > > public class ReportServer extends AbstractService { > > > public static final String SERVICE_NAME = "ReportServer"; > > > private String FIRSTDOM = "$firstDOM"; > > > private String FIRSTDONM = "$firstDONM"; > > > private String FIRSTDOLM = "$firstDOLM"; > > > > > > private Object processValue(String test) { > > > if (test == null || !test.startsWith("$")) > > > return test; > > > // maybe > > > if (FIRSTDOM.equals(test)) > > > return DateUtils.getFirstDayOfMonth(null); > > > else if (FIRSTDONM.equals(test)) > > > return DateUtils.getFirstDayOfNextMonth(null); > > > > else if (FIRSTDOLM.equals(test)) > > > return DateUtils.getFirstDayOfLastMonth(null); > > > else > > > return test; > > > > > > } > > > public ILink getLink(IRequestCycle cycle, IComponent > component, > > > Object[] parms) { > > > String[] context; > > > String pageName = component.getPage().getPageName(); > > > String idPath = component.getIdPath(); > > > context = new String[1]; > > > context[0] = pageName; > > > return constructLink(cycle, SERVICE_NAME, context, > > parms, > > > true); > > > } > > > > > > public void service(IEngineServiceView acrg0, IRequestCycle > > cycle, > > > ResponseOutputStream response) throws > > > ServletException, IOException { > > > Object[] parms = this.getParameters(cycle); > > > String reportName = (String) parms[0]; > > > String[] keys = (String[]) parms[1]; > > > String[] values = (String[]) parms[2]; > > > boolean pdf = (Boolean) parms[3]; > > > HashMap params = new HashMap(); > > > int max = Math.min(keys.length, values.length); > > > // check authorization... > > > if (!GateKeeper.canViewReport(reportName)){ > > > Visit v = MyServlet.getVisit(); > > > String message = > > > SystemMessage.bindMessage("generic_not_authorized"); > > > v.getMessageQueue().addError(message); > > > Gallileo.goHome(cycle); > > > return; > > > } > > > for (int x = 0; x < max; x++) { > > > String key = keys[x]; > > > String value = values[x]; > > > Object send = processValue(value); > > > // big time bodge > > > if (send instanceof Date) { > > > send = DateUtils.renderBirtString > ((Date) > > > send); > > > } > > > params.put(key, send); > > > } > > > // now we render the report > > > response.setContentType("text/html"); > > > String output; > > > if (pdf) { > > > response.setContentType("application/pdf"); > > > > > > cycle.getRequestContext().getResponse().setHeader("Pragma", "public"); > > > > > > cycle.getRequestContext().getResponse().setHeader("Cache-Control", > > > "max-age=0"); > > > output = HTMLRenderOption.OUTPUT_FORMAT_PDF; > > > } else > > > output = HTMLRenderOption.OUTPUT_FORMAT_HTML; > > > ReportManager.runReport(reportName, params, response, > > > output); > > > > > > } > > > > > > public String getName() { > > > > > > return SERVICE_NAME; > > > } > > > > > > } > > > > > > > -----Original Message----- > > > > From: Steve Wells [mailto:[EMAIL PROTECTED] > > > > Sent: Wednesday, January 25, 2006 1:04 AM > > > > To: [email protected] > > > > Subject: Wiring up an Export service > > > > > > > > Like many folks I have a requirement to stream out reports (or > > whatever) > > > > in various formats eg pdf, xls > > > > > > > > Following some threads here I've started writing a Service to handle > > > > this but am having trouble wiring it into my pages (some basic Tap > > > > knowledge is eluding me here) > > > > > > > > The basic flow is: > > > > ReportCriteria page to collect parameters eg. date range, export > > format > > > > Form submit listener calls ReportResult page to get the report data > > and > > > > spit out to user in selected format... > > > > ...OR should the listener call the service, if so how? > > > > > > > > Any more detailed code examples or tips would be fantastic. I'm > > > > starting to feel a bit dumb right now as I can't see how a page > talks > > to > > > > a service. > > > > > > > > Thanks... > > > > -- > > > > Steve Wells > > > > [EMAIL PROTECTED] > > > > > > > > -- > > > > http://www.fastmail.fm - Or how I learned to stop worrying and > > > > love email again > > > > > > > > > > > > > --------------------------------------------------------------------- > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >
