1 Reply Latest reply on Mar 13, 2007 3:13 PM by sergeysmirnov

    Creating references to images, with mediaOuput

    kuon

      Hello,

      What I want to do, is to generate a css in my document, with link to a couple of database stored images.

      In the init() of my page bean, I have

      for(Category c : (List<Category>)getSessionBean1().getCategoryListDataProvider().getList()) {
       pageStyle += "div.categoryLabel_"+c.getId()+" {";
       if(c.getColor() != null)
       pageStyle += "background-color:"+c.getColor();
       if(c.getIconMimeType() != null) {
       MediaOutput out = new MediaOutput();
       out.setValue(c.getId());
       out.setMimeType(c.getIconMimeType());
       out.setCacheable(false);
       out.setSession(true);
       out.setElement("img");
       out.setCreateContent(getFacesContext().getApplication().createMethodBinding("#{SessionBean1.paintCategoryIcon}", null));
       pageStyle += "background:url("+out.getUriAttribute()+") no-repeat top;";
       }
       pageStyle += "}\n";
       }


      But, getUriAttribute is null, what I totaly understand, because the component has not yet been rendered.

      But, I don't know what is the correct way to achieve this.

      the SessionBean1.paintCategoryIcon method works, and I have some a4j:mediaOutput component (created in jsp) in another page which works well.

      Best Regards

      Kuon

        • 1. Re: Creating references to images, with mediaOuput

          Ajax4jsf has more simple way how to generate images for css dynamically. It is much simpler that one you are trying to follow.
          RichFaces uses it on practice. So, you just need to look at RichFaces source code. For example, take the source for panel, look at xcss file inside the resources folder and see how the gradient is generated