Conversión nativa de JSF 2.3 para enumerados en selección de tipo de

usuario.
This commit is contained in:
Marcos Garcia Nuñez
2019-12-13 02:01:31 +01:00
parent c2852718ce
commit 551e79e7e8
4 changed files with 97 additions and 119 deletions

View File

@@ -45,20 +45,22 @@
<h:form id="frmRegisterUser" rendered="#{not RegisterUser.registered}"> <h:form id="frmRegisterUser" rendered="#{not RegisterUser.registered}">
<h:outputScript> <h:outputScript>
function handleRequest(xhr, status, args) { function handleRequest(xhr, status, args) {
if(args.specs) { /*
$('#panCentros').slideUp(); if(args.specs) {
$('#panEspecialidades').slideDown(); $('#panCentros').slideUp();
} $('#panEspecialidades').slideDown();
else if (args.caps) { }
$('#panEspecialidades').slideUp(); else if (args.caps) {
$('#panCentros').slideDown(); $('#panEspecialidades').slideUp();
} else { $('#panCentros').slideDown();
$('#panCentros').slideUp(); } else if (args.pats) {
$('#panEspecialidades').slideUp(); $('#panCentros').slideUp();
} $('#panEspecialidades').slideUp();
} }
</h:outputScript> */
}
</h:outputScript>
<p:messages id="mesgs" showDetail="true" closable="true" autoupdate="true" /> <p:messages id="mesgs" showDetail="true" closable="true" autoupdate="true" />
<p:panel id="tipoUsuario" header="Especifique el tipo de usuario que desea registrarse"> <p:panel id="tipoUsuario" header="Especifique el tipo de usuario que desea registrarse">
<div class="ui-g ui-fluid"> <div class="ui-g ui-fluid">
@@ -67,12 +69,11 @@
</div> </div>
<div class="ui-g-6 ui-md-6"> <div class="ui-g-6 ui-md-6">
<p:selectOneButton id="selUsertype" value="#{RegisterUser.userType}" required="true" unselectable="false" requiredMessage="Debe especificar un tipo de usuario"> <p:selectOneButton id="selUsertype" value="#{RegisterUser.userType}" required="true" unselectable="false" requiredMessage="Debe especificar un tipo de usuario">
<f:selectItems value="#{RegisterUser.userTypes}" var="item" itemLabel="#{item.userTypename}" itemValue="#{item.name}" /> <f:selectItems value="#{RegisterUser.availableUserTypes}" var="item" itemLabel="#{item.userTypename}" />
<p:ajax listener="#{RegisterUser.onUserTypeChange}" update="DatosPersonales" oncomplete="handleRequest(xhr, status, args)" /> <p:ajax listener="#{RegisterUser.onUserTypeChange}" update="panCombos" oncomplete="handleRequest(xhr, status, args)" />
<!-- <p:ajax listener="#{RegisterUser.onUserTypeChange}" update="panEspecialidades, panCentros" oncomplete="handleRequest(xhr, status, args)" /> -->
</p:selectOneButton> </p:selectOneButton>
</div> </div>
<div class="ui-g-4 ui-md-4"></div> <div class="ui-g-4 ui-md-4" />
</div> </div>
</p:panel> </p:panel>
<br /> <br />
@@ -102,7 +103,7 @@
<p:outputLabel value="Apellidos:" for="surname" /> <p:outputLabel value="Apellidos:" for="surname" />
</div> </div>
<div class="ui-g-4 ui-md-4"> <div class="ui-g-4 ui-md-4">
<p:inputText id="surname" value="#{RegisterUser.surname}" required="true" maxlength="100" requiredMessage="Por favor, indique sus apellidos" /> <p:inputText id="surname" value="#{RegisterUser.surname}" required="true" maxlength="100" requiredMessage="Por favor, indique sus apellidos" />
</div> </div>
<div class="ui-g-6 ui-md-6"> <div class="ui-g-6 ui-md-6">
<p:message for="surname" /> <p:message for="surname" />
@@ -112,8 +113,8 @@
<p:outputLabel value="Correo electrónico:" for="email" /> <p:outputLabel value="Correo electrónico:" for="email" />
</div> </div>
<div class="ui-g-4 ui-md-4"> <div class="ui-g-4 ui-md-4">
<p:inputText id="email" value="#{RegisterUser.email}" required="true" maxlength="120" validator="emailValidator" validatorMessage="La dirección #{RegisterUser.email} no es válida" <p:inputText id="email" value="#{RegisterUser.email}" required="true" maxlength="120" validator="emailValidator"
requiredMessage="Por favor, especifique su correo electrónico"> validatorMessage="La dirección #{RegisterUser.email} no es válida" requiredMessage="Por favor, especifique su correo electrónico">
<f:validateRegex pattern="[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" /> <f:validateRegex pattern="[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
</p:inputText> </p:inputText>
</div> </div>
@@ -141,46 +142,48 @@
<p:message for="passwordRepeat" /> <p:message for="passwordRepeat" />
</div> </div>
<h:panelGroup id="panCentros" layout="block" styleClass="ui-g-12" rendered="#{RegisterUser.familyDoctor}"> <h:panelGroup id="panCombos" class="ui-g-12 nopadding" layout="block">
<div class="ui-g-2 ui-md-2"> <h:panelGroup class="ui-g-12 nopadding" layout="block" rendered="#{RegisterUser.familyDoctor}">
<p:outputLabel value="Centro:" for="selPHC" /> <div class="ui-g-2 ui-md-2">
</div> <p:outputLabel value="Centro:" for="selPHC" />
<div class="ui-g-4 ui-md-4"> </div>
<p:autoComplete id="selPHC" dropdown="true" value="#{RegisterUser.primaryHealthCareCenter}" completeMethod="#{RegisterUser.completePrimaryHealCareCenter}" var="phc" <div class="ui-g-4 ui-md-4">
itemLabel="#{phc.displayName}" itemValue="#{phc}" forceSelection="true" requiredMessage="Por favor, selecciona un nuevo centro de antención primaria"> <p:autoComplete id="selPHC" dropdown="true" value="#{RegisterUser.primaryHealthCareCenter}" completeMethod="#{RegisterUser.completePrimaryHealCareCenter}" var="phc"
<o:converter converterId="omnifaces.ListConverter" list="#{RegisterUser.phcList}" /> itemLabel="#{phc.displayName}" itemValue="#{phc}" forceSelection="true" requiredMessage="Por favor, selecciona un nuevo centro de antención primaria">
<p:column headerText="Nombre"> <o:converter converterId="omnifaces.ListConverter" list="#{RegisterUser.phcList}" />
<h:outputText value="#{phc.name}" /> <p:column headerText="Nombre">
</p:column> <h:outputText value="#{phc.name}" />
<p:column headerText="Localización"> </p:column>
<h:outputText value="#{phc.location}" /> <p:column headerText="Localización">
</p:column> <h:outputText value="#{phc.location}" />
</p:autoComplete> </p:column>
</div> </p:autoComplete>
<div class="ui-g-6 ui-md-6"> </div>
<p:message for="selPHC" /> <div class="ui-g-6 ui-md-6">
</div> <p:message for="selPHC" />
</h:panelGroup> </div>
</h:panelGroup>
<h:panelGroup id="panEspecialidades" layout="block" styleClass="ui-g-12" rendered="#{RegisterUser.specialistDoctor}"> <h:panelGroup layout="block" class="ui-g-12 nopadding" rendered="#{RegisterUser.specialistDoctor}">
<div class="ui-g-2 ui-md-2"> <div class="ui-g-2 ui-md-2">
<p:outputLabel value="Especialidad médica:" for="selMS" /> <p:outputLabel value="Especialidad médica:" for="selMS" />
</div> </div>
<div class="ui-g-4 ui-md-4"> <div class="ui-g-4 ui-md-4">
<p:autoComplete id="selMS" dropdown="true" value="#{RegisterUser.medicalSpecialty}" completeMethod="#{RegisterUser.completeMedicalSpecialty}" var="ms" <p:autoComplete id="selMS" dropdown="true" value="#{RegisterUser.medicalSpecialty}" completeMethod="#{RegisterUser.completeMedicalSpecialty}" var="ms"
itemLabel="#{ms.displayName}" itemValue="#{ms}" forceSelection="true" requiredMessage="Por favor, selecciona una especialidad médica"> itemLabel="#{ms.displayName}" itemValue="#{ms}" forceSelection="true" requiredMessage="Por favor, selecciona una especialidad médica">
<o:converter converterId="omnifaces.ListConverter" list="#{RegisterUser.medicalSpecialtiesList}" /> <o:converter converterId="omnifaces.ListConverter" list="#{RegisterUser.medicalSpecialtiesList}" />
<p:column headerText="Nombre"> <p:column headerText="Nombre">
<h:outputText value="#{ms.name}" /> <h:outputText value="#{ms.name}" />
</p:column> </p:column>
<p:column headerText="Localización"> <p:column headerText="Localización">
<h:outputText value="#{ms.description}" /> <h:outputText value="#{ms.description}" />
</p:column> </p:column>
</p:autoComplete> </p:autoComplete>
</div> </div>
<div class="ui-g-6 ui-md-6"> <div class="ui-g-6 ui-md-6">
<p:message for="selMS" /> <p:message for="selMS" />
</div> </div>
</h:panelGroup>
</h:panelGroup> </h:panelGroup>
<div class="ui-g-12 ui-g-nopad"> <div class="ui-g-12 ui-g-nopad">

View File

@@ -109,7 +109,7 @@
<p:message for="passwordRepeat" /> <p:message for="passwordRepeat" />
</div> </div>
<h:panelGroup id="panCentros" layout="block" styleClass="ui-g-12" rendered="#{UpdateProfile.userTypeFamilyDoctor}"> <h:panelGroup id="panCentros" layout="block" styleClass="ui-g-12 nopadding" rendered="#{UpdateProfile.userTypeFamilyDoctor}">
<div class="ui-g-2 ui-md-2"> <div class="ui-g-2 ui-md-2">
<p:outputLabel value="Centro de atención (CAP):" for="selPHC" /> <p:outputLabel value="Centro de atención (CAP):" for="selPHC" />
</div> </div>
@@ -130,7 +130,7 @@
</div> </div>
</h:panelGroup> </h:panelGroup>
<h:panelGroup id="panEspecialidades" layout="block" styleClass="ui-g-12" rendered="#{UpdateProfile.userTypeSpecialistDoctor}"> <h:panelGroup id="panEspecialidades" layout="block" styleClass="ui-g-12 nopadding" rendered="#{UpdateProfile.userTypeSpecialistDoctor}">
<div class="ui-g-2 ui-md-2"> <div class="ui-g-2 ui-md-2">
<p:outputLabel value="Especialidad médica:" for="selMS" /> <p:outputLabel value="Especialidad médica:" for="selMS" />
</div> </div>
@@ -151,7 +151,7 @@
</div> </div>
</h:panelGroup> </h:panelGroup>
<h:panelGroup id="panMedicosFamilia" layout="block" styleClass="ui-g-12" rendered="#{UpdateProfile.userTypePatient}"> <h:panelGroup id="panMedicosFamilia" layout="block" styleClass="ui-g-12 nopadding" rendered="#{UpdateProfile.userTypePatient}">
<div class="ui-g-2 ui-md-2"> <div class="ui-g-2 ui-md-2">
<p:outputLabel value="Médico de familia:" for="FamilyDoc" /> <p:outputLabel value="Médico de familia:" for="FamilyDoc" />
</div> </div>

View File

@@ -2,7 +2,6 @@ package managedbean.profile;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@@ -49,8 +48,8 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
private String lastUIQueryMS; private String lastUIQueryMS;
// private HashMap<String, String> userTypes; // private HashMap<String, String> userTypes;
private List<UserType> userTypes; private List<UserType> availableUserTypes;
private String userType; private UserType userType;
private PrimaryHealthCareCenterTO primaryHealthCareCenter; private PrimaryHealthCareCenterTO primaryHealthCareCenter;
private MedicalSpecialtyTO medicalSpecialty; private MedicalSpecialtyTO medicalSpecialty;
private List<MedicalSpecialtyTO> medicalSpecialitiesList; private List<MedicalSpecialtyTO> medicalSpecialitiesList;
@@ -62,26 +61,26 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
@PostConstruct @PostConstruct
public void init() { public void init() {
this.userTypes = new ArrayList<UserType>(); this.availableUserTypes = new ArrayList<UserType>();
this.userTypes.add(UserType.PATIENT); this.availableUserTypes.add(UserType.PATIENT);
this.userTypes.add(UserType.FAMILY_DOCTOR); this.availableUserTypes.add(UserType.FAMILY_DOCTOR);
this.userTypes.add(UserType.SPECIALIST_DOCTOR); this.availableUserTypes.add(UserType.SPECIALIST_DOCTOR);
this.registered = false; this.registered = false;
this.lastUIQueryPH = ""; this.lastUIQueryPH = "";
this.lastUIQueryMS = ""; this.lastUIQueryMS = "";
this.userType = UserType.PATIENT.name(); this.userType = UserType.PATIENT;
this.medicalSpecialitiesList = this.getRemoteManagerCommon().listMedicalSpecialitiesPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH); this.medicalSpecialitiesList = this.getRemoteManagerCommon().listMedicalSpecialitiesPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
this.primaryHealthCareCentersList = this.getRemoteManagerCommon().listCAPsPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH); this.primaryHealthCareCentersList = this.getRemoteManagerCommon().listCAPsPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
} }
public List<UserType> getUserTypes() { public List<UserType> getAvailableUserTypes() {
return userTypes; return availableUserTypes;
} }
public void onUserTypeChange() { public void onUserTypeChange() {
switch (UserType.valueOf(this.userType)) { switch (this.userType) {
case SPECIALIST_DOCTOR: case SPECIALIST_DOCTOR:
try { try {
PrimeFaces.current().ajax().addCallbackParam("specs", true); PrimeFaces.current().ajax().addCallbackParam("specs", true);
@@ -130,15 +129,15 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
} }
public boolean isPatient() { public boolean isPatient() {
return (UserType.valueOf(this.userType) == UserType.PATIENT); return (this.userType == UserType.PATIENT);
} }
public boolean isFamilyDoctor() { public boolean isFamilyDoctor() {
return (UserType.valueOf(this.userType) == UserType.FAMILY_DOCTOR); return (this.userType == UserType.FAMILY_DOCTOR);
} }
public boolean isSpecialistDoctor() { public boolean isSpecialistDoctor() {
return (UserType.valueOf(this.userType) == UserType.SPECIALIST_DOCTOR); return (this.userType == UserType.SPECIALIST_DOCTOR);
} }
public boolean isDoctor() { public boolean isDoctor() {
@@ -203,7 +202,7 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
if (error == 0) { if (error == 0) {
try { try {
switch (UserType.valueOf(this.userType)) { switch (this.userType) {
case PATIENT: case PATIENT:
PatientTO pat = this.getRemoteManagerProfile().registerPatient(id, nif, name, surname, password, email); PatientTO pat = this.getRemoteManagerProfile().registerPatient(id, nif, name, surname, password, email);
this.cipCode = pat.getPersonalIdentificationCode(); this.cipCode = pat.getPersonalIdentificationCode();
@@ -232,28 +231,28 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
} }
} }
public String getUserType() { public UserType getUserType() {
return userType; return userType;
} }
public void setUserType(String userType) { public void setUserType(UserType value) {
this.userType = userType; this.userType = value;
} }
public MedicalSpecialtyTO getMedicalSpecialty() { public MedicalSpecialtyTO getMedicalSpecialty() {
return medicalSpecialty; return medicalSpecialty;
} }
public void setMedicalSpecialty(MedicalSpecialtyTO medicalSpecialty) { public void setMedicalSpecialty(MedicalSpecialtyTO value) {
this.medicalSpecialty = medicalSpecialty; this.medicalSpecialty = value;
} }
public PrimaryHealthCareCenterTO getPrimaryHealthCareCenter() { public PrimaryHealthCareCenterTO getPrimaryHealthCareCenter() {
return primaryHealthCareCenter; return primaryHealthCareCenter;
} }
public void setPrimaryHealthCareCenter(PrimaryHealthCareCenterTO primaryHealthCareCenter) { public void setPrimaryHealthCareCenter(PrimaryHealthCareCenterTO value) {
this.primaryHealthCareCenter = primaryHealthCareCenter; this.primaryHealthCareCenter = value;
} }
public boolean isRegistered() { public boolean isRegistered() {

View File

@@ -2,7 +2,6 @@ package managedbean.profile;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@@ -53,7 +52,7 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
private String lastUIQueryFD; private String lastUIQueryFD;
private List<UserType> userTypes; private List<UserType> userTypes;
private String userType; private UserType userType;
private PrimaryHealthCareCenterTO primaryHealthCareCenter; private PrimaryHealthCareCenterTO primaryHealthCareCenter;
private MedicalSpecialtyTO medicalSpecialty; private MedicalSpecialtyTO medicalSpecialty;
private List<MedicalSpecialtyTO> medicalSpecialitiesList; private List<MedicalSpecialtyTO> medicalSpecialitiesList;
@@ -83,7 +82,7 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Sesión no válida", this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Sesión no válida",
"Su sesión actual no es válida, por favor cierre su sesión y vuelva a logearse en el sistema."); "Su sesión actual no es válida, por favor cierre su sesión y vuelva a logearse en el sistema.");
else { else {
this.userType = usr.getUserType().getName(); this.userType = usr.getUserType();
this.id = Integer.valueOf(usr.getId()); this.id = Integer.valueOf(usr.getId());
switch (usr.getUserType()) { switch (usr.getUserType()) {
@@ -147,29 +146,6 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
return userTypes; return userTypes;
} }
public void onUserTypeChange() {
switch (UserType.valueOf(this.userType)) {
case SPECIALIST_DOCTOR:
try {
PrimeFaces.current().ajax().addCallbackParam("specs", true);
} catch (Exception e) {
this.manageException(e);
}
break;
case FAMILY_DOCTOR:
try {
PrimeFaces.current().ajax().addCallbackParam("caps", true);
} catch (Exception e) {
this.manageException(e);
}
break;
case ADMINISTRATOR:
case PATIENT:
PrimeFaces.current().ajax().addCallbackParam("pats", true);
break;
}
}
public List<MedicalSpecialtyTO> getMedicalSpecialtiesList() { public List<MedicalSpecialtyTO> getMedicalSpecialtiesList() {
return medicalSpecialitiesList; return medicalSpecialitiesList;
} }
@@ -210,15 +186,15 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
} }
public boolean isUserTypePatient() { public boolean isUserTypePatient() {
return (UserType.valueOf(this.userType) == UserType.PATIENT); return (this.userType == UserType.PATIENT);
} }
public boolean isUserTypeFamilyDoctor() { public boolean isUserTypeFamilyDoctor() {
return (UserType.valueOf(this.userType) == UserType.FAMILY_DOCTOR); return (this.userType == UserType.FAMILY_DOCTOR);
} }
public boolean isUserTypeSpecialistDoctor() { public boolean isUserTypeSpecialistDoctor() {
return (UserType.valueOf(this.userType) == UserType.SPECIALIST_DOCTOR); return (this.userType == UserType.SPECIALIST_DOCTOR);
} }
public boolean isUserTypeDoctor() { public boolean isUserTypeDoctor() {
@@ -300,7 +276,7 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
if (error == 0) { if (error == 0) {
try { try {
switch (UserType.valueOf(this.userType)) { switch (this.userType) {
case PATIENT: case PATIENT:
PatientTO pat = this.getRemoteManagerProfile().updatePatientData(id, nif, name, surname, password, email); PatientTO pat = this.getRemoteManagerProfile().updatePatientData(id, nif, name, surname, password, email);
this.setPatientData(pat); this.setPatientData(pat);
@@ -333,12 +309,12 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
} }
} }
public String getUserType() { public UserType getUserType() {
return userType; return userType;
} }
public void setUserType(String userType) { public void setUserType(UserType value) {
this.userType = userType; this.userType = value;
} }
public MedicalSpecialtyTO getMedicalSpecialty() { public MedicalSpecialtyTO getMedicalSpecialty() {