You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Borut Bolčina <bo...@gmail.com> on 2010/07/14 15:26:15 UTC
Binding component parameter of type byte[]
Hi,
I am having problem binding a parameter of type byte[]. It is not bound for
some reason while imageTitle works as expected. The page template looks
like:
<t:dynaimage t:image="imageBytes" t:title="imageTitle"/>
DynaImage is my custom component which displays image from byte[], or so it
should :-)
In my page class:
@Property
private String imageTitle;
@Property
private byte[] imageBytes;
void onActivate(Game game) {
this.game = game;
this.imageBytes = game.getImage();
this.imageTitle = "Hello";
logger.info("image size: " + this.imageBytes.length); // correctly
displays image size (cca 200kbytes)
}
And here is the component class:
public class DynaImage {
@Inject
private Logger logger;
@Inject
private ComponentResources componentResources;
@Parameter(name = "imageBytes", required = false)
private byte[] imageBytes;
@Parameter(name = "title", required = false)
private String title;
@BeginRender
protected boolean beginRender(MarkupWriter writer) throws SQLException {
if (!componentResources.isBound("title")) {
logger.warn("title not bound.");
} else {
logger.info("title: " + title);
}
if (!componentResources.isBound("imageBytes")) {
logger.warn("imageBytes not bound.");
return true;
}
ImageIcon image = null;
image = new ImageIcon(imageBytes);
// Write an action link for this photo
final Link link = componentResources.createEventLink("photo", new
Object[] { 999 });
writer.element("img", "src", link, "title", title, "alt", "Loading "
+ title, "height",
image.getIconHeight(), "width", image.getIconWidth());
componentResources.renderInformalParameters(writer);
writer.end();
return true;
}
Any help appreciated,
Borut
Re: Binding component parameter of type byte[]
Posted by Borut Bolčina <bo...@gmail.com>.
Dear lord, of course it is not bound, the name of the parameter is
inccorect. It should be
@Parameter(name = "*image*", required = false)
private byte[] imageBytes;
And I was already debugging Tapestry sources...
2010/7/15 Christophe Cordenier <ch...@gmail.com>
> Hi
>
> AFAIK Primitive arrays are coerced to List.
>
> 2010/7/14 Borut Bolčina <bo...@gmail.com>
>
> > Hi,
> >
> > I am having problem binding a parameter of type byte[]. It is not bound
> for
> > some reason while imageTitle works as expected. The page template looks
> > like:
> >
> > <t:dynaimage t:image="imageBytes" t:title="imageTitle"/>
> >
> > DynaImage is my custom component which displays image from byte[], or so
> it
> > should :-)
> >
> > In my page class:
> >
> > @Property
> > private String imageTitle;
> >
> > @Property
> > private byte[] imageBytes;
> >
> > void onActivate(Game game) {
> > this.game = game;
> > this.imageBytes = game.getImage();
> > this.imageTitle = "Hello";
> > logger.info("image size: " + this.imageBytes.length); //
> correctly
> > displays image size (cca 200kbytes)
> > }
> >
> > And here is the component class:
> >
> > public class DynaImage {
> >
> > @Inject
> > private Logger logger;
> >
> > @Inject
> > private ComponentResources componentResources;
> >
> > @Parameter(name = "imageBytes", required = false)
> > private byte[] imageBytes;
> >
> > @Parameter(name = "title", required = false)
> > private String title;
> >
> > @BeginRender
> > protected boolean beginRender(MarkupWriter writer) throws SQLException
> {
> > if (!componentResources.isBound("title")) {
> > logger.warn("title not bound.");
> > } else {
> > logger.info("title: " + title);
> > }
> > if (!componentResources.isBound("imageBytes")) {
> > logger.warn("imageBytes not bound.");
> > return true;
> > }
> >
> > ImageIcon image = null;
> >
> > image = new ImageIcon(imageBytes);
> >
> > // Write an action link for this photo
> > final Link link = componentResources.createEventLink("photo", new
> > Object[] { 999 });
> > writer.element("img", "src", link, "title", title, "alt", "Loading
> "
> > + title, "height",
> > image.getIconHeight(), "width", image.getIconWidth());
> > componentResources.renderInformalParameters(writer);
> >
> > writer.end();
> > return true;
> > }
> >
> >
> > Any help appreciated,
> > Borut
> >
>
>
>
> --
> Regards,
> Christophe Cordenier.
>
> Committer on Apache Tapestry 5
> Co-creator of wooki @wookicentral.com
>
Re: Binding component parameter of type byte[]
Posted by Christophe Cordenier <ch...@gmail.com>.
Hi
AFAIK Primitive arrays are coerced to List.
2010/7/14 Borut Bolčina <bo...@gmail.com>
> Hi,
>
> I am having problem binding a parameter of type byte[]. It is not bound for
> some reason while imageTitle works as expected. The page template looks
> like:
>
> <t:dynaimage t:image="imageBytes" t:title="imageTitle"/>
>
> DynaImage is my custom component which displays image from byte[], or so it
> should :-)
>
> In my page class:
>
> @Property
> private String imageTitle;
>
> @Property
> private byte[] imageBytes;
>
> void onActivate(Game game) {
> this.game = game;
> this.imageBytes = game.getImage();
> this.imageTitle = "Hello";
> logger.info("image size: " + this.imageBytes.length); // correctly
> displays image size (cca 200kbytes)
> }
>
> And here is the component class:
>
> public class DynaImage {
>
> @Inject
> private Logger logger;
>
> @Inject
> private ComponentResources componentResources;
>
> @Parameter(name = "imageBytes", required = false)
> private byte[] imageBytes;
>
> @Parameter(name = "title", required = false)
> private String title;
>
> @BeginRender
> protected boolean beginRender(MarkupWriter writer) throws SQLException {
> if (!componentResources.isBound("title")) {
> logger.warn("title not bound.");
> } else {
> logger.info("title: " + title);
> }
> if (!componentResources.isBound("imageBytes")) {
> logger.warn("imageBytes not bound.");
> return true;
> }
>
> ImageIcon image = null;
>
> image = new ImageIcon(imageBytes);
>
> // Write an action link for this photo
> final Link link = componentResources.createEventLink("photo", new
> Object[] { 999 });
> writer.element("img", "src", link, "title", title, "alt", "Loading "
> + title, "height",
> image.getIconHeight(), "width", image.getIconWidth());
> componentResources.renderInformalParameters(writer);
>
> writer.end();
> return true;
> }
>
>
> Any help appreciated,
> Borut
>
--
Regards,
Christophe Cordenier.
Committer on Apache Tapestry 5
Co-creator of wooki @wookicentral.com