2014-01-27 62 views
0
 public void approveVacation() throws AddressException,MessagingException 
    String emplname=this.getEmployeeName(); 

    session = FacesContext.getCurrentInstance().getExternalContext() 
     .getSessionMap(); 

    VacationDTO vacation=new VacationDTO(); 
    vacation.setLeaveId(this.getLeaveId()); 
    vacation.setLeaveDescriptions(this.getLeaveDescriptions()); 
    vacation.setLeaveStartDate(this.getLeaveStartDate()); 
    vacation.setEmployee(getEmployeeService().getUserByEmployeeId(getEmployeeId())); 

    vacation.setIsApproved((byte)1); 
    getVacationService().approveVacation(vacation); 
    String to=vacation.getEmployee().getEmployeeEmailAddress(); 
    String name=vacation.getEmployee().getEmployeeName(); 
    getVacationService().approveVacation(vacation); 
    Util.sendMail(to, "Hi"+name, 
      "Your vacation have been approved"); 

而這正是我使用我的名單XHTML頁面....無法使用數據表從JSF發送郵件,

<h:form> 


      <h:dataTable headerClass="header" rowClasses="oddRow,evenRow" value="#{approveVacationBean.vacationList}" 
        var="list"> 
        <h:column> 
         <f:facet name="header">Employee Id</f:facet> 
        #{list.employee.employeeId} 
       </h:column> 
        <h:column> 
         <f:facet name="header">Employee Name</f:facet> 
        #{list.employee.employeeName} 
       </h:column> 

        <h:column> 
         <f:facet name="header">Leave Applied</f:facet> 
        #{list.leaveStartDate} 

       </h:column> 
        <h:column> 
         <f:facet name="header">Leave Start Date</f:facet> 
        #{list.leaveStartDate} 

       </h:column> 


        <h:column> 
         <f:facet name="header">Leave End Date</f:facet> 
        #{list.leaveEndDate} 
       </h:column> 
        <h:column> 
         <f:facet name="header">No of days</f:facet> 
        #{list.leaveEndDate} 


</h:column> 
<h:column> 
<f:facet name="header">Paid Leave Balence</f:facet> 
    #{list.leaveBalance} 
    </h:column> 

        <h:column> 
        <f:facet name="header">Leave Description</f:facet> 
        #{list.leaveDescriptions} 


        </h:column> 
       <h:column> 
         <f:facet name="header">Comment</f:facet> 
        <h:inputTextarea ></h:inputTextarea> 
       </h:column> 
       <h:column> 
         <f:facet name="header"></f:facet> 
       <h:commandButton value="Approve"/> 
       <h:commandButton value="Reject"/> 
       </h:column> 

       </h:dataTable> 

我得到的問題在選擇特定的行按鈕。

很多時候,所謂的...我使用getVacationList()用於顯示列表serive方法,但沒有郵件發送給特定員工

回答

1

首先,放置在approveVacationBean你approveVacation方法。

然後改變方法來接受列表作爲參數(我想它是VacationDTO)。

最後,你應該用approveVacation方法鏈接命令按鈕:

<h:commandButton value="Approve" ajax="false" action="#{approveVacationBean.approveVacation(list)}"/> 

你approveVacation方法應該是這樣的:

public void approveVacation(VacationDTO vacation) throws AddressException,MessagingException { 

vacation.setIsApproved((byte)1); 
getVacationService().approveVacation(vacation); 
String to=vacation.getEmployee().getEmployeeEmailAddress(); 
String name=vacation.getEmployee().getEmployeeName(); 
getVacationService().approveVacation(vacation); 
Util.sendMail(to, "Hi"+name, 
     "Your vacation have been approved"); 

}

+0

叫這不是工作vacationList()方法很多次... – user3073103

+0

MB控股vacationList()的範圍是什麼?您是否使用@PostConstruct來初始化vacationList?顯示你的MB代碼... – Yamada

+0

我嘗試過所有範圍。我正在使用getVacationList()....我沒有使用@PostConstruct .. – user3073103