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: tapestry-user@jakarta.apache.org > > > 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]