简体   繁体   English

过滤后的数据表更新后没有更新selectBooleanCheckbox

[英]selectBooleanCheckbox not updated after filtered data table update

We have a data table with 3 columns, the first has a selectBooleanCheckbox and the two last have outputText. 我们有一个包含3列的数据表,第一列具有selectBooleanCheckbox,最后两列具有outputText。

We also set up a filter on this table to show or hide rows depending on the filter boolean value. 我们还在此表上设置了一个过滤器,以根据过滤器的布尔值显示或隐藏行。

The entity used for the data table is made with these 3 columns properties, 1 boolean, 2 String. 数据表所使用的实体由以下3列属性组成:1布尔值,2字符串。 See below. 见下文。

The problem is, when we select a filter in the first column such as "Yes" and click the update button, the table will be updated but the filter is not applied thus the table filter is not refreshed. 问题是,当我们在第一列中选​​择一个过滤器(例如“是”)并单击“更新”按钮时,该表将被更新,但未应用该过滤器,因此该表过滤器未刷新。

Step to reproduce: 复制步骤:

  1. Load the page, don't modify any checkboxes 加载页面,请勿修改任何复选框
  2. Select the filter "Yes" 选择过滤器“是”
  3. Press update button 按下更新按钮
  4. The datatable is not updated 数据表未更新

This is my Entity.java 这是我的Entity.java

public class Entity {
    boolean                 enabled;
    private String          label;
    private String          description;

    public Entity(boolean enabled, String label, String description) {
        this.enabled    = enabled;
        this.label      = label;
        this.description = description;
    }

    public boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}

This is my simple bean 这是我的简单豆

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller
@Scope ("view")
public class TestBean {
    private List<Entity>    list;

    public TestBean() {
        list = new ArrayList<Entity>();

        /* Populate examples */
        list.add(new Entity(true, "Book", "This is a C book"));
        list.add(new Entity(false, "Screen", "21\" HP Screen"));
        list.add(new Entity(true, "Game", "You won 1 million"));
    }

    /*
     * Update list, in the real application it is a little bit more complicated
     * but I simplified it and the problem is reproducible for this stuff too.
     */
    public void update() {
        Entity entity;

        /* "Disable" the third because we didn't win */
        entity = list.get(2);
        entity.setEnabled(false);
    }

    public List<Entity> getList() {
        return list;
    }

    public void setList(List<Entity> list) {
        this.list = list;
    }
}

This is my little bean for the filter boolean value 这是我的小豆作为过滤器布尔值

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

/**
 * The Class BooleanListBean.
 */
@Controller
@Scope ("session")
@SuppressWarnings ("serial")
public class BooleanListBean implements Serializable {

    /**
     * Instantiates a new boolean list bean.
     */
    public BooleanListBean() {
        super();
    }

    /**
     * Gets the options.
     * 
     * @return the options
     */
    public SelectItem[] getOptions() {
        final List<SelectItem> options = new ArrayList<SelectItem>();

        final FacesContext facesContext = FacesContext.getCurrentInstance();
        options.add(new SelectItem("", "Select"));
        options.add(new SelectItem(Boolean.FALSE.toString(), "No"));
        options.add(new SelectItem(Boolean.TRUE.toString(), "Yes"));

        return options.toArray(new SelectItem[0]);
    }
}

And finally the xhtml file 最后是xhtml文件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:fn="http://java.sun.com/jsp/jstl/functions"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ft="http://primefaces.prime.com.tr/facestrace"
    xmlns:t="http://myfaces.apache.org/tomahawk"
    xmlns:util="http://java.sun.com/jsf/composite/components/util">
<ui:composition template="/xhtml/common/toolbarLayout.xhtml">
    <ui:define name="content">
        <p:commandButton value="Update"
            actionListener="#{testBean.update}"
            update=":contentForm:entityList" />

        <p:dataTable value="#{testBean.list}" var="entity" id="entityList" widgetVar="entityList">
            <p:column headerText="Activated"
                filterBy="#{entity.enabled}" filterOptions="#{booleanListBean.options}">

                <h:selectBooleanCheckbox value="#{entity.enabled}" />
            </p:column>

            <p:column headerText="Label">
                <h:outputText value="#{entity.label}" />
            </p:column>

            <p:column headerText="Description">
                <h:outputText value="#{entity.description}" />
            </p:column>
        </p:dataTable>
    </ui:define>
</ui:composition>
</html>

I think dataTable should have filtered Value tag, 我认为dataTable应该已经过滤了Value标签,

filteredValue="#{testBean.filteredList}"

Add a filter list in testBean and refer it. 在testBean中添加一个过滤器列表并引用它。

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

相关问题 向数据库发出更新请求后,我无法在页面上获取更新的数据(数据仅在重新启动应用程序后更新) - I can not get updated data on the page after Update request to the database (data updated only after restart applications) Array 更新后更新 JcomboBox - update JcomboBox after Array is updated 提交事务后数据未更新 - Data not updated after commiting the transaction 每当更新MySQL表时更新JFrame - Update JFrame whenever MySQL table is updated 数据不一致:父表未更新,子表更新 - Data inconsistancy: Parent table is not updated while Child table is updated 如何知道数据在mysql表中被更新(即数据被删除,修改或插入),从而在java中更新json对象 - How to know that data is updated (i.e. data deleted, modified or inserted) in mysql table, so that update json object in java 在firebase中更新数据时如何更新文本视图 - How to update textviews when data is updated in firebase 仅当记录随着数据修改而更新时才更新日期 - Update date only if record updated with data modification 为什么表中的数据无法更新? - Why data in my table cannot be not updated? 从动态更新的数据表中删除元素 - Delete elements from a dynamically updated data table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM