我使用primeface的UI组件,我必须设置布局部临时使用的CSS样式它做的背景下,如何添加CSS样式属性动态地在JSF
.layoutCustomStyle.ui-layout-unit-content
{
background-image: url('resources/images/backgrnd.png');
}
的ID该layoutunit的是“layoutId”和所用的styleClass是“layoutCustomStyle”
在XHTML中,
<p:layoutUnit position="top" id= "layoutId" styleClass ="layoutCustomStyle">
</p:layoutUnit>
但我要的是动态地添加背景图像。图像将由文件浏览器选择,所以我不能为此添加单独的类并使用bean。
UIViewRoot view = FacesContext.getCurrentInstance().getViewRoot();
UIComponent comp= view.findComponent("layoutId");
Map<String, Object> attrMap = comp.getAttributes();
String className = (String)attrMap.get("styleClass");
使用此我可以设置和获取类名,但如何更改属性“background-image:”动态?
希望这个问题是明确的。任何帮助表示赞赏。
由于提前, 飞马
动态的意思是什么事情你想改变背景??你使用任何Bean类?我告诉我,然后我会为你提供代码。 –
有一个文件浏览器,所选图像应设置为背景。是的,我正在使用bean class.I使用primeface fileupload组件来选择图像文件。 – user2632444