Shr*_*uti 6 java xhtml templates jsf-2
我已经加了我commandLink(这是注销链接)到模板文件,该文件是不是一个内部的JSF表单.
MainTemplate.xhtml
<h:commandLink action="#{welcomeBean.logOutSession}" class="subAnchor" value="Log Out">
</h:commandLink>
Run Code Online (Sandbox Code Playgroud)
对使用该模板的网页,我有一个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>
Run Code Online (Sandbox Code Playgroud)
我希望注销将工作,一旦我在页面中使用的模板与JSF表单.然而,注销commandLink显示错误:
注销:因为它不嵌套在JSF表单中的这个链接被禁用.
我知道一个明确的解决办法是单独添加这些元素到每个将使用该模板的XHTML页面的.但我希望它被添加到模板本身,因为它是一种常见的元素中的所有页面.
任何帮助将深表感谢.谢谢!:)
编辑: 这是我的MainTemplate.xhtml的代码
<?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>
Run Code Online (Sandbox Code Playgroud)
小智 12
由于commandLink启动了一个动作,你必须添加啊:form
<h:form>
<h:commandLink action="#{welcomeBean.logOutSession}" class="subAnchor" value="Log Out"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)