Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting background image dynamically in wicket application

Tags:

wicket

In my wicket application there are pages for users depending upon their role and on different criteria. In my database I am storing the path of image to be used as a background for that user. Every user has a unique page. I know I can add read image if I do something like this :

<img wicket:id="img">

and corresponding to this I am writing the code which will get image for me .

But how can I set the image as body background dynamically .I am pretty much new to wicket .Can anybody have a clue how to do that ?

like image 986
Ruby Avatar asked Jun 19 '26 09:06

Ruby


1 Answers

In your page you can do it with some header contribution:

   @Override
   public void renderHead(IHeaderResponse response) {
      super.renderHead(response);
      response.render(CssHeaderItem.forCSS("body{ background-image: url('" + getBackgroundBodyImagePath() + "');};", "uniqueBodyBackground"));
   }

Or you could assign a wicket id to your <body> element and add an AttributeModifier like this:

   @Override
   protected void onInitialize() {
      super.onInitialize();
      bodyElement.add(AttributeModifier.replace("style", "background-image: url(" + getBackgroundBodyImagePath() + \"');"));
   } 
like image 154
Robert Niestroj Avatar answered Jun 21 '26 14:06

Robert Niestroj