JSF page jumps to a new page after using the ajax filter method and fails to bind the current object - jsf

When I don't use filter from the search area.
After I clicked zoom icon. It runs as normal.
But when I use filter from the search area.
Search area of customer details always returns first data of datatable
This is part of my codes related to search area of customer list
licenseholder.xhtml
<p:commandButton process="#this"
title="Details"
icon="fa button-icon-color icon-search"
action="#{licenseHolderAdmin.doShowDetails()}">
<f:setPropertyActionListener value="#{serviceCustomer}" target="#{licenseHolderAdmin.holderCurrent}" />
<f:setPropertyActionListener value="0" target="#{licenseHolderAdmin.activeTab}" />
</p:commandButton>
LicenseholderAdmin.java
public String doShowDetails() {
if (updateCurrentHolder) {
this.getHolderCurrent();
}
setSelectedLicenses(new ArrayList<License>());
return "licenseholderdetails";
}
public LicenseHolder getHolderCurrent() {
if (updateCurrentHolder) {
if (holderCurrent != null
&& holderCurrent.getCustomerId() != null) {
holderCurrent = customerDao.update(holderCurrent);
}
updateCurrentHolder = false;
}
return holderCurrent;
}
CustomerDao.java
#Override
public LicenseHolder findById(long id) {
try {
Query query = em.createQuery("select distinct lh from LicenseHolder lh where customerId = :id");
Integer intId = (int) id;
query.setParameter("id", intId);
return (LicenseHolder) query.getSingleResult();
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Datensatz konnte nicht gefunden werden.", "ID=" + id));
LOGGER.error("Error while retrieving single customer.");
return null;
}
}
public LicenseHolder update(LicenseHolder customer) {
return findById(customer.getCustomerId());
}
This is part of my codes related to Search area of customer details
licenseholder-details.xhtml
<p:selectOneMenu class="dropdown" value="#{licenseHolderAdmin.holderCurrent}" converter="licenseHolderConverter" >
<f:selectItems value="#{licenseHolderAdmin.getServiceCustomers()}" var="customer"
itemLabel="#{customer.company} (#{customer.customberNumber})" itemValue="#{customer}" />
<p:ajax event="change" oncomplete="switchToCustomer()" process="#form" />
</p:selectOneMenu>
LicenseHolderAdmin.java
public List<LicenseHolder> getServiceCustomers() {
return getHolders();
}
public List<LicenseHolder> getHolders() {
if (holders == null || updateHolderList) {
holders = customerDao.getAllCustomers();
updateHolderList = false;
}
return holders;
}
CustomerDao.java
public List<LicenseHolder> getAllCustomers() {
List<LicenseHolder> holders = null;
try {
Query query = em.createQuery("select distinct lh from LicenseHolder lh order by COMPANY");
holders = query.getResultList();
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Datensätze konnte nicht geladen werden.", ""));
LOGGER.error("Error while retrieving all customers.");
}
return holders;
}
I have tried f:selectItems to set itemValue="#{customer.customberNumber}". Result doesn't change.
I have also tried f:selectItems to set value="#{licenseHolderAdmin.getHolder(Long id). But I will lost function of query of dropdown. For example.
I am unfamiliar with JSF. Any advice will be grateful!

Related

SelectOneRadio returns always 0

I am developing a web application with JSF and EJB 3.1, I want to retrieve a value from a selectOneRadio :
<p:selectOneRadio id="noteItem" value="#{entretienController.val1}">
<f:selectItem itemLabel="0" itemValue="0"/>
itemLabel="1" itemValue="1"/>
<f:selectItem itemLabel="2" itemValue="2"/>
<f:selectItem itemLabel="3" itemValue="3"/>
<f:selectItem itemLabel="4" itemValue="4"/>
<p:ajax process="#this" update="noteItem"/>
</p:selectOneRadio>
<p:commandButton process="entretienAnnuelDAPanel" action="#{noteEntretienController.testPersist()}"
/>
testPersist method :
public void testPersist() {
System.out.println("entrée dans la méthode testPersist");
try {
getFacade().saveListeNoteEntretien();
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("finally !!!!!");
}
}
saveListeNoteEntretien method :
public void saveListeNoteEntretien() {
List<NoteEntretien> listNoteEntretien = new ArrayList<>();
try {
Collaborateur collaborateur = collaborateurFacade.find(1);
List<Competence> competences = null;
Competence competence = new Competence();
competences = competenceFacade.findAll();
Integer maxIdEntretien = (Integer) em.createQuery("SELECT MAX(e.idEntretien) from Entretien
e").getSingleResult();
Entretien entretien = new Entretien(maxIdEntretien + 1);
entretien.setDateEntretien(new Date());
entretien.setDiagnosticEntretien(entretienController.getDiagItem());
entretien.setObservationsEntretien(entretienController.getObsItem());
entretien.setIdCollaborateur(collaborateurController.getSelected());
em.persist(entretien);
for (int i = 0; i < 24; i++) {
Integer maxIdNoteEntretien = (Integer) em.createQuery("SELECT MAX(n.idNoteEntretien) from
NoteEntretien n").getSingleResult();
NoteEntretien noteEntretien = new NoteEntretien(maxIdNoteEntretien + 1);
noteEntretien.setIdCollaborateur(collaborateurController.getSelected());
noteEntretien.setIdCompetence(competences.get(i));
noteEntretien.setIdEntretien(entretien);
try {
System.out.println(entretienController.getVal1());
noteEntretien.setValNoteEntretien((float)entretienController.getVal1());
} catch (Exception e) {
e.printStackTrace();
}
em.persist(noteEntretien);
listNoteEntretien.add(noteEntretien);
}
} catch (EJBException e) {
#SuppressWarnings("ThrowableResultIgnored")
Exception cause = e.getCausedByException();
if (cause instanceof ConstraintViolationException) {
#SuppressWarnings("ThrowableResultIgnored")
ConstraintViolationException cve = (ConstraintViolationException)
e.getCausedByException();
for (Iterator<ConstraintViolation<?>> it = cve.getConstraintViolations().iterator();
it.hasNext();) {
ConstraintViolation<? extends Object> v = it.next();
System.err.println(v);
System.err.println("==>>" + v.getMessage());
}
}
System.err.println("ejb exception ! ! ! ! !");
} finally {
System.out.println("persistence OK !!!!!!!");
}
}
The value retrieved is always set to 0 even if I select 1, 2, 3 or 4.
I tried a simple inputText and parse it to float on the defined method, then could get the proper value :
<h3 style="width: 150px">Note</h3>
<p:inputText id="noteItem" value="#{entretienController.val1}">
<p:ajax update="noteItem"/>
</p:inputText>
UPDATE :
I also tried a spinner and it works perfectly. The issue is just with the selectOneRadio
<p:outputLabel
value="#
{bundle.Personnel_Aptitudes_Communication_Ecrite}"
style="font-weight:bold"/>
<p:spinner id="noteItem" value="#
{entretienController.val1}">
<p:ajax update="noteItem"></p:ajax>
</p:spinner>
Does anyone have the possibility to help me on that ?
Thank you !

Issue in setting values in p:organigram

Hi i am facing problem in setting values in organigram primeFaces.
I want to show reporting to employees, all things are working perfect but the issue only i am facing is that parent nodes are repeating, according to number of childs.
so please suggest me any best way to handle it.
Here is Model:
public TreeMap<String, String> getALLEmployees(OrganigramView ob) {
ConnectionHandler conHandler = ConnectionHandler.getConnectionHandler();
Connection con = conHandler.getConnection();
Statement stmt = null;
ArrayList<OrganigramView> list = new ArrayList();
OrganigramView obs;
TreeMap<String, String> tm = new TreeMap<String, String>();
try {
stmt = con.createStatement();
String selectQry = "select emp.* ,emp.Name as reportingName,ejd.`REPORTING_BOSS_ID`,emp2.`NAME` as reportToBy, emp.`EMPLOYEE_ID` as empID\n"
+ "from employee emp \n"
+ "JOIN employee_job_detail ejd ON ejd.`EMPLOYEE_ID` = emp.`EMPLOYEE_ID`\n"
+ "JOIN employee emp2 ON emp2.`EMPLOYEE_ID` = ejd.`REPORTING_BOSS_ID` \n"
+ " WHERE emp.COMPANY_ID = 4 and emp.`PROFILE_STATUS` = 1 ";
System.out.println("selectQry : " + selectQry);
ResultSet rs = stmt.executeQuery(selectQry);
while (rs.next()) {
tm.put( rs.getString("Name"),rs.getString("reportToBy") );
System.out.println(tm.size());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (stmt != null) {
stmt.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
conHandler.freeConnection(con);
}
return tm;
}
Here is Bean:
protected OrganigramNode addDivision(OrganigramNode parent, String name, String... employees) {
OrganigramNode divisionNode = new DefaultOrganigramNode("division", name, parent);
divisionNode.setDroppable(true);
divisionNode.setDraggable(true);
divisionNode.setSelectable(true);
if (employees != null) {
for (String employee : employees) {
OrganigramNode employeeNode = new DefaultOrganigramNode("employee", employee, divisionNode);
employeeNode.setDraggable(true);
employeeNode.setSelectable(true);
}
}
return divisionNode;
}
Here is XHTML
<p:organigram id="organigram"
widgetVar="organigram"
value="#{organigramView.rootNode}"
var="node"
>
<p:ajax event="dragdrop" process="#this" update="#form:growl" listener="#{organigramView.nodeDragDropListener}" />
<p:ajax event="select" process="#this" update="#form:growl" listener="#{organigramView.nodeSelectListener}" />
<p:ajax event="contextmenu" process="#this" />
<p:ajax event="collapse" process="#this" update="#form:growl" listener="#{organigramView.nodeCollapseListener}" />
<p:ajax event="expand" process="#this" update="#form:growl" listener="#{organigramView.nodeExpandListener}" />
<p:organigramNode>
<h:outputText value="#{node.data}" />
</p:organigramNode>
<p:organigramNode type="root"
style="border-radius: 10px;">
<h:outputText value="#{node.data}" />
</p:organigramNode>
<p:organigramNode type="division"
styleClass="division"
icon="pi pi-briefcase"
iconPos="left">
<h:outputText value="#{node.data}" />
</p:organigramNode>
<p:organigramNode type="employee"
styleClass="employee"
icon="pi pi-user">
<h:outputText value="#{node.data}" />
</p:organigramNode>
</p:organigram>
Again i am repeating that all things are working perfect but only parent nodes are repeating, according to number of child nodes, but i want that one parent and there child should be shown.
EXPECTED:
OUT PUT

JSF page redirect inside property getter

I have a JSF 2 application that retrieves data from the database and displays it on a page.
I have a property get method called "getCurrentPage" which will display the database data. Inside this method if no data exists for the specified page, I want to redirect to a 404 page.
I tried
FacesContext.getCurrentInstance().getExternalContext().redirect("404.xhtml");
but I get a java.lang.IllegalStateException.
How to I redirect?
Here is my XHTML snippet
<h:panelGroup layout="block">
<h:outputText escape="false" value="#{common.currentPage.cmsPageBody}"/>
</h:panelGroup>
Here is my bean snippet
public CmsPage getCurrentPage() {
HttpServletRequest request = (HttpServletRequest) (FacesContext.getCurrentInstance().getExternalContext().getRequest());
try {
String requestUrl = (String) request.getAttribute("javax.servlet.forward.request_uri");
if (this.currentCmsPage == null) {
// Page not found. Default to the home page.
this.currentCmsPage = cmsPageBL.getCmsPage("/en/index.html", websiteId);
} else {
this.currentCmsPage = cmsPageBL.getCmsPage(requestUrl, websiteId);
}
if (this.currentCmsPage == null) {
FacesContext.getCurrentInstance().getExternalContext().redirect("404.xhtml");
}
}
} catch (Exception ex) {
log.error("getCurrentPage Exception: ", ex);
}
return currentCmsPage;
}
}
Thou should not perform business logic in getter methods. It's only recipe for trouble in all colors. Getter methods are supposed to solely return already-prepared properties. Just use a pre render view event listener instead.
E.g.
<f:event type="preRenderView" listener="#{common.initCurrentPage}" />
<h:panelGroup layout="block">
<h:outputText escape="false" value="#{common.currentPage.cmsPageBody}"/>
</h:panelGroup>
with
public void initCurrentPage() throws IOException {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
String requestUrl = (String) ec.getRequestMap().get(RequestDispatcher.FORWARD_REQUEST_URI);
if (currentCmsPage == null) {
// Page not found. Default to the home page.
currentCmsPage = cmsPageBL.getCmsPage("/en/index.html", websiteId);
} else {
currentCmsPage = cmsPageBL.getCmsPage(requestUrl, websiteId);
}
if (currentCmsPage == null) {
ec.redirect(ec.getRequestContextPath() + "/404.xhtml");
}
}
public CmsPage getCurrentPage() {
return currentCmsPage;
}
Note that I also improved some poor logic.

Bean method not called unless I remove Rendered attribute in p:commandButton in p:dataTable

I can only get my actionListener to fire if I remove my "rendered" attribute on my p:commandButton in my data table. Not sure what the problem is.
Page Code:
<ui:define name="content">
<H1>Manage Delegates</H1>
<P>In order to raise requests on behalf of other users in the system, and to be able to access, attach and update
personal information such as travel details and credit card details, you must be authorised to act on the users
behalf.</P>
<P>Please use the button below to as a user for their permission to act on their behalf within the Admin Direct
system.</P>
<h:form id="delegateForm">
<h:messages id="generalMessages"></h:messages>
<p:growl id="messages"></p:growl>
<H1>Your Delegate Requests (The users you can act on behalf of in Admin Direct)</H1>
<P>The following list represents the users you have requested to be a delegate form, and the status of those requests. You will be able to create tasks and edit the personal details of these users if your request has been Approved, and if they have authorised you to (1) create tasks for them in the system, and (2) edit their personal details.</P>
<P>If you wish to act on behalf of someone else within Admin Direct, please request delegate access using the "Request Delegate" button below. You can monitor the status of the request from here, but will also receive email confirmation once a response (Approve/Reject) has been received within the system.</P>
<P>Once a request has been approved, you will be able to select that user when creating tasks to indicate that the task is being created for someone else, but you will be able to specify that you are the primary contact during the tasks processing.</P>
<p:commandButton id="createDelegateRequest" value="Request Delegate Access" onclick="peopleDlg.show();" type="button" />
<P/>
<p:dataTable id="sentRequests" rowKey="#{sentRequest.id}" var="sentRequest"
value="#{delegateBean.user.delegateRequestsRaisedBy}">
<p:column headerText="Request Sent" style="width:100px">
<h:outputText value="#{sentRequest.createdDate}" />
</p:column>
<p:column headerText="Delegate" style="width:200px">
<h:outputText value="#{sentRequest.adminDirectUser.fullName}" />
</p:column>
<p:column headerText="Request Status" style="width:100px">
<h:outputText value="#{sentRequest.delegateRequestStatus.status}" />
</p:column>
<p:column headerText="Response Date" style="width:100px">
<h:outputText value="#{sentRequest.responseDate}" />
</p:column>
<p:column headerText="Can Raise Requests" style="width:100px">
<p:selectBooleanCheckbox value="#{sentRequest.canRaiseTasks}" disabled="true"/>
</p:column>
<p:column headerText="Can Edit Personal Details" style="width:100px">
<p:selectBooleanCheckbox value="#{sentRequest.canEditPersonalDetails}" disabled="true" />
</p:column>
<p:column headerText="Resend Email" style="width:100px">
<p:commandButton
id="resendRequest"
rendered="#{delegateBean.requestIsPending(sentRequest) or delegateBean.requestIsRejected(sentRequest)}"
value="Resend Request"
immediate="true"
process="#this"
update="#all"
actionListener="#{delegateBean.resendRequest(sentRequest)}" />
</p:column>
<p:column headerText="Delete Delegate" style="width:100px">
<p:commandButton
actionListener="#{delegateBean.deleteDelegateRequest(sentRequest)}"
value="Delete Delegate"
immediate="true"
process="#this"
update="#all" />
</p:column>
</p:dataTable>
<P/>
<P/>
<P/>
<H1>Your Designated Delegates (The people who can currently act on your behalf within Admin Direct)</H1>
<P>Any requests marked as "Approved", are employees you have authorised to act on your behalf within Admin Direct. Below you can see who is able to act on your behalf, and the permissions you have granted to these users.</P>
<P>Any requests marked "Pending", are outstanding requests which you can either Approve or Reject directly using the links provided</P>
<P>You can remove a delegate completely from the list below to prevent them from performing any actions on your behalf, or you can adjust the permissions that you have granted individuals by ticking/unticking the relevant boxes against each user.</P>
</h:form>
<p:dialog id="peopleDialog" widgetVar="peopleDlg" appendToBody="true">
<h:form id="pdSearch2">
<ps:personSearch searchButtonLabel="Find Users" searchFieldLabel="Surname: " rows="8" pagination="true" />
<p:commandButton value="Add User"
actionListener="#{delegateBean.raiseDelegateRequest(personSearchBean.selectedPerson)}"
update=":delegateForm :messagesDialogForm" oncomplete="handleAddToRoleComplete(xhr, status, args)" />
</h:form>
</p:dialog>
<p:dialog header="Admin Direct Message" widgetVar="messagesDialog" modal="true" closable="false" closeOnEscape="true"
resizable="false" height="150" width="300" appendToBody="true">
<h:form id="messagesDialogForm">
<h:outputText id="dialogMessage" value="#{delegateBean.dialogMessage}" style="text-align:centre;" />
<p />
<div style="text-align: center;">
<p:commandButton value="Close" onclick="messagesDialog.hide();"></p:commandButton>
</div>
</h:form>
</p:dialog>
<script type="text/javascript">
function handleAddToRoleComplete(xhr, status, args) {
if (args.error == true) {
messagesDialog.show();
}
}
</script>
</ui:define>
</ui:composition>
The offending item is here:
<p:column headerText="Resend Email" style="width:100px">
<p:commandButton
id="resendRequest"
rendered="#{delegateBean.requestIsPending(sentRequest) or delegateBean.requestIsRejected(sentRequest)}"
value="Resend Request"
immediate="true"
process="#this"
update="#all"
actionListener="#{delegateBean.resendRequest(sentRequest)}" />
</p:column>
my backing bean looks like this:
#ManagedBean
#ViewScoped
public class DelegateBean {
#ManagedProperty("#{sendMailBean}")
private SendMailBean sendMailBean;
private String dialogMessage = null;
private PersonSearchBean personSearchBean = null;
private UserSessionBean userSessionBean = null;
private AdminDirectUser sessionUser = null;
private DelegateRequestStatus pendingStatus = null;
private DelegateRequestStatus approvedStatus = null;
private DelegateRequestStatus rejectedStatus = null;
#PostConstruct
public void init() {
HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
.getRequest();
userSessionBean = (UserSessionBean) req.getSession().getAttribute("userSessionBean");
sessionUser = userSessionBean.getCurrentUser();
}
public void raiseDelegateRequest(PeopleServicePerson peopleServicePerson) {
AdminDirectUser requester = this.getUser(); // fresh database pull
RequestContext context = RequestContext.getCurrentInstance();
if (requester == null) {
context.addCallbackParam("error", true); // basic parameter
dialogMessage = "An issue occured locating your account details.";
setErrorMessage(dialogMessage);
return;
}
String server = FacesContext.getCurrentInstance().getExternalContext().getRequestServerName();
int port = FacesContext.getCurrentInstance().getExternalContext().getRequestServerPort();
String app = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
if (peopleServicePerson == null) {
context.addCallbackParam("error", true); // basic parameter
dialogMessage = "An issue occured, the person you tried to select appears to be null.";
setErrorMessage(dialogMessage);
return;
}
AdminDirectUser adUser = getAdUser(peopleServicePerson);
if (adUser == null) {
context.addCallbackParam("error", true); // basic parameter
dialogMessage = "An issue occured, unable to locate the person in the people directory.";
setErrorMessage(dialogMessage);
return;
}
// if we get this far we can raise the request, but we need to check if
// we already have a request for this person
List<DelegateRequest> requestsRaised = requester.getDelegateRequestsRaisedBy();
if (requestsRaised != null && !requestsRaised.isEmpty()) {
// do we already have a request for this user
for (DelegateRequest request : requestsRaised) {
if (request.getAdminDirectUser().equals(adUser)) {
// we have already raised a request for this user
context.addCallbackParam("error", true); // basic parameter
dialogMessage = "You have already raised a request for this user,"
+ adUser.getFullName()
+ ". If you need to resend the existing request please use 'Resend Request option in you existing requests list.";
setErrorMessage(dialogMessage);
return;
}
}
}
// if we get this far, we have an adUser persisted in the database who
// we have yet to raise a request for
// so we can raise the request
DelegateRequest request = new DelegateRequest();
request.setCanRaiseTasks(false);
request.setDelegateRequestStatus(this.getPendingStatus());
request.setCreatedDate(new Date());
request.setRaisedBy(requester);
request.setAdminDirectUser(adUser);
requester.getDelegateRequestsRaisedBy().add(request);
request.persist();
requester.merge();
String url = "http://" + server + ":" + port + app + "/pages/customer/delegateResponseForm.jsf?requestId="
+ request.getId();
System.out.println("url " + url);
sendMailBean.sendDelegateRequest(request);
setMessage("Request for delegate access has been sent to " + adUser.getFullName());
}
private AdminDirectUser getAdUser(PeopleServicePerson peopleServicePerson) {
// Here we need to check if the user exists as an Admin Direct user
// already.
// If so then we just need to return that user.
// If not, then we need to get a full response from the people search
// service, and create a new Admin Direct User
// with the people search details used to do an initial population
// and return the persisted Admin Direct User
AdminDirectUser adUser = null;
if (peopleServicePerson != null) {
adUser = AdminDirectUser.findAdminDirectUserByPrid(peopleServicePerson.getPrid().toLowerCase().trim());
if (adUser == null) {
// Create a new AdminDirectUser instance
adUser = new AdminDirectUser();
// and get a handle on all the details from the people search
// person
PeopleServicePerson fullServicePerson = personSearchBean.findPersonFull(peopleServicePerson.getPrid()
.toLowerCase().trim());
if (fullServicePerson != null) {
adUser.setFirstName(fullServicePerson.getFirstName());
adUser.setLastName(fullServicePerson.getLastName());
adUser.setCostCentre(fullServicePerson.getCostCentre());
adUser.setDeskLocation(fullServicePerson.getRoom());
adUser.setTelephone(fullServicePerson.getOfficePhone());
adUser.setManager(fullServicePerson.getManager());
adUser.setLogonId(fullServicePerson.getPrid());
adUser.setPrid(fullServicePerson.getPrid());
adUser.setEmail(fullServicePerson.getEmail());
adUser.setEmployeeNumber(fullServicePerson.getEmployeeNumber());
adUser.persist();
}
}
}
return adUser;
}
public boolean requestIsPending(DelegateRequest request) {
// is the request passed in in pending status
System.out.println("request id: " + request.getId() + " isPending = " + request.getDelegateRequestStatus().equals(this.getPendingStatus()));
return request.getDelegateRequestStatus().equals(this.getPendingStatus());
}
public boolean requestIsRejected(DelegateRequest request) {
// is the request passed in in pending status
System.out.println("request id: " + request.getId() + " isRejected = " + request.getDelegateRequestStatus().equals(this.getRejectedStatus()));
return request.getDelegateRequestStatus().equals(this.getRejectedStatus());
}
public void abc() {
System.out.println("abc");
}
public void resendRequest(DelegateRequest request) {
AdminDirectUser requester = this.getUser(); // fresh database pull
System.out.println("Resending request");
RequestContext context = RequestContext.getCurrentInstance();
if (requester == null) {
context.addCallbackParam("error", true); // basic parameter
dialogMessage = "An issue occured locating your account details.";
setErrorMessage(dialogMessage);
return;
}
String server = FacesContext.getCurrentInstance().getExternalContext().getRequestServerName();
int port = FacesContext.getCurrentInstance().getExternalContext().getRequestServerPort();
String app = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
AdminDirectUser adUser = request.getAdminDirectUser();
if (adUser == null) {
context.addCallbackParam("error", true); // basic parameter
dialogMessage = "An issue occured, unable to locate the person within Admin Direct.";
setErrorMessage(dialogMessage);
return;
}
request.setDelegateRequestStatus(this.getPendingStatus());
request.persist();
String url = "http://" + server + ":" + port + app + "/pages/customer/delegateResponseForm.jsf?requestId="
+ request.getId();
System.out.println("url " + url);
sendMailBean.sendDelegateRequest(request);
setMessage("Request for delegate access has been re-sent to " + adUser.getFullName());
}
private void setMessage(String strMessage) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(strMessage));
}
private void setErrorMessage(String errorMessage) {
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, null));
}
public String getDialogMessage() {
return dialogMessage;
}
public void setDialogMessage(String dialogMessage) {
this.dialogMessage = dialogMessage;
}
public AdminDirectUser getSessionUser() {
return sessionUser;
}
public AdminDirectUser getUser() {
AdminDirectUser adUser = null;
if (sessionUser != null) {
adUser = AdminDirectUser.findAdminDirectUser(sessionUser.getId());
}
return adUser;
}
public DelegateRequestStatus getPendingStatus() {
if (pendingStatus != null) {
return pendingStatus;
} else {
for (DelegateRequestStatus status : DelegateRequestStatus.findAllDelegateRequestStatuses()) {
if (status.getStatus().equals(DelegateRequestStatusList.PENDING.toString())) {
pendingStatus = status;
}
}
}
return pendingStatus;
}
public DelegateRequestStatus getApprovedStatus() {
if (approvedStatus != null) {
return approvedStatus;
} else {
for (DelegateRequestStatus status : DelegateRequestStatus.findAllDelegateRequestStatuses()) {
if (status.getStatus().equals(DelegateRequestStatusList.APPROVED.toString())) {
approvedStatus = status;
}
}
}
return approvedStatus;
}
public DelegateRequestStatus getRejectedStatus() {
if (rejectedStatus != null) {
return rejectedStatus;
} else {
for (DelegateRequestStatus status : DelegateRequestStatus.findAllDelegateRequestStatuses()) {
if (status.getStatus().equals(DelegateRequestStatusList.REJECTED.toString())) {
rejectedStatus = status;
}
}
}
return rejectedStatus;
}
public SendMailBean getSendMailBean() {
return sendMailBean;
}
public void setSendMailBean(SendMailBean sendMailBean) {
this.sendMailBean = sendMailBean;
}
}
This is the code which never gets called unless I remove the rendered attribute:
public void resendRequest(DelegateRequest request) {
AdminDirectUser requester = this.getUser(); // fresh database pull
System.out.println("Resending request");
RequestContext context = RequestContext.getCurrentInstance();
if (requester == null) {
context.addCallbackParam("error", true); // basic parameter
dialogMessage = "An issue occured locating your account details.";
setErrorMessage(dialogMessage);
return;
}
String server = FacesContext.getCurrentInstance().getExternalContext().getRequestServerName();
int port = FacesContext.getCurrentInstance().getExternalContext().getRequestServerPort();
String app = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
AdminDirectUser adUser = request.getAdminDirectUser();
if (adUser == null) {
context.addCallbackParam("error", true); // basic parameter
dialogMessage = "An issue occured, unable to locate the person within Admin Direct.";
setErrorMessage(dialogMessage);
return;
}
request.setDelegateRequestStatus(this.getPendingStatus());
request.persist();
String url = "http://" + server + ":" + port + app + "/pages/customer/delegateResponseForm.jsf?requestId="
+ request.getId();
System.out.println("url " + url);
sendMailBean.sendDelegateRequest(request);
setMessage("Request for delegate access has been re-sent to " + adUser.getFullName());
}
Any advice appreciated.
Regards
Stephen

How can I retrieve the item that the user selected from the drop down? in jsf

My question is how can i retrieve selected item in backing bean ?
In my view page i have one select box component :
<h:selectOneMenu id="materialCat"
value="#
{materialMasterBean.materialDTOs.materialCategoryId}" required="true" requiredMessage="Material Category is Mandatory">
<f:selectItem itemLabel="select" itemValue="-1" />
<f:selectItems value="#{materialMasterBean.materialCatList}" />
</h:selectOneMenu>
This is my backing bean
` public ArrayList getMaterialCatList() {
if(materialCatList == null )
{
materialCatList= new ArrayList<SelectItem>();
ArrayList<MaterialDTO> temp;
try {
temp= getAdminDelegate().getMaterialLsit();
for (int i = 0; i < temp.size(); i++)
{
MaterialDTO materialDTO = temp.get(i);
item = new SelectItem(materialDTO.getMaterialCategoryId(),materialDTO.getMaterialCategory());
materialCatList.add(item);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return materialCatList;
}
else
{
return materialCatList;
}
}
`
also in backing Bean i have:
private MaterialDTO materialDTOs;
please help me
you can access it in your bean if you binded it with the value="#{bean.filed} attribute
EDIT: here is an example on how to do a selectonebox, i think you missunderstood some things. Do you want to select a MaterialDTO Object in the list? or an Id? You dont need an ArrayList with SelectItem ...

Resources