You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Cristina <cr...@acm.org> on 2008/12/28 06:37:40 UTC

Dynamically generating an img tag

Hi,

I'm trying to generate an img tag pointing to a Google chart at
http://chart.apis.google.com/. I'm getting the chart URL as a string and I
need to generate the img tag in order to display it as an image.

I'm trying to use a Label, like:

HTML:

            <div wicket:id="imgDisplay">img tag goes here</div>

Java:

            // prefix and sufix hold the start and end of the img tag
            String imgTag = prefix + getImgURL() + sufix;
            add(new Label("imgDisplay", imgTag));

Problem is, < > and " are not interpreted as markup delimiters, but as
normal characters, so all I've got is the URL displayed as a literal where
the image should be displayed.

Is there a simple way to do something like this?

Thanks so much,

Cristina

-- 
View this message in context: http://www.nabble.com/Dynamically-generating-an-img-tag-tp21190259p21190259.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Dynamically generating an img tag

Posted by Cristina <cr...@acm.org>.
Thanks Jeremy, Jonathan and Jan.

Jan, I've tried your suggestion and it works as expected... :-) Still,
Jeremy is right when he defends a cleaner solution. I'll try his suggestion
as well.

The Wicket API for Google Charts seems very interesting, Jonathan. I'm
already using charts4j to encode the chart... It's an interesting project,
too. Please see:

 http://code.google.com/p/charts4j/

Best regards,

Cristina



Jeremy Thomerson-5 wrote:
> 
> Or use a WebMarkupContainer and an AttributeModifier.  Wrap this in your
> own
> class so you're not writing HTML in your Java code.  Then your links are
> actually in your HTML (except the SRC which gets generated in code) and
> your
> designers can stylize the links etc.  Much better IMHO.
> 
> [...]
> 

-- 
View this message in context: http://www.nabble.com/Dynamically-generating-an-img-tag-tp21190259p21199079.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Dynamically generating an img tag

Posted by Jeremy Thomerson <je...@wickettraining.com>.
Or use a WebMarkupContainer and an AttributeModifier.  Wrap this in your own
class so you're not writing HTML in your Java code.  Then your links are
actually in your HTML (except the SRC which gets generated in code) and your
designers can stylize the links etc.  Much better IMHO.

Something like:
 public class MyLink extends WebMarkupContainer {
    private static final long serialVersionUID = 1L;
    public MyLink(String id, IModel<String> model) {
        super(id);
        add(new AttributeModifier("src", true, model));
    }
}
In your HTML:
<a href="#" class="yourClass" wicket:id="yourID">your text</a>

It doesn't abuse Label this way, and is much more in line with the standard
Wicket way.

-- 
Jeremy Thomerson
http://www.wickettraining.com




On Sun, Dec 28, 2008 at 12:07 AM, Jan Kriesten
<kr...@mail.footprint.de>wrote:

>
> Hi Cristina,
>
> > Java:
> >
> >             // prefix and sufix hold the start and end of the img tag
> >             String imgTag = prefix + getImgURL() + sufix;
> >             add(new Label("imgDisplay", imgTag));
>
> try:
>
> add(new Label("imgDisplay", imgTag).setEscapeModelStrings(false));
>
> Best regards, --- Jan.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Dynamically generating an img tag

Posted by Jan Kriesten <kr...@mail.footprint.de>.
Hi Cristina,

> Java:
> 
>             // prefix and sufix hold the start and end of the img tag
>             String imgTag = prefix + getImgURL() + sufix;
>             add(new Label("imgDisplay", imgTag));

try:

add(new Label("imgDisplay", imgTag).setEscapeModelStrings(false));

Best regards, --- Jan.


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


Re: Dynamically generating an img tag

Posted by Jonathan Locke <jo...@gmail.com>.

you might also look at this:
http://www.codecommit.com/blog/java/a-wicket-api-for-google-charts


Cristina wrote:
> 
> Hi,
> 
> I'm trying to generate an img tag pointing to a Google chart at
> http://chart.apis.google.com/. I'm getting the chart URL as a string and I
> need to generate the img tag in order to display it as an image.
> 
> I'm trying to use a Label, like:
> 
> HTML:
> 
>             <div wicket:id="imgDisplay">img tag goes here</div>
> 
> Java:
> 
>             // prefix and sufix hold the start and end of the img tag
>             String imgTag = prefix + getImgURL() + sufix;
>             add(new Label("imgDisplay", imgTag));
> 
> Problem is, < > and " are not interpreted as markup delimiters, but as
> normal characters, so all I've got is the URL displayed as a literal where
> the image should be displayed.
> 
> Is there a simple way to do something like this?
> 
> Thanks so much,
> 
> Cristina
> 
> 

-- 
View this message in context: http://www.nabble.com/Dynamically-generating-an-img-tag-tp21190259p21190506.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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