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;
}
}
DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled.