0

3つの列を持つデータテーブルがあり、最初の列にはselectBooleanCheckboxがあり、最後の2つの列にはoutputTextがあります。

また、このテーブルにフィルターを設定して、フィルターのブール値に応じて行を表示または非表示にします。

データテーブルに使用されるエンティティは、これらの3つの列のプロパティ、1つのブール値、2つの文字列で作成されます。下記参照。

問題は、最初の列で「はい」などのフィルターを選択して更新ボタンをクリックすると、テーブルは更新されますが、フィルターが適用されないため、テーブルフィルターが更新されないことです。

再現する手順:

  1. ページをロードし、チェックボックスを変更しないでください
  2. フィルタ「はい」を選択します
  3. 更新ボタンを押す
  4. データテーブルは更新されません

これは私の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;
    }
}

これは私のシンプルな豆です

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;
    }
}

これは、フィルターブール値の私の小さなBeanです

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]);
    }
}

そして最後に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>
4

1 に答える 1

0

dataTableはValueタグをフィルタリングする必要があると思います。

filteredValue="#{testBean.filteredList}"

testBeanにフィルターリストを追加して参照します。

于 2012-10-16T14:14:46.627 に答える