This will probably help (3.0.3):

        1: The Service:

package services;

import java.io.IOException;

import javax.servlet.ServletException;

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 survey.InternalImage;
import data.HibHelper;

public class InternalImageServer extends AbstractService {
        public static final String SERVICE_NAME = "InternalImageServer";

        public ILink getLink(IRequestCycle cycle, IComponent component,
                        Object[] parms) {
                String[] context;
                String pageName = component.getPage().getPageName();
                String idPath = component.getIdPath();

                if (idPath != null) {
                        context = new String[2];
                        context[1] = idPath;
                } else
                        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 id = (String) parms[0];
                InternalImage ii = (InternalImage)
HibHelper.getSession().get(InternalImage.class, id);            
                response.setContentType(ii.getType());
                response.write(ii.getData());           
        }

        public String getName() {

                return SERVICE_NAME;
        }

}

        Step 2: The ImageLink java file

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.InternalImageServer;

public abstract class ImageLink extends BaseComponent { 
        private String fImageId;
        private String fAlt = null;
        private String fTitleText = null;

        public String getAlt() {
                if (fAlt == null)
                        fAlt = "Alt";
                return fAlt;
        }

        public void setAlt(String alt) {
                fAlt = alt;
        }

        public String getTitleText() {
                if (fTitleText == null)
                        fTitleText = "Title";
                return fTitleText;
        }

        public void setTitleText(String titleText) {
                fTitleText = titleText;
        }

        public String getImageId() {
                return fImageId;
        }

        public void setImageId(String imageId) {
                fImageId = imageId;
        }
        
        public String getLink() {
                IRequestCycle cycle = getPage().getRequestCycle();
                IEngineService service =
cycle.getEngine().getService(InternalImageServer.SERVICE_NAME);

                Object[] parms = new Object[1];
                parms[0] = fImageId;
                ILink link = service.getLink(cycle, this, parms);
                return link.getAbsoluteURL();
        }

}
        Part 3: The ImageLink .jwc 
<?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.ImageLink"
    allow-body="yes"
    allow-informal-parameters="yes">
    
    <description>add a description</description>
    <parameter name="imageId" required="yes" type="java.lang.String"
direction="in"/>
    <parameter name="alt" required="no" type="java.lang.String"
direction="in" />
    <parameter name="titleText" required="no" type="java.lang.String"
direction="in" />
</component-specification>

        Part 4: The Imagelink html
<span jwcid="@Any" element="img" src="ognl:getLink()" alt="ognl:alt"
title="ognl:titleText"/>

        

> -----Original Message-----
> From: skydiverx [mailto:[EMAIL PROTECTED]
> Sent: Sunday, January 29, 2006 3:43 PM
> To: [email protected]
> Subject: Images from DB
> 
> Apologies all around if I have missed the obvious.
> 
> What would be best practise if I have images stored as BLOBs in a DB and
> want to display those through a  tag?
> 
> This has to be a fairly common problem and yet we have failed to find some
> mention of this in the docs.
> 
> I dont know if it's relevant but we use Hibernate on top of MySQL.
> 
> Thank you in advance for your advice.
> 
> Tom.
> 
> 
> -------------------- m2f --------------------
> 
> Sent from www.TapestryForums.com
> 
> Read this topic online here: <<topic_link>>
> 
> http://www.tapestryforums.com/viewtopic.php?p=13981#13981
> 
> -------------------- m2f --------------------
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to