如何在JSF中动态添加CSS样式属性 [英] how to add a css style property dynamically in JSF

查看:690
本文介绍了如何在JSF中动态添加CSS样式属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用primface作为UI组件,我必须通过使用css样式临时设置布局单元的背景。

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

layoutunit的id是layoutId,所使用的styleclass是layoutCustomStyle xhtml中的

 < p:layoutUnit position = topid =layoutIdstyleClass =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:动态?



希望问题很清楚。非常感谢。



Pegasus

解决方案

使用 style 属性代替 styleClass


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

解决方案

Use style attribute instead of styleClass.

这篇关于如何在JSF中动态添加CSS样式属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