Any idea why the sorting does not work?
<h:form prependId="false">
<p:dataTable value="#{questionBackingBean.questions}"
var="question" id="questionTable" paginator="true" rows="15"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="15,25,50" paginatorPosition="bottom">
<p:column sortBy="#{question.id}">
<f:facet name="header">ID</f:facet>
<h:outputText value="#{question.id}" />
</p:column>
<p:column sortBy="#{question.description}">
<f:facet name="header">Description</f:facet>
<h:outputText value="#{question.description}" />
</p:column>
</h:form>
Question entity
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Question)) {
return false;
}
Question other = (Question) obj;
if (id != other.id) {
return false;
}
return true;
}
Backing bean
@ManagedBean
@ViewScoped
public class QuestionBackingBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private QuestionLocal questionBean;
private List<Question> questions;
@Inject
private Question question;
private int questionParamId;
public List<Question> getQuestions() {
questions = questionBean.findAllQuestions();
return questions;
}
public void setQuestions(List<Question> questions) {
this.questions = questions;
}
public Question getQuestion() {
return question;
}
public void setQuestion(Question question) {
this.question = question;
}
public int getQuestionParamId() {
return questionParamId;
}
public void setQuestionParamId(int questionParamId) {
this.questionParamId = questionParamId;
}
public void init() {
question = questionBean.findQuestion(questionParamId);
}
public String addQuestion() {
questionBean.createQuestion(question);
return "../index.xhtml";
}
}