problem for datatable

UI Components for JSF
Post Reply
zsuiqiang
Posts: 146
Joined: 13 Sep 2010, 03:52

05 Sep 2011, 10:14

Code: Select all

<p:dataTable  id="table" value="#{faultTypeBean.types}" var="type" rowKey="#{type.id}" selectionMode="single" selection="#{faultTypeBean.type}">
                <p:ajax event="rowEdit" listener="#{faultTypeBean.save}"/>
						<p:column headerText="name">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{type.name}" />
								</f:facet>
								<f:facet name="input">
									<p:inputText value="#{type.name}" style="width:100%" />
								</f:facet>
							</p:cellEditor>
						</p:column>

						<p:column headerText="code">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{type.code}" />
								</f:facet>
								<f:facet name="input">
									<p:inputText value="#{type.code}" style="width:100%" />
								</f:facet>
							</p:cellEditor>
						</p:column>
						<p:column headerText="des">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{type.des}" />
								</f:facet>
								<f:facet name="input">
									<p:inputText value="#{type.des}"
										style="width:100%" />
								</f:facet>
							</p:cellEditor>
						</p:column>
						<p:column headerText="modify" style="width:30px">  
            				<p:rowEditor />  
        				</p:column>
            </p:dataTable>

Code: Select all

public class FaultType  implements java.io.Serializable {
     private Integer id;
     private String name;
     private String code;
     private String des;
    /** default constructor */
    public FaultType() {
    }
    
    /** full constructor */
    public FaultType(String name, String code, String des) {
        this.name = name;
        this.code = code;
        this.des = des;
    }

    public Integer getId() {
        return this.id;
    }
    
    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return this.code;
    }
    
    public void setCode(String code) {
        this.code = code;
    }

    public String getDes() {
        return this.des;
    }
    
    public void setDes(String des) {
        this.des = des;
    }

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		FaultType other = (FaultType) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return name;
	}
}
I get an exception :javax.faces.FacesException:
DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled.
primefaces:jakarta:12.0.0.jar,
primefaces-ext:jakarta:12.0.0.jar,
JSF Mojarra 3.0
glassfish-6.2.5,
netbeans 14
IDEA 2022.2.2
Browser: Edge

zsuiqiang
Posts: 146
Joined: 13 Sep 2010, 03:52

05 Sep 2011, 10:43

rowKey cann't be null.
primefaces:jakarta:12.0.0.jar,
primefaces-ext:jakarta:12.0.0.jar,
JSF Mojarra 3.0
glassfish-6.2.5,
netbeans 14
IDEA 2022.2.2
Browser: Edge

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 41 guests