简体   繁体   English

使用h:selectBooleanCheckbox和c:if来获取a的行值 <rich:datatable> -JSF

[英]Using h:selectBooleanCheckbox with c:if to obtain row value of a <rich:datatable> - JSF

I'm using a <rich:datatable> to show the content of a List<Map<String, String> 我正在使用<rich:datatable>来显示List<Map<String, String>

In the code below, spotlightPtBindings is the List<Map<String, String> and spotlightbinding represents each Map<String, String> . 在下面的代码中, spotlightPtBindingsList<Map<String, String>spotlightbindings表示每个Map<String, String> In the first column, I'm showing one selectBooleanCheckBox for eah row. 在第一列中,我为eah行显示一个selectBooleanCheckBox When a selectBooleanCheckBox is checked, I'd like to send the value of the Map<String, String> corresponding to the key "URI" as a parameter to the method: inserirBean.onSelectedCheckBox(uri) , and that's why I put this value in a ui:param of name: uri . 当检查selectBooleanCheckBox时 ,我想将与键“ URI”相对应的Map<String, String>的值作为参数发送给方法inserirBean.onSelectedCheckBox(uri) ,这就是为什么我将此值放置在ui:name参数中: uri The problem here is that when I try to print the value uri received in inserirBean.onSelectedCheckBox(uri) , I don't get the any output, as if it is empty. 这里的问题是,当我尝试打印inserirBean.onSelectedCheckBox(uri)中接收的值uri时 ,我没有得到任何输出,好像它是空的一样。 Below there's the rest of the code: 下面是其余的代码:

InsereDocumento.xhtml InsereDocumento.xhtml

<rich:dataTable value="#{inserirBean.spotlightPtBindings}" var="spotlightbinding">

        <rich:column>
                 <f:facet name="header">*</f:facet>
                 <ui:param name="uri" value="#{spotlightbinding['URI']}"/>

                 <h:selectBooleanCheckbox value="#{selectionBean.selected}" />

                    <c:if test="#{selectionBean.selected}">
                        #{inserirBean.onSelectedCheckBox(uri)}"
                    </c:if>

             </rich:column> 

        <c:forEach items="#{inserirBean.variableNamesPt}" var="vname">
             <rich:column>
                 <f:facet name="header">#{vname}</f:facet>
                  #{spotlightbinding[vname]}
             </rich:column> 
         </c:forEach>  


     </rich:dataTable> <br />

SelectionBean 选择豆

package managedBeans;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class CheckBoxSelectionBean implements Serializable {
    private transient boolean selected = false;
    private static final long serialVersionUID = 1L;

    public CheckBoxSelectionBean() {
        // TODO Auto-generated constructor stub
    }

     public boolean isSelected() {
            return selected;
        }

        public void setSelected(boolean selected) {
            this.selected = selected;
        }

}

InserirBean - I'm not showing here how the List<Map<String, String>> named spotlightPtBinding and how the List<String> variableNamesPt were populated, because it was a complex process, but I can tell you they are certainly populated, cause I can see their content on the screen. InserirBean-我这里没有显示如何命名名为spotlightPtBindingList<Map<String, String>>以及如何填充List<String> variableNamesPt ,因为这是一个复杂的过程,但是我可以告诉您它们肯定是填充的我可以在屏幕上看到他们的内容。

@ManagedBean
public class InsereDocumentoBean implements Serializable {

    private static final long serialVersionUID = 1L;

        private List<String> variableNamesPt = new ArrayList<String>();
        private List<Map<String, String>> spotlightPtBindings = new ArrayList<Map<String, String>>();


         public List<String> getVariableNamesPt() {
        return variableNamesPt;
    }

    public List<Map<String, String>> getSpotlightPtBindings() {
        return this.spotlightPtBindings;
    }

          public void onSelectedCheckBox(String uri) {
        System.out.println("URI: " + uri);
    }
}

What may the problem be? 可能是什么问题? Thank you! 谢谢! I'm new to JSF and need your help! 我是JSF的新手,需要您的帮助!

In JSF rendering is a two-step process: there's view build time and view render time . 在JSF中,呈现过程分为两个步骤: 视图构建时间视图呈现时间 Although they're in the same file, some tags take effect at view build time, some at render time. 尽管它们在同一个文件中,但某些标记在视图构建时生效,而某些则在渲染时生效。

JSTL tags like <c:forEach> , <c:if> and all tag handlers (including <ui:param> , see here ) are evaluated at view build time, they add content to the "final" xml tree that is then rendered by JSF. <c:forEach><c:if>类的JSTL标记和所有标记处理程序 (包括<ui:param> ,请参见此处 )在视图构建时进行评估,它们将内容添加到“最终” xml树中,然后进行渲染由JSF。

JSF HTML tags and derivates like <rich:dataTable> are evaluated at view render time, so the datatable's var is evaluated later then the <ui:param> which causes spotlightbinding not to be bound when it's assigned to uri . JSF HTML标记和类似<rich:dataTable>派生类在视图渲染时进行评估,因此, 稍后将评估数据表的var然后评估<ui:param> ,这会导致将spotlightbinding绑定到uri时未绑定。

Instead, I suggest you assign an ajax listener to call the function: 相反,我建议您分配一个ajax侦听器来调用该函数:

<h:selectBooleanCheckbox value="#{selectionBean.selected}">
    <f:ajax listener="#{inserirBean.onSelectedCheckBox(spotlightbinding['URI'])}" />
</h:selectBooleanCheckbox>

Note that the listener is called whenever the value changes . 请注意,只要值更改,就会调用侦听器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用分页时,在rich:dataTable中选择的h:selectBooleanCheckbox丢失 - h:selectBooleanCheckbox being selected in rich:dataTable is lost when using Pagination 使用h:selectBooleanCheckbox删除JSF数据表中的多行 - Using h:selectBooleanCheckbox to delete multiple rows in JSF datatable DataTable中的JSF selectBooleanCheckbox值始终为false - JSF selectBooleanCheckbox value in DataTable is allways false 如何在ah:dataTable中的ah:dataTable中映射ah:selectBooleanCheckbox的值? - How to map the value of a h:selectBooleanCheckbox in a h:dataTable within a h:dataTable? JSF数据表和SelectBooleanCheckBox - JSF Datatable and SelectBooleanCheckBox 带有selectbooleancheckbox的jsf数据表 - jsf datatable with selectbooleancheckbox 如何通过使用JavaScript获得JSF selectBooleanCheckbox的值? - How to get a value of JSF selectBooleanCheckbox by using JavaScript? 如何在JSF中使用rich:dataTable显示特定行 - How to display specific row with rich:dataTable in JSF 的价值 <h:selectBooleanCheckbox> 内 <p:dataTable> 提交时仍为假 - Value of <h:selectBooleanCheckbox> inside <p:dataTable> remains false on submit 如何使用JSF的h:selectBooleanCheckbox和h:dataTable来获取选中的复选框而不提交页面内容? - How to use JSF's h:selectBooleanCheckbox with h:dataTable to get selected checkboxes without submitting the page content?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM