Ejemplo de paginación (Listado de preguntas pendientes) con primefaces
utilizando LazyDataModel, con recarga automática de la página solicitada.
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
package ejb.medicalTest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import TO.FamilyDoctorTO;
|
||||
import TO.LoggedUserTO;
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import TO.MedicalTestTO.MedicalTestType;
|
||||
import TO.PatientTO;
|
||||
import TO.QuestionTO;
|
||||
import common.QuestionStatus;
|
||||
import common.UserType;
|
||||
import TO.QuestionTO;
|
||||
import ejb.common.CommonFacadeLocal;
|
||||
import jpa.FamilyDoctorJPA;
|
||||
import jpa.PatientJPA;
|
||||
@@ -34,10 +35,9 @@ import managedbean.common.SessionUtils;
|
||||
*/
|
||||
@Stateless
|
||||
public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
|
||||
|
||||
// Persistence Unit Context
|
||||
@PersistenceContext(unitName = "MyHealth")
|
||||
private EntityManager entman;
|
||||
EntityManager entman;
|
||||
|
||||
@EJB
|
||||
CommonFacadeLocal commonServices;
|
||||
@@ -77,13 +77,36 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
|
||||
public void answerQuestion(String question, String response) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Recuperar las preguntas sin respuesta para un médico
|
||||
*
|
||||
* @param professionalNumber
|
||||
*/
|
||||
@Override
|
||||
public void listAllPendingQuestions(int professionalNumber) {
|
||||
public List<QuestionTO> listAllPendingQuestions(int familyDoctorId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Long getPendingQuestionsCount(int familyDoctorId) {
|
||||
TypedQuery<Long> query = entman.createQuery("SELECT count(1) from QuestionJPA q where q.status=:status and q.familyDoctor.id=:docId", Long.class);
|
||||
query.setParameter("status", QuestionStatus.PENDING);
|
||||
query.setParameter("docId", familyDoctorId);
|
||||
|
||||
return query.getSingleResult();
|
||||
}
|
||||
|
||||
public List<QuestionTO> listPendingQuestionsPaged(int familyDoctorId, int pageNumber, int pageSize) {
|
||||
TypedQuery<QuestionJPA> query = entman.createQuery("SELECT q from QuestionJPA q where q.status=:status and q.familyDoctor.id=:docId order by q.title", QuestionJPA.class);
|
||||
query.setParameter("status", QuestionStatus.PENDING);
|
||||
query.setParameter("docId", familyDoctorId);
|
||||
|
||||
if (pageSize > 0) {
|
||||
query.setFirstResult(pageNumber * pageSize);
|
||||
query.setMaxResults(pageSize);
|
||||
}
|
||||
|
||||
List<QuestionJPA> allJPA = query.getResultList();
|
||||
List<QuestionTO> pendingQuestions = new ArrayList<QuestionTO>();
|
||||
|
||||
for (QuestionJPA item : allJPA) {
|
||||
pendingQuestions.add(commonServices.getPOJOforQuestionJPA(item, 1));
|
||||
}
|
||||
|
||||
return pendingQuestions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user