h:selectBooleanCheckbox valueChangeListener 不起作用

发布于 2024-11-27 11:01:27 字数 3403 浏览 0 评论 0原文

我遇到了 h:selectBooleanCheckboxvalueChangeListener 问题。我有以下代码块:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">
    <link href="../css/profile.css" rel="stylesheet" type="text/css" />
    <link href="../css/style.css" rel="stylesheet" type="text/css" />
    <link href="../css/twt.css" rel="stylesheet" type="text/css" /> 
    <script language="JavaScript" src="../js/custom-form-elements.js"></script>
    <a4j:form id="userList">
        <a4j:outputPanel id="userListPanel" rendered="#{popupController.iIndex >= 0}">          
            <div id="listPopup_#{popupController.iIndex}" 
                style="width: 202px; height: 235px; position: absolute; right: 0%; display: none; z-index: 10000; 
                background-image: url('../images/Alert/createNewListBack.gif'); background-repeat: no-repeat;">
                <table width="180" cellpadding="0" cellspacing="0" height="100%" style="margin-top: 6px; margin-left: 10px;">
                    <a4j:repeat id="userListRepeat" value="#{popupController.userList}" rowKeyVar="i" var="listByUser">
                        <tr>
                            <td valign="middle" align="center" width="35" style="padding-left: 8px;">                               
                                <h:selectBooleanCheckbox id="listCheckbox_#{i}" name="listCheckbox_#{i}"                                                                        
                                valueChangeListener="#{popupController.addUserListMember}" immediate="true">

                            </h:selectBooleanCheckbox>
                            </td>
                            <td valign="middle" align="left" class="alertSelect" width="145">
                                <div style="width: 170px; height: auto; word-wrap: break-word; white-space: pre-wrap;">
                                    <h:outputText style="padding-right: 8px;" value="#{listByUser.name}" />                                 
                                </div>                              
                            </td>
                        </tr>                                           
                    </a4j:repeat>                   
                </table>    
            </div>          
        </a4j:outputPanel>
    </a4j:form>

</ui:composition>

PopupController 的 addUserListMember 是

public void addUserListMember(ValueChangeEvent event) throws Exception {
    System.out.println("=========================== PopupController.addUserListMember() ==================");
    Boolean isChecked = (Boolean) event.getNewValue();
    if(isChecked) {
        System.out.println("===== Checked =====");                                              
    } else {
        System.out.println("===== Un Checked =====");
    }                
}

但是 valuechangelistner 不起作用。我无法使用 this.form.submit() 因为它不适合代码。我使用的是jsf 1.2。

有什么补救办法?谢谢。

I am facing trouble with the valueChangeListener of h:selectBooleanCheckbox. I have the following code block:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">
    <link href="../css/profile.css" rel="stylesheet" type="text/css" />
    <link href="../css/style.css" rel="stylesheet" type="text/css" />
    <link href="../css/twt.css" rel="stylesheet" type="text/css" /> 
    <script language="JavaScript" src="../js/custom-form-elements.js"></script>
    <a4j:form id="userList">
        <a4j:outputPanel id="userListPanel" rendered="#{popupController.iIndex >= 0}">          
            <div id="listPopup_#{popupController.iIndex}" 
                style="width: 202px; height: 235px; position: absolute; right: 0%; display: none; z-index: 10000; 
                background-image: url('../images/Alert/createNewListBack.gif'); background-repeat: no-repeat;">
                <table width="180" cellpadding="0" cellspacing="0" height="100%" style="margin-top: 6px; margin-left: 10px;">
                    <a4j:repeat id="userListRepeat" value="#{popupController.userList}" rowKeyVar="i" var="listByUser">
                        <tr>
                            <td valign="middle" align="center" width="35" style="padding-left: 8px;">                               
                                <h:selectBooleanCheckbox id="listCheckbox_#{i}" name="listCheckbox_#{i}"                                                                        
                                valueChangeListener="#{popupController.addUserListMember}" immediate="true">

                            </h:selectBooleanCheckbox>
                            </td>
                            <td valign="middle" align="left" class="alertSelect" width="145">
                                <div style="width: 170px; height: auto; word-wrap: break-word; white-space: pre-wrap;">
                                    <h:outputText style="padding-right: 8px;" value="#{listByUser.name}" />                                 
                                </div>                              
                            </td>
                        </tr>                                           
                    </a4j:repeat>                   
                </table>    
            </div>          
        </a4j:outputPanel>
    </a4j:form>

</ui:composition>

And the addUserListMember of PopupController is

public void addUserListMember(ValueChangeEvent event) throws Exception {
    System.out.println("=========================== PopupController.addUserListMember() ==================");
    Boolean isChecked = (Boolean) event.getNewValue();
    if(isChecked) {
        System.out.println("===== Checked =====");                                              
    } else {
        System.out.println("===== Un Checked =====");
    }                
}

But the valuechangelistner is not working. I can't use this.form.submit() because it will not fit into the code. I am in jsf 1.2.

What is the remedy? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深居我梦 2024-12-04 11:01:27

valueChangeListener 不是客户端事件/发生的事件。它完全是服务器端的。在更改值后,您确实应该将表单提交到服务器端,以便调用它。

由于您显然已经在使用 Ajax4jsf,因此您只需添加 <代码>

<h:selectBooleanCheckbox ...>
    <a4j:support event="onclick" reRender="someOtherComponentIfNecessary" />
</h:selectBooleanCheckbox>

The valueChangeListener is not a client side event/happening. It's fully server side. You should really submit the form to the server side after you change the value in order to get it invoked.

As you're apparently already using Ajax4jsf, you could just add an <a4j:support>.

<h:selectBooleanCheckbox ...>
    <a4j:support event="onclick" reRender="someOtherComponentIfNecessary" />
</h:selectBooleanCheckbox>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文