2014-04-15 20 views
6

Tôi đã thêm My commandLink (là liên kết đăng xuất) vào tệp mẫu mà không phải là bên trong biểu mẫu jsf .CommandLink không ở dạng jsf vì tôi đã thêm nó vào mẫu. Tuy nhiên nó bị vô hiệu hóa. Có cách nào khác để kích hoạt nó không?

MainTemplate.xhtml

<h:commandLink action="#{welcomeBean.logOutSession}" class="subAnchor" value="Log Out"> 
</h:commandLink> 

trên trang web có sử dụng các mẫu, tôi có tất cả các yếu tố bên trong một hình thức JSF:

NewWelcome.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
       xmlns:h="http://xmlns.jcp.org/jsf/html" 
       xmlns:f="http://xmlns.jcp.org/jsf/core" 
       xmlns:ui="http://java.sun.com/jsf/facelets" 
       template="/webpages/templates/MainTemplate.xhtml"> 

    <ui:define name="infomationPartOfBody"> 
    <h:form> 
<div> Here i have all the page specific content </div> 

</h:form> 
</ui:define> 

</ui:composition> 

Tôi đã hy vọng rằng việc đăng xuất sẽ hoạt động khi tôi sử dụng mẫu trong một trang có dạng jsf. Tuy nhiên, lệnh đăng xuấtLiên kết hiển thị lỗi:

Đăng xuất: Liên kết này bị tắt vì không được lồng trong biểu mẫu JSF.

Tôi biết giải pháp rõ ràng là thêm phần tử này riêng biệt vào từng trang xhtml có thể sử dụng mẫu. Nhưng tôi muốn nó được thêm vào bản thân mẫu vì nó là phần tử phổ biến trong tất cả các trang.

Mọi trợ giúp sẽ được đánh giá cao. Cảm ơn bạn! :)

Biên tập: đây là mã của MainTemplate.xhtml tôi

<?xml version="1.0" encoding="UTF-8"?> 

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://xmlns.jcp.org/jsf/html" 
xmlns:f="http://xmlns.jcp.org/jsf/core" 
    xmlns:ui="http://java.sun.com/jsf/facelets"> 
<f:view> 

    <h:head> 
     <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/cupertino/jquery-ui.css"/> 
     <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.0.js"></script> 
     <script type="text/javascript" src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
    <script type="text/javascript" src="../JavaScriptPages/JQueryFile.js"></script> 

     <title>State Transport Department- Work Schedule</title> 
     <link rel="stylesheet" type="text/css" href="../CSS/CompleteTemplateCSS.css"/> 
    <link rel="stylesheet" type="text/css" href="../CSS/templateCSS.css"/> 
    </h:head> 

    <h:body> 

     <div class="container"> 
      <div class="header"> 
       <h:graphicImage id="img" value="http://s28.postimg.org/ksnr9zs5p/header.jpg" class="img" ></h:graphicImage> 
      </div> 
      <div class="menu"> 
       <h:outputLabel class="welcomeNote" style="font-size: x-large; color: white; float: left; 
           margin: 8px 0 0 5px; text-shadow:0 0 3px white" value="#{welcomeBean.fullname}" /> 

     <ul class="ulForMyAccount"> 
         <li> <h:outputLabel value="My Account" id="mainAnchor"/> 

          <ul > 
           <li> <h:link value="Change my Password" outcome="/webpages/ChangePasswordxhtml.xhtml" rendered="true" class="subAnchor"/> </li> 
           <li><h:commandLink action="#{welcomeBean.logOutSession}" class="subAnchor" value="Log Out"> 
          </h:commandLink> </li> 

          </ul> 
         </li> 
        </ul>  
      </div> 
      <div class="contentBody"> 
       <div class="menuTable"> 

        <table class="templateBody" > 
          <tr> 
           <td class="navigationLink" > <ul><li> 
              <h:link value="Home" outcome="/webpages/NewWelcome.xhtml" rendered="#{welcomeBean.home}" class="mainLinks"/> 
             </li></ul> </td> 

          </tr> 

          <tr> 
           <td class="navigationLink"> <ul> <li> 
              <h:link value="My Schedule" outcome="/webpages/MyTask.xhtml" rendered="#{welcomeBean.myTask}" class="mainLinks"/>  
             </li></ul></td> 
          </tr> 

          <tr> 
           <td class="navigationLink"> <ul> <li> 
              <h:link value="Employee Work Schedule" outcome="/webpages/EmpDutySched.xhtml" rendered="#{welcomeBean.workSchedule}" class="mainLinks"/>  
             </li></ul></td> 
          </tr> 

          <tr> 
           <td class="navigationLink"><ul> <li> 
              <h:link value="Allocate Work" outcome="/webpages/AllocateTask.xhtml" rendered="#{welcomeBean.allocateWork}" class="mainLinks"/> 
             </li></ul></td> 
          </tr> 

          <tr> 
           <td class="navigationLink"><ul> <li> 
              <h:outputLabel value="Report" rendered="#{welcomeBean.report}" class="reportMenu"/> 

              </li></ul> 
            <ul> 
               <li><h:link value="Project Wise Report" outcome="/webpages/ProjectWiseReport.xhtml" rendered="true" class="reportItems"/></li> 
               <li><h:link value="Employee Wise Report" outcome="/webpages/EmployeeWiseReport.xhtml" rendered="true" class="reportItems"/></li> 
              </ul> 
             </td> 
          </tr> 

         </table> 

       </div> 

       <ui:insert name="infomationPartOfBody"> 

       </ui:insert> 

      </div> 

      <div class="footer"></div> 
     </div> 

    </h:body> 

</f:view> 

</html> 
+0

bạn có thể thêm mã của mẫu của bạn MainTemplate.xhtml? – user3489875

+0

tôi đã thêm. vui lòng xem. – Shruti

Trả lời

10

Kể từ commandLink khởi động một hành động, bạn phải thêm ah: hình thức

<h:form> 
<h:commandLink action="#{welcomeBean.logOutSession}" class="subAnchor" value="Log Out"/> 
</h:form> 
+0

vì vậy tôi chỉ cần thêm nút đăng xuất tht trong biểu mẫu jsf hoặc toàn bộ mẫu? Và sẽ không có một mẫu trong mẫu và các trang khác tạo ra một số loại lỗi? lỗi của hai hình thức tồn tại vv? – Shruti

+0

Bạn có thử điều này:

  • user3489875

    +0

    có! nó đã làm việc! Cảm ơn rât nhiêu! :) – Shruti

    Các vấn đề liên quan