2012-03-15 56 views
5

我想用AJAX实现JSF页面。这是JSF页面的代码:没有定义“head”组件

<?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"> 
    <h:head> 
     <ui:insert name="header">   
      <ui:include src="header.xhtml"/>   
     </ui:insert> 
    </h:head> 
    <h:body> 

     <h1><img src="resources/css/images/icon.png" alt="NVIDIA.com" /> Settings Center</h1> 
     <!-- layer for black background of the buttons --> 
     <div id="toolbar" style="margin: 0 auto; width:1180px; height:30px; position:relative; background-color:black"> 
      <!-- Include page Navigation --> 
      <ui:insert name="Navigation">   
       <ui:include src="Navigation.xhtml"/>   
      </ui:insert> 

     </div> 

     <div id="greenBand" class="ui-state-default ui-corner-allh" style="position:relative; top:35px; left:0px;"> 
      <h:graphicImage alt="Application Settings" style="position:relative; top:-20px; left:9px;" value="resources/images/logo_application_settings.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="settingsdiv" style="width:350px; height:400px; position:absolute; background-color:r; top:20px; left:1px"> 
        <h:panelGrid columns="2"> 
         <h:panelGroup>User Session Timeout</h:panelGroup> 
         <h:panelGroup> 
          <h:selectOneMenu value="#{ApplicationController.settingValue('SessionTTL')}"> 
           <f:selectItem itemValue="one" itemLabel="Option one" /> 
           <f:selectItem itemValue="two" itemLabel="Option two" /> 
           <f:selectItem itemValue="three" itemLabel="Option three" /> 
           <f:selectItem itemValue="custom" itemLabel="Define custom value" /> 
           <f:ajax render="input" /> 
          </h:selectOneMenu> 
          <h:panelGroup id="input"> 
           <h:inputText value="#{ApplicationController.settingValue('SessionTTL')}" rendered="#{bean.type == 'custom'}" required="true" /> 
          </h:panelGroup>    
         </h:panelGroup> 

         <h:panelGroup>Maximum allowed users</h:panelGroup> 
         <h:panelGroup>#{ApplicationController.settingValue('MaxUsersActive')}</h:panelGroup>                  
        </h:panelGrid>                

       </div> 

       <div id="settingslayer" style="width:350px; height:400px; position:absolute; background-color:transparent; top:20px; left:400px"> 



       </div> 

       <div id="settingspanel" style="width:350px; height:400px; position:absolute; background-color:transparent; top:20px; left:800px"> 


       </div> 



      </div> 
     </div> 

    </h:body> 
</html> 

当我加载页面我得到这个错误:

One or more resources have the target of "head", but no "head" component has been defined within the view.

这是标题的代码:

<?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"> 


    <title>Settings Center</title> 
    <link href="resources/css/helper.css" media="screen" rel="stylesheet" type="text/css" /> 

    <link href="resources/css/dropdown.css" media="screen" rel="stylesheet" type="text/css" /> 
    <link href="resources/css/default.advanced.css" media="screen" rel="stylesheet" type="text/css" /> 

    <!--[if lt IE 7]> 
    <script type="text/javascript" src="js/jquery/jquery.js"></script> 
    <script type="text/javascript" src="js/jquery/jquery.dropdown.js"></script> 
    <![endif]--> 

    <!--/END --> 



</html> 

阿贾克斯无法正常工作,并且在加载页面时出现此错误消息。也许我错过了要补充的东西。我如何修复代码?

最良好的祝愿 彼得

回答

4

尽量把<ui:composition><html>并围绕其在header.xhtml内容。

+0

我这样编辑代码:http://pastebin.com/gCFQsegf但没有任何变化。我仍然收到错误消息。 – 2012-03-15 10:35:11

+0

'ui:composition'仅在header.xhtml中需要。不知道还有什么可能是错的。您可以尝试从文件中移除“”标题,但实际上该消息大约缺少“”。 – mrembisz 2012-03-15 10:50:44

+0

我在navigation.xhtml页面添加了标签ui:composition。有用。谢谢! – 2012-03-15 11:04:47

6

好吧,我想你需要编辑header.xhtml这样

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"  
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:ui="http://java.sun.com/jsf/facelets"> 
    <ui:composition> 
    <title>index</title> 
     <h:head> 
      <link rel="stylesheet" href="style.css" type="text/css" 
       media="screen"/> 
      <script>.... 
      </script> 
     </h:head> 

确保您使用<h:head> - 而不是<head>