【问题标题】:datatable not selecting in jsf数据表未在 jsf 中选择
【发布时间】:2013-10-29 11:30:48
【问题描述】:

当我在数据表中选择一行时,它没有显示在所需的文本框字段中。我不知道是什么问题

当我在数据表中选择一行时,它没有显示在所需的文本框字段中。我不知道是什么问题

我的数据表

<p:dataTable
    var="op"
    value="#{Bean.datamodel}"
    paginator="true"
    rows="10"
    paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
    rowsPerPageTemplate="2,5,10,15"
    selectionMode="single"
    lazy="true"
    selection="#{Bean.dto}"
    id="customerSearchTable"
    emptyMessage="No Customers found with given criteria"
    resizableColumns="true"
    widgetVar="dataTab">
    <p:tooltip
        for="customerSearchTable"
        value="Select a customer to update the details" />
    <p:ajax
        event="rowSelect"
        update=":name:display" />
    <f:facet name="header">  
       Letter  of Promotion
        </f:facet>

    <p:column
        headerText=" Id"
        sortBy="#{op.id}"
        width="100"
        filterBy="#{op.id}"
        filterMatchMode="contains">
        <h:outputText value="#{op.id}" />
    </p:column>

    <p:column
        headerText="Empno"
        sortBy="#{op.empno}"
        filterBy="#{op.empno}"
        filterMatchMode="contains">
        <h:outputText value="#{op.empno}" />
    </p:column>
    <p:column
        headerText="De"
        sortBy="#{op.de}"
        filterBy="#{op.de}"
        filterMatchMode="contains">
        <h:outputText value="#{op.de}" />
    </p:column>
    <p:column
        headerText="Empname"
        sortBy="#{op.empname}"
        filterBy="#{op.empname}"
        filterMatchMode="contains">
        <h:outputText value="#{op.empname}" />
    </p:column>

    <p:column
        headerText="De"
        sortBy="#{op.de}"
        filterBy="#{op.de}"
        filterMatchMode="contains">
        <h:outputText value="#{op.de}" />
    </p:column>

    <p:column
        headerText="Lo"
        sortBy="#{op.lo}"
        filterBy="#{op.lo}"
        filterMatchMode="contains">
        <h:outputText value="#{op.lo}" />
    </p:column>


    <f:facet name="footer">
        In total there are  #{Bean.datamodel.rowCount}
    </f:facet>

数据模型

import java.io.Serializable;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

public class Datamodel extends ListDataModel<DTO> implements SelectableDataModel<DTO>, Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;


    public Datamodel(List<DTO> list) {
        super(list);
        // TODO Auto-generated constructor stub
    }

    @Override
    public DTO getRowData(String rowKey) {
        // TODO Auto-generated method stub
        @SuppressWarnings("unchecked")
        List<DTO> points = (List<DTO>)getWrappedData();
        if (rowKey != null && rowKey.trim().length() != 0 && !rowKey.equalsIgnoreCase("null")) {
            for (DTO point : points) {
                if (point.getEmpname().equals(rowKey)) {
                    return point;
                }
            }
        }
        return null;
    }

    @Override
    public Object getRowKey(DTO arg0) {
        // TODO Auto-generated method stub
        return null;
    }


}

【问题讨论】:

    标签: jsf jsf-2 primefaces datatable


    【解决方案1】:

    这个问题的解决方案是

    Datamodel 中的空构造函数

    public Datamodel() {
                super();
                // TODO Auto-generated constructor stub
            }
    

    数据模型中的返回值

    public Object getRowKey(dto point) {
                // TODO Auto-generated method stub
                return point.getid();
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-09
      • 2011-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-22
      相关资源
      最近更新 更多