小编use*_*444的帖子

如何在 JSF 中动态添加 css 样式属性

我正在为 UI 组件使用primeface,我必须使用css样式临时设置布局单元的背景,

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

layoutunit 的 id 是“layoutId”,使用的样式类是“layoutCustomStyle”

在 xhtml 中,

<p:layoutUnit position="top" id= "layoutId" styleClass ="layoutCustomStyle">
</p:layoutUnit>
Run Code Online (Sandbox Code Playgroud)

但我想要的是动态添加背景图像。图像将由文件浏览器选择,因此我无法为此添加单独的类并使用 bean。

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

使用它我可以设置和获取类名,但如何动态更改属性“背景图像:”?

希望问题很清楚。感谢任何帮助。

提前致谢,飞马

css jsf primefaces

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

css ×1

jsf ×1

primefaces ×1