how to add a css style property dynamically in JSF

css, jsf, primefaces

Solution

Use `style` attribute instead of `styleClass`.

Problem

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

Original source