【问题标题】:JSF change css style attribute onclickJSF 更改 css 样式属性 onclick
【发布时间】:2015-02-14 02:38:23
【问题描述】:

需要明确的是,我有一个具有特定样式的 div,当我单击该 div 内的命令按钮时,我想将显示属性设置为“无”。

我希望通过单击命令按钮来更改 css 样式。

这是我的 xhtml :

<div class="details" id="detailsPopUp" style="#{detailsPopUpManager.style}">
                <h:commandButton image="resources/images/close Icon.png" 
                                 action="#{detailsPopUpManager.closePopUp()}" 
                                 class="closeIcon"/>
</div>

这是 detailsPopUpManager 代码:

 @Named(value = "detailsPopUpManager")

 @SessionScoped

 public class DetailsPopUpManager implements Serializable {

    private String style;
    public DetailsPopUpManager() {
        style = "width:500px;\n" +
                "height:500px;\n" +
                "background: graytext;\n" +
                "position: absolute;\n" +
                "right: 25%;\n" +
                "top: 10px;\n" +
                "z-index: 1;";
    }

    public String getStyle() {
        return style;
    }

    public void setStyle(String style) {
        this.style = style;
    } 

    public void closePopUp()
    {
        style = "width:500px;\n" +
                "height:500px;\n" +
                "background: graytext;\n" +
                "position: absolute;\n" +
                "right: 25%;\n" +
                "top: 10px;\n" +
                "z-index: 1;\n" +
                "display: none;";
    }

感谢您的进一步帮助。

【问题讨论】:

    标签: css jsf onclick managed-bean


    【解决方案1】:

    您需要使用 ajax 来实现该结果。

    <h:form id="myForm">
       <div class="details" id="detailsPopUp" style="#{detailsPopUpManager.style}">
                    <h:commandButton image="resources/images/close Icon.png" 
                                     action="#{detailsPopUpManager.closePopUp()}" 
                                     class="closeIcon">
                       <f:ajax render="myForm"/>
                    </h:commandButton>
    
       </div>
    </h:form>
    

    【讨论】:

    • 感谢您的帮助。在我的帖子中使用“-1”,我想我已经问了一些非常简单的问题,但我是 jsf 的新手,不习惯 ajax。我已经阅读、理解并让自己成为这里展示的例子:mkyong.com/jsf2/jsf-2-0-ajax-hello-world-example。但我无法用 css 重现同样的东西。很抱歉占用您的时间,但您能告诉我您将如何做到这一点吗?
    • 无论我尝试做什么(基于您的代码),我总是得到一个“空 PK”。
    • 您一定是从其他地方获得了该异常。因为我的代码不能导致空 PK 异常。它与一些数据库操作有关。这段代码在我的电脑上运行良好。
    • 哦,是的,你是对的。我认为它是链接,因为只有当我单击 commandButton 时才会引发空 PK 异常。感谢您的帮助,我会检查我的代码!
    猜你喜欢
    • 2021-01-12
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    • 2014-10-12
    • 2020-12-30
    • 2014-07-07
    • 2018-10-06
    • 2012-04-25
    相关资源
    最近更新 更多