You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Bill Holloway <bi...@gmail.com> on 2006/12/09 09:32:11 UTC

First pass at a Tapestry 5 Image Component

I needed one, so I took a shot at it.  Flame away! :) Package
declaration deliberately left out:

import java.io.IOException;

import org.apache.tapestry.Asset;
import org.apache.tapestry.MarkupWriter;
import org.apache.tapestry.annotations.BeginRender;
import org.apache.tapestry.annotations.ComponentClass;
import org.apache.tapestry.annotations.Mixin;
import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.corelib.mixins.RenderInformals;

@ComponentClass
public class Image
{
	@Parameter (required = true)
	private Asset _imageAsset;
	
	@Parameter
	private String _description;
	
	@Mixin
	private RenderInformals _renderInformals;
	
	@BeginRender
	public void renderImageTag (MarkupWriter writer)
	{
		writer.element (	"img",
							"src", _imageAsset.getResource().getPath(),
							"alt", _description
		);
		
	}
}

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


Re: First pass at a Tapestry 5 Image Component

Posted by Massimo Lusetti <ml...@gmail.com>.
On 12/10/06, Howard Lewis Ship <hl...@gmail.com> wrote:

> I'm thinking about a custom JavaDoc doclet to generate component
> documentation, since most of what you need to document is private.
> Alternately, perhaps Tapestry code JavaDoc should just include privates as
> well as everything else?

I would go with the inclusion of privates methods within JavaDoc, that
would reveal how public/protected methods would like to act.

-- 
Massimo
http://meridio.blogspot.com

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


Re: First pass at a Tapestry 5 Image Component

Posted by Howard Lewis Ship <hl...@gmail.com>.
Hey, if it works for you.

description vs. alt : Early Tapestry 1.0 established the precendent of
giving "Java-ish" aliases to common HTML attributes.  A mistake, in my
opinion, since it gained little, obscured some, and requires that much more
documentation.

In other words, I wouldn't inlcude a description parameter, but I would
include informal parameters.

In addition, the correct code is:

  writer.element("img", "src", _imageAsset.toClientURL(), "alt",
_description);


That is, Asset includes a toClientURL() method for the express purpose of
this code snippet. I don't know if its in the latest snapshot, but it's in
Subversion trunk.


In fact:

  writer.element("img", "src", _imageAsset, "alt", _description);

should also work, since toString() is used on the values, and for Assets,
toString() is explicitly the same as toClientURL().

Subversion trunk also includes classpath assets, and a new idea, classpath
aliases (a way of creating shorter, more mnuemonic URIs for classpath
assets).

Bill -- I saw you figured out that you needed to invoke writer.end()  (and
this is documented multiple times, in bold!) ... was the behavior and/or
error messages sufficient? How hard was it for you to track this down?

What's interesting with the Tapestry components is often they have NO public
methods.  That's a pretty easy API to remember.

I'm thinking about a custom JavaDoc doclet to generate component
documentation, since most of what you need to document is private.
Alternately, perhaps Tapestry code JavaDoc should just include privates as
well as everything else?

On 12/9/06, Bill Holloway <bi...@gmail.com> wrote:
>
> Well, didn't end writer.  Also "public'ed" methods --
>
> @BeginRender
> void renderImageTag (MarkupWriter writer)
> {
>         writer.element (        "img",
>                                         "src",
> _imageAsset.getResource().getPath(),
>                                         "alt", _description
>        );
>
> }
>
> @AfterRender
> void afterRender (MarkupWriter writer)
>         {
>                 writer.end();
>         }
>
> On 12/9/06, Bill Holloway <bi...@gmail.com> wrote:
> > I needed one, so I took a shot at it.  Flame away! :) Package
> > declaration deliberately left out:
> >
> > import java.io.IOException;
> >
> > import org.apache.tapestry.Asset;
> > import org.apache.tapestry.MarkupWriter;
> > import org.apache.tapestry.annotations.BeginRender;
> > import org.apache.tapestry.annotations.ComponentClass;
> > import org.apache.tapestry.annotations.Mixin;
> > import org.apache.tapestry.annotations.Parameter;
> > import org.apache.tapestry.corelib.mixins.RenderInformals;
> >
> > @ComponentClass
> > public class Image
> > {
> >         @Parameter (required = true)
> >         private Asset _imageAsset;
> >
> >         @Parameter
> >         private String _description;
> >
> >         @Mixin
> >         private RenderInformals _renderInformals;
> >
> >         @BeginRender
> >         public void renderImageTag (MarkupWriter writer)
> >         {
> >                 writer.element (        "img",
> >                                                         "src",
> _imageAsset.getResource().getPath(),
> >                                                         "alt",
> _description
> >                 );
> >
> >         }
> > }
> >
>
>
> --
> "Budgets are moral documents."
>
>      -- Ann Richards
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

Re: First pass at a Tapestry 5 Image Component

Posted by Bill Holloway <bi...@gmail.com>.
Well, didn't end writer.  Also "public'ed" methods --

@BeginRender
void renderImageTag (MarkupWriter writer)
{
	writer.element (	"img",
					"src", _imageAsset.getResource().getPath(),
					"alt", _description
       );
		
}
	
@AfterRender
void afterRender (MarkupWriter writer)
	{
		writer.end();
	}

On 12/9/06, Bill Holloway <bi...@gmail.com> wrote:
> I needed one, so I took a shot at it.  Flame away! :) Package
> declaration deliberately left out:
>
> import java.io.IOException;
>
> import org.apache.tapestry.Asset;
> import org.apache.tapestry.MarkupWriter;
> import org.apache.tapestry.annotations.BeginRender;
> import org.apache.tapestry.annotations.ComponentClass;
> import org.apache.tapestry.annotations.Mixin;
> import org.apache.tapestry.annotations.Parameter;
> import org.apache.tapestry.corelib.mixins.RenderInformals;
>
> @ComponentClass
> public class Image
> {
>         @Parameter (required = true)
>         private Asset _imageAsset;
>
>         @Parameter
>         private String _description;
>
>         @Mixin
>         private RenderInformals _renderInformals;
>
>         @BeginRender
>         public void renderImageTag (MarkupWriter writer)
>         {
>                 writer.element (        "img",
>                                                         "src", _imageAsset.getResource().getPath(),
>                                                         "alt", _description
>                 );
>
>         }
> }
>


-- 
"Budgets are moral documents."

     -- Ann Richards

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