如果我在我的数据表中移除p:commandButton上的“rendered”属性,我只能触发我的actionListener。不确定是什么问题。
页码:
<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>
违规项目在这里:
<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>
我的支持bean看起来像这样:
@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;
}
}
这是永远不会被调用的代码,除非我删除渲染的属性:
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());
}
任何建议表示赞赏。
此致
斯蒂芬