2012-09-22 43 views
0

我有一個問題,我無法解決。當我打開JSF選項卡並嘗試點擊按鈕時,該頁面無法工作。JSF頁面中的標籤不起作用

主頁:

<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"  
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core" 
     xmlns:ui="http://java.sun.com/jsf/facelets" 
     xmlns:p="http://primefaces.org/ui" 
     xmlns:c="http://java.sun.com/jsp/jstl/core"> 
    <h:head> 
     <ui:insert name="header">   
      <ui:include src="header.xhtml"/>   
     </ui:insert> 
     <style type="text/css"> 
      .settingsHashMap { font: 80% "Trebuchet MS", sans-serif;} 
     </style> 
    </h:head> 
    <h:body> 
     <h1><img src="resources/css/images/icon.png" alt="DX-57" /> Rack Management Center</h1> 
     <!-- layer for black background of the buttons --> 
     <div id="toolbar" style="margin: 0 auto; width:100%; height:30px; position:relative; background-color:black"> 
      <!-- Include page Navigation --> 
      <ui:insert name="Navigation">   
       <ui:include src="Navigation.xhtml"/>   
      </ui:insert> 
     </div> 
     <div id="logodiv" style="position:relative; top:35px; left:0px;"> 
      <h:graphicImage alt="Datacenter Profile" style="position:relative" value="resources/images/logo_datacenter_profile.png" /> 
     </div> 
     <div id="main" style="margin: 0 auto; width:1190px; height:700px; position:absolute; background-color:transparent; top:105px"> 

      <div id="mainpage" style="margin: 0 auto; width:1190px; height:500px; position:absolute; background-color:transparent; top:80px"> 

       <div id="settingsHashMapz" class="settingsHashMap" style="width:1150px; height:400px; position:absolute; top:20px; left:1px"> 

        <h:form prependId="false"> 
         <h:panelGroup id="tabs" layout="block"> 
          <ul> 
           <c:forEach items="#{DatacenterProfileController.tabs}" var="tab"> 
            <li><a href="##{tab.tabid}" onclick="$('#button_#{tab.tabid}').click()">#{tab.tabid}</a></li> 
            <h:commandButton id="button_#{tab.tabid}" value="TabClick" action="#{DatacenterProfileController.switchPages(tab.tabid)}" style="display:none"> 
             <f:ajax render="tabs"></f:ajax> 
            </h:commandButton> 
           </c:forEach> 
          </ul> 

          <c:forEach items="#{DatacenterProfileController.tabs}" var="tab"> 
           <h:panelGroup id="#{tab.tabid}" layout="block" rendered="#{tab.tabid eq DatacenterProfileController.selectedTab}"> 
            <ui:include src="#{tab.tabfilename}"></ui:include> 
           </h:panelGroup> 
          </c:forEach> 

         </h:panelGroup> 
        </h:form> 

       </div> 

      </div> 
     </div> 
    </h:body> 
</html> 

標籤頁:

