You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Max Grigoriev <da...@mail.ru> on 2003/09/17 08:48:44 UTC
Re[2]: Show a picture from DB
But if i want to show not only images but also word documents, pdf and
etc. It will not work.
Tuesday, September 16, 2003, 3:24:03 PM, you wrote:
HK> Take a look at the ChartService in the workbench. Basically, you change
HK> your service link to an Image and create an Asset that returns the URL
HK> to your ViewDocService. Something like the following...
HK> Template:
HK> <img jwcid="@Image" image="ognl:externalDocAsset"..../>
HK> Asset:
HK> public class ExternalDocAsset extends AbstractAsset
HK> {
HK> // Take a look at ChartAsset in workbench to see what methods to
HK> implement
HK> }
HK> Service:
HK> ... you already have this.
HK> Page:
HK> .....
HK> public IAsset getExternalDocAsset()
HK> {
HK> return new ExternalDocAsset(getRequestCycle(), this);
HK> }
HK> .....
HK> -Harish
HK> Max Grigoriev wrote:
>>Hello tapestry-user,
>>
>> I try to implememt my own service for showing pictures:
>>
>> My Service:
>>
>>public class ViewDocumentService extends AbstractService {
>> public static final String VIEW_DOC_SERVICE = "viewdoc";
>>
>> public String getName() {
>> return VIEW_DOC_SERVICE;
>> }
>>
>> public void service(IEngineServiceView iEngineServiceView, IRequestCycle cycle,
>> ResponseOutputStream responseOutputStream)
>> throws ServletException, IOException {
>> HttpServletResponse response =
>> cycle.getRequestContext().getResponse();
>> String[] params = getServiceContext(cycle.getRequestContext());
>> if (params == null || params.length != 1) {
>> throw new ApplicationRuntimeException(
>> Tapestry.format("service-single-context-parameter", VIEW_DOC_SERVICE));
>> }
>> Visit visit = (Visit) cycle.getEngine().getVisit();
>> try {
>> //My picture holder
>> ExternalDocument extDoc =
>> ReportHome.getExternalDocument(params[0],
>> visit.getReport(), null);
>> response.setContentType("image/jpeg");
>> byte[] buf = extDoc.getValue();
>> response.getOutputStream().write(buf);
>>
>> //for debug only...
>> File f = new File(extDoc.getName());
>> FileOutputStream out = new FileOutputStream(f);
>> out.write(buf);
>> out.close();
>> //end for debug...
>> } catch (MiddleException e) {
>> e.printStackTrace();
>> }
>> }
>>
>> public ILink getLink(IRequestCycle cycle, IComponent iComponent, Object[] objects) {
>> if (objects == null || objects.length == 0)
>> throw new ApplicationRuntimeException(
>> Tapestry.format("service-requires-parameters", VIEW_DOC_SERVICE));
>>
>> String docName = (String) objects[0];
>> String[] context = new String[]{docName};
>>
>> return constructLink(cycle, VIEW_DOC_SERVICE, context, new Object[0], true);
>>
>> }
>>
>> And i invoke this service like this:
>>
>><a jwcid="@ServiceLink"
>>
>> service="ognl:@com.clearview.feedback.web.ViewDocumentService@VIEW_DOC_SERVICE"
>> parameters="ognl:bean.currExtDocName"><span jwcid="@Insert"
>> value="ognl:bean.currExtDocName"/></a>
>>
>>But i don't see a picture. I tried to show picture and write it to
>>file. The picture saved in the file is OK, so i think i do something
>>wrong with tapestry.
>>
>>Has someone done such thing already ? And where is my fault ?
>>
>>Thank's
>>
>>
>>
HK> ---------------------------------------------------------------------
HK> To unsubscribe, e-mail:
HK> tapestry-user-unsubscribe@jakarta.apache.org
HK> For additional commands, e-mail:
HK> tapestry-user-help@jakarta.apache.org
--
Best regards,
Max mailto:darkit@mail.ru
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org