0

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

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

我的数据表

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


}
4

1 回答 1

0

这个问题的解决方案是

数据模型中的空构造函数

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

数据模型中的返回值

public Object getRowKey(dto point) {
            // TODO Auto-generated method stub
            return point.getid();
        }
于 2013-11-15T05:00:37.480 回答