<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"  
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core" 
     xmlns:ui="http://java.sun.com/jsf/facelets" 
     xmlns:p="http://primefaces.org/ui" 
     xmlns:c="http://java.sun.com/jsp/jstl/core"> 
    <h:head> 

    </h:head> 
    <h:body> 
     <ui:composition> 
      <h:panelGroup> 
       <h:form id="zones" > 
        <p:growl id="growl" showDetail="true" sticky="true" /> 
        <!-- The sortable data table --> 
        <h:dataTable onmouseover="addOnclickToTabsDatatableRows();" id="dataTable" headerClass="columnHeader" value="#{DCProfileTabZonesController.dataList}" binding="#{zones}" var="item"> 
         <!-- Check box --> 
         <h:column> 
          <f:facet name="header"> 
           <h:selectBooleanCheckbox style="margin-left: 0px;" value="#{DCProfileTabZonesController.mainSelectAll}" class="checkall" > 
            <f:ajax listener="#{DCProfileTabZonesController.selectAll}" render="@form" /> 
           </h:selectBooleanCheckbox> 
          </f:facet> 
          <h:selectBooleanCheckbox onclick="highlight(this)" value="#{DCProfileTabZonesController.selectedIds[item.datacenterid]}" > 
           <!-- if the user deselects one row deselect the main checkbox --> 
           <f:ajax listener="#{DCProfileTabZonesController.deselectMain}" render="@form" /> 
          </h:selectBooleanCheckbox> 
          <!-- Click on table code --> 
          <h:outputLink id="lnkHidden" value="ZoneProfile.jsf" style="text-decoration:none; color:white; background-color:black"> 
           <f:param name="id" value="#{item.datacenterid}" /> 
          </h:outputLink> 
         </h:column> 
         ............ 

        </h:dataTable> 

        <!-- The paging buttons --> 
        <h:commandButton styleClass="bimage" value="first" action="#{DCProfileTabZonesController.pageFirst}" 
            disabled="#{DCProfileTabZonesController.firstRow == 0}" > 
         <f:ajax render="@form" execute="@form"></f:ajax> 
        </h:commandButton>&nbsp; 

        <h:commandButton styleClass="bimage" value="prev" action="#{DCProfileTabZonesController.pagePrevious}" 
            disabled="#{DCProfileTabZonesController.firstRow == 0}" > 
         <f:ajax render="@form" execute="@form"></f:ajax> 
        </h:commandButton>&nbsp; 

        <h:commandButton styleClass="bimage" value="next" action="#{DCProfileTabZonesController.pageNext}" 
            disabled="#{DCProfileTabZonesController.firstRow + DCProfileTabZonesController.rowsPerPage >= DCProfileTabZonesController.totalRows}" > 
         <f:ajax render="@form" execute="@form"></f:ajax> 
        </h:commandButton>&nbsp;  

        <h:commandButton styleClass="bimage" value="last" action="#{DCProfileTabZonesController.pageLast}" 
            disabled="#{DCProfileTabZonesController.firstRow + DCProfileTabZonesController.rowsPerPage >= DCProfileTabZonesController.totalRows}" > 
         <f:ajax render="@form" execute="@form"></f:ajax> 
        </h:commandButton>&nbsp; 

        <h:outputText value="Page #{DCProfileTabZonesController.currentPage}/#{DCProfileTabZonesController.totalPages}" /> 
        <br /> 

        <!-- The paging links --> 
        <ui:repeat value="#{DCProfileTabZonesController.pages}" var="page"> 
         <h:commandLink value="#{page}" actionListener="#{DCProfileTabZonesController.page}" 
             rendered="#{page != DCProfileTabZonesController.currentPage}" style="text-decoration:none;color:white;"> 
          <f:ajax render="@form" execute="@form"></f:ajax> 
         </h:commandLink> 
         <h:outputText value="#{page}" escape="false" 
             rendered="#{page == DCProfileTabZonesController.currentPage}" style="text-decoration:none;color:gray;"/> 
        </ui:repeat> 
        <br /> 

        <!-- Set rows per page --> 
        <h:outputLabel for="rowsPerPage" value="Rows per page" /> 
        <h:inputText id="rowsPerPage" value="#{DCProfileTabZonesController.rowsPerPage}" size="3" maxlength="3" /> 
        <h:commandButton styleClass="bimage" value="Set" action="#{DCProfileTabZonesController.pageFirst}" > 
         <f:ajax render="@form" execute="@form"></f:ajax> 
        </h:commandButton>&nbsp; 
        <h:message for="rowsPerPage" errorStyle="color: red;" /> 

        <!-- hidden button --> 
        <h:commandButton id="deleterow" value="HiddenDelete" action="#{DCProfileTabZonesController.deleteSelectedIDs}" style="display:none"> 
         <f:ajax render="@form"></f:ajax> 
        </h:commandButton> 

        <!-- the delete button --> 
        <h:button styleClass="bimage" value="Delete" onclick="deletedialog(this, 'Do you want to delete the selected rows?'); return false;" />&nbsp; 

        <!-- New Zone --> 
        <h:button id="newzone" styleClass="lbimage" value="New Zone" outcome="/NewZone.xhtml"/> 

        <script type="text/javascript" src="resources/js/tabs.js"></script> 
       </h:form>   
      </h:panelGroup> 
     </ui:composition> 
    </h:body> 
</html> 

當我刪除了ui:composition標籤並插入我所有的代碼放到一個頁面的按鈕都在工作。

+1

請在[我們的JSF wiki](http://stackoverflow.com/tags/jsf/info)中閱讀「提供的信息」的最後一點。很多你的問題(和[你的同事或克隆賬戶](http://stackoverflow.com/users/1285928/user1285928))被忽略或幾乎沒有正確回答,因爲它們含有大量不相關的噪音(也是如此經常被變色)。例如,你是絕對肯定的,例如這件作品'DX-57'與這個特殊問題有關嗎?即當你刪除它時,問題消失了?沒有?離開它。 – BalusC

+0

好吧,我會記下來。一個想法,爲什麼它不工作 - 我使用形式到另一種形式。這可能是一個問題嗎? –

+0

是的,表單不能在另一個表單內。很抱歉,但這是基本的HTML。在網絡上開始編程之前,您應該學習(或查看)網絡的工作方式。看到這個答案:[從哪裏開始從Web開發?](http://stackoverflow.com/a/1843841/1065197)和[Java Web開發,我需要什麼技能?](http://stackoverflow.com/a/1958854/1065197),均由BalusC提供。 –

回答

3

正如您在其中一條評論中指出的那樣,您不能使用嵌套表單。你需要重構你的佈局。將您的外表格放在您的外圍<ul>

<h:panelGroup id="tabs" layout="block"> 
    <h:form prependId="false"> 
      <ul> 
      ... 
      </ul> 
    </h:form> 

    <c:forEach items="#{DatacenterProfileController.tabs}" var="tab"> 
      ... 
    </c:forEach> 
</h:panelGroup> 

您的其他代碼應該沒問題。通過這種方式可以避免嵌套窗體。