Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add a css style property dynamically in JSF

I am using primeface for the UI components and I have to set the background of the layout unit temporary its done by using the css style,

 .layoutCustomStyle.ui-layout-unit-content
  {
     background-image: url('resources/images/backgrnd.png');
  }

The id of the layoutunit is "layoutId" and the styleclass used is "layoutCustomStyle"

in xhtml,

<p:layoutUnit position="top" id= "layoutId" styleClass ="layoutCustomStyle">
</p:layoutUnit>

But what I want is to add the background image dynamically. The image will be chosen by file browser so, I cannot add a separate class for that and use bean.

UIViewRoot view = FacesContext.getCurrentInstance().getViewRoot();
UIComponent comp= view.findComponent("layoutId");
Map<String, Object> attrMap = comp.getAttributes();
String className = (String)attrMap.get("styleClass");

using this I can set and get class names but how to change the attribute "background-image:" dynamically?

Hope the question is clear.Any help appreciated.

Thanks in advance, Pegasus

like image 605
user2632444 Avatar asked Aug 02 '13 08:08

user2632444


Video Answer


1 Answers

Use style attribute instead of styleClass.

like image 172
BalusC Avatar answered Sep 17 '22 23:09

BalusC