Search the list, use either a resource or a servlet are the conclusion...
Like so :
package zeuzgroup.web.icons;
import org.apache.log4j.Logger;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.model.Model;
import zeuzgroup.web.application.WicketApplication;
public class Icons {
private static org.apache.log4j.Logger log =
Logger.getLogger(Icons.class);
/**
* Call this when application loads
*
* @param wicketApp
*/
public static void LoadImages() {
for (IconType iconType : IconType.values()) {
getResource(iconType);
}
}
public static ResourceReference getResource(IconType iconType) {
ResourceReference iconRef = new ResourceReference(Icons.class,
iconType.getName());
iconRef.bind(WicketApplication.get());
log.debug("binding icon to:" + iconType.getName());
return iconRef;
}
public static Image getImageForIcon(String id, IconType iconType) {
log.debug("getting image for:" + iconType.getName());
ResourceReference resource = new
ResourceReference(Icons.class,iconType.getName());
if (resource == null) {
log.error("got null resource for :" + iconType.getName()
+ " Will try to build new");
resource = getResource(iconType);
}
Image image = new Image(id, resource);
image.add(new AttributeModifier("alt", true, new Model(iconType
.getDescription())));
image.add(new AttributeModifier("title", true, new Model(iconType
.getDescription())));
return image;
}
public enum IconType {
CONCERT("kguitar.png", "Concert"), MUSIC("music.png", "Music"),
MONEY(
"money.png", "Money"), INVITATION("page_white_text.png",
"Invitation"), MONEY_ADD("money_add.png", "Money Add"), NEW(
"new.png", "New"), DOOR_OPEN("door_open.png", "Open"),
USERS(
"system-users.png", "Users"), DRINK("drink.png",
"Drink"), RAINBOW(
"rainbow.png", "Rainbow"), LINK("link.png", "Link"),
NOPICTURE("nopicture.png","No Picture");
private IconType(String name, String description) {
this.description = description;
this.name = name;
}
private String description;
private String name;
public String getDescription() {
return description;
}
public String getName() {
return this.name;
}
}
}
smallufo wrote:
Hi
I hope I can use wicket to serve image data.
I know I can extend org.apache.wicket.markup.html.image.Image and provide a
DynamicImageResource
but the generated image link is
http://localhost/app/?wicket:interface=:0:customImage::IResourceListener::
The image data is stored in the session and not bookmarkable, which is not
what I want.
I then created an ImagePage extends WebPage and override onBeforeRender() ,
and coding below :
HttpServletResponse response = ((WebResponse)
getWebRequestCycle().getResponse()).getHttpServletResponse();
try
{
response.setContentType("image/png");
OutputStream responseOutputStream = response.getOutputStream();
responseOutputStream.write(myImageBytes);
responseOutputStream.flush();
responseOutputStream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
It works !!! And I can bookmark the image.
But there are warning output :
2008-12-26 02:20:42,919 ERROR wicket.RequestCycle -
org.apache.wicket.Component has not been properly rendered. Something in the
hierarchy of foo.bar.ImagePage has not called super.onBeforeRender() in the
override of onBeforeRender() method
java.lang.IllegalStateException: org.apache.wicket.Component has not been
properly rendered. Something in the hierarchy of foo.bar.ImagePage has not
called super.onBeforeRender() in the override of onBeforeRender() method
at
org.apache.wicket.Component.internalBeforeRender(Component.java:1006)
at org.apache.wicket.Component.beforeRender(Component.java:1034)
at org.apache.wicket.Component.prepareForRender(Component.java:2160)
Is this the "standard" way of outputing binary data ?
If not , what is the better way (wicket 1.3.5) ?
thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org