You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Luther Baker <lu...@gmail.com> on 2009/03/10 20:57:11 UTC

img tag (src)

If I am storing an image in the database - and would like to display it in
response to

   <img src="images/get/01"/>

I've implemented the following examples:

http://wiki.apache.org/tapestry/Tapestry5HowToStreamAnExistingBinaryFile
http://wiki.apache.org/tapestry/Tapestry5HowToCreateADynamicPDF

and I've got that work fine with something like

Object onActionFromX()
{
}

but what about rendering this image inline? I think I would want to
implement a render lifecycle method ... ? Does that sound correct?

It seems that these all return boolean -
http://tapestry.apache.org/tapestry5/guide/rendering.html -

Am I'm looking for a render method that returns an Object - and stops the
rest of the lifecycle?

Thanks in advance,

-Luther

Re: img tag (src)

Posted by iberck <ib...@gmail.com>.
My solution:

${image} 

public Link getImage() {
        Link link = resources.createEventLink("preview");
        return link;
}

Object onPreview() {
        return new StreamResponse(){}
}




--
View this message in context: http://tapestry.1045711.n5.nabble.com/img-tag-src-tp2425421p5716261.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: img tag (src)

Posted by Luther Baker <lu...@gmail.com>.
Got it! thanks to both of you and the examples.

Wow - onActivate can return an Object :) and nice to know about
ComponentResources.

-Luther





On Wed, Mar 11, 2009 at 10:15 AM, Elmer Smith <es...@venterraliving.com>wrote:

> I have a component based off of the example Thiago mentions.  The just
> of it is:
>
>  - a page ViewImage that has an activation context of a d/b related ID
>  - that pages onActivate returns a StreamResponse
>  - the stream response is created by loading bytes from the d/b using
> the ID passed in the activation context
>  - a component that uses a template with an <img /> tag
>  - the component provides a link to the ViewImage page; the link can be
> constructed to ask the containing component (or page) to provide the
> byte stream or it will provide a default
>
> I use this all over to render images that are stored in the database.
>
> Hope that helps,
> Elmer
>
> -----Original Message-----
> From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com]
> Sent: Wednesday, March 11, 2009 9:52 AM
> To: Tapestry users
> Subject: Re: img tag (src)
>
> Maybe
> http://wiki.apache.org/tapestry/Tapestry5HowToCreateASimpleGraphComponen
> t
> is an example that can be adapted to what you need.
>
> > So, from a different perspective, what I really want in my page is
> somethin like
> > Object onRender()
> > {
> >   StreamResponse = ...
> >   <blah/>
> >   return streamResponse;
> > }
>
> Instead of onRender(), use onActivate(). ;)
>
> --
> Thiago
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
> This message (including any attachments) is intended only for the use of
> the individual or entity to whom it is addressed and may contain information
> that is non-public, proprietary, privileged, confidential, and exempt from
> disclosure under applicable law or may constitute attorney work product. If
> you are not the intended recipient, you are hereby notified that any use,
> dissemination, distribution, or copying of this communication is strictly
> prohibited. If you have received this communication in error, please notify
> us immediately by telephone and (i) destroy this message if a facsimile or
> (ii) delete this message immediately if an electronic communication.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

RE: img tag (src)

Posted by Elmer Smith <es...@venterraliving.com>.
I have a component based off of the example Thiago mentions.  The just
of it is:

  - a page ViewImage that has an activation context of a d/b related ID
  - that pages onActivate returns a StreamResponse
  - the stream response is created by loading bytes from the d/b using
the ID passed in the activation context
  - a component that uses a template with an <img /> tag
  - the component provides a link to the ViewImage page; the link can be
constructed to ask the containing component (or page) to provide the
byte stream or it will provide a default

I use this all over to render images that are stored in the database.

Hope that helps,
Elmer

-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com] 
Sent: Wednesday, March 11, 2009 9:52 AM
To: Tapestry users
Subject: Re: img tag (src)

Maybe
http://wiki.apache.org/tapestry/Tapestry5HowToCreateASimpleGraphComponen
t
is an example that can be adapted to what you need.

> So, from a different perspective, what I really want in my page is
somethin like
> Object onRender()
> {
>   StreamResponse = ...
>   <blah/>
>   return streamResponse;
> }

Instead of onRender(), use onActivate(). ;)

-- 
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


This message (including any attachments) is intended only for the use of the individual or entity to whom it is addressed and may contain information that is non-public, proprietary, privileged, confidential, and exempt from disclosure under applicable law or may constitute attorney work product. If you are not the intended recipient, you are hereby notified that any use, dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by telephone and (i) destroy this message if a facsimile or (ii) delete this message immediately if an electronic communication.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: img tag (src)

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Maybe http://wiki.apache.org/tapestry/Tapestry5HowToCreateASimpleGraphComponent
is an example that can be adapted to what you need.

> So, from a different perspective, what I really want in my page is somethin like
> Object onRender()
> {
>   StreamResponse = ...
>   <blah/>
>   return streamResponse;
> }

Instead of onRender(), use onActivate(). ;)

-- 
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: img tag (src)

Posted by Luther Baker <lu...@gmail.com>.
I was hoping to wake up to a solution/suggestion :)

Anyone?

So, from a different perspective, what I really want in my page is something
like


Object onRender()
{
   StreamResponse = ...
   <blah/>
   return streamResponse;
}


where I can simply return the blog - just like onActionFromId ... type
handlers. The problem here for me is ...

what event to use when rendering a url the browser requests (like <img
src="[tapestry/Url]"/>) and how to get a binary response back and cease the
rest of the events..

Dare I try

Object pageAttached()
{
 ...
}


Hope that makes sense. Simplistically, I'm just trying to render an image
when the page is requested.

Were this stuts, I do this in the execute method of the action but with the
stages Tapestry has, I'm sure I need to think about it subtley differently.
I just haven't done something like this when RENDERING the page - only on
ACTION from the page - etc.

I'll keep thinking about it - maybe I am just missing it. Thanks,

-Luther



On Wed, Mar 11, 2009 at 1:25 AM, Luther Baker <lu...@gmail.com> wrote:

> So I've embedded an img tag as follows: <img src="image/Get/1"/>
>
> The url "image/Get/1" invokes page "image/Get" with an activation context
> of "1". The *.java onActivate handler loads the image from Hibernate. The
> corresponding *.tml page only has one component on it of which takes a
> @Parameter of type Image ... which the page successfully gives it.
>
> <t:Layout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
>     <t:ImageStream image="value"/>
> </t:Layout>
>
> And hopefully, the ImageStream component attempts to render itself --- does
> this sound correct so far?
>
> My problem is - how does the component render binary data? IE: component
> render methods can take 0 or 1 argument, a MarkupWriter ... which doesn't
> have a binary output method. And if I try to be slick and change the render
> method signature to
>
> Object beginRender()
>
> I predictably get the error:
>
> "The return value from a render phase event method was not compatible the
> expected return type of java.lang.Boolean. You should change the method to
> return the correct type."
>
> So I think I'm back to the same question, "is there a way I can return
> binary information as part of a page or component's rendering lifecycle?"
> i.e.: in response to a GET.
>
> I can definitely do it onAction, onSuccess, etc since those methods can
> return Object ... streams, pages, etc. But what about BEFORE the user takes
> such action ... in the rendering cycle or as a simple response to a GET.
> Those render lifecycle methods seem to return boolean.
>
> Does that question make sense? Thanks,
>
> -Luther
>
>
>
>
>
> On Tue, Mar 10, 2009 at 5:06 PM, Thiago H. de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
>> Em Tue, 10 Mar 2009 16:57:11 -0300, Luther Baker <lu...@gmail.com>
>> escreveu:
>>
>>  Am I'm looking for a render method that returns an Object - and stops the
>>> rest of the lifecycle?
>>>
>>
>> I would try to create a component instead. It is a more reusable solution.
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Independent Java consultant, developer, and instructor
>> http://www.arsmachina.com.br/thiago
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>

Re: img tag (src)

Posted by Luther Baker <lu...@gmail.com>.
So I've embedded an img tag as follows: <img src="image/Get/1"/>

The url "image/Get/1" invokes page "image/Get" with an activation context of
"1". The *.java onActivate handler loads the image from Hibernate. The
corresponding *.tml page only has one component on it of which takes a
@Parameter of type Image ... which the page successfully gives it.

<t:Layout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
    <t:ImageStream image="value"/>
</t:Layout>

And hopefully, the ImageStream component attempts to render itself --- does
this sound correct so far?

My problem is - how does the component render binary data? IE: component
render methods can take 0 or 1 argument, a MarkupWriter ... which doesn't
have a binary output method. And if I try to be slick and change the render
method signature to

Object beginRender()

I predictably get the error:

"The return value from a render phase event method was not compatible the
expected return type of java.lang.Boolean. You should change the method to
return the correct type."

So I think I'm back to the same question, "is there a way I can return
binary information as part of a page or component's rendering lifecycle?"
i.e.: in response to a GET.

I can definitely do it onAction, onSuccess, etc since those methods can
return Object ... streams, pages, etc. But what about BEFORE the user takes
such action ... in the rendering cycle or as a simple response to a GET.
Those render lifecycle methods seem to return boolean.

Does that question make sense? Thanks,

-Luther




On Tue, Mar 10, 2009 at 5:06 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> Em Tue, 10 Mar 2009 16:57:11 -0300, Luther Baker <lu...@gmail.com>
> escreveu:
>
>  Am I'm looking for a render method that returns an Object - and stops the
>> rest of the lifecycle?
>>
>
> I would try to create a component instead. It is a more reusable solution.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java consultant, developer, and instructor
> http://www.arsmachina.com.br/thiago
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: img tag (src)

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Tue, 10 Mar 2009 16:57:11 -0300, Luther Baker <lu...@gmail.com>  
escreveu:

> Am I'm looking for a render method that returns an Object - and stops the
> rest of the lifecycle?

I would try to create a component instead. It is a more reusable solution.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: img tag (src)

Posted by Christine <ch...@christine.nl>.
Hi,
may I suggest that the tutorial on tapestry.apache.org ("tutorial1") be
updated? The "mvn create" command doesn't work for me as it is now,
maven suggested I use "generate", but then you need some additional info
to make it work properly. This would make life easier for newbies - like
me.
Maybe this has been suggested before, couldn't find it in the archives.
I'm willing to provide the new chunks of text.

dagdag
Christine


-- 
dagdag is just a two character rotation of byebye
www.christine.nl