根据这篇文章,我想重新设计我的模板,因为我有同样的问题。我<h:commandButton>
的没有被调用。
编辑:我实现了一种从本教程制作模板的方法:KLICK
这是我的新主模板客户端,称为app.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<body>
<ui:composition template="./layout/layout.xhtml">
<ui:define name="header">
<ui:include src="./misc/header.xhtml"/>
</ui:define>
<ui:define name="rightColumn">
Ads here
</ui:define>
<ui:define name="leftColumn">
<ui:include src="./misc/sideBar.xhtml"/>
</ui:define>
<ui:define name="content">
<h:panelGroup id="contentPanel">
<ui:include src="#{appController.content}.xhtml" />
</h:panelGroup>
</ui:define>
<ui:define name="footer">
<ui:include src="./misc/footer.xhtml"/>
</ui:define>
</ui:composition>
</body>
</html>
主布局页面:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="./css/default.css" rel="stylesheet" type="text/css" />
<link href="./css/cssLayout.css" rel="stylesheet" type="text/css" />
<title>Facelets Template</title>
<style type="text/css" media="all">
body
{
background-color: #2b3a3c;
color: #2d2e2e;
font-family: Arial, Helvetica, sans-serif;
font-size: .8em;
line-height: 1.2em;
margin: 0 0 0 0; /* Sets the margin properties for an element using shorthand notation (top, right, bottom, left) */
padding: 0 0 0 0; /* Sets the padding properties for an element using shorthand notation (top, right, bottom, left) */
text-align: center; /* Centers the page content container in IE 5 browsers. */
}
#outerWrapper
{
background-color: #fff;
margin: 0 auto 0 auto; /* Sets the margin properties for an element using shorthand notation (top, right, bottom, left) */
text-align: left; /* Redefines the text alignment defined by the body element. */
width: 100%;
}
#outerWrapper #header
{
background-color: #8ab573;
border-bottom: solid 1px #628152; /* Sets the bottom border properties for an element using shorthand notation */
font-size: 1.5em;
font-weight: bold;
line-height: 1.7em;
padding: 10px 10px 10px 10px; /* Sets the padding properties for an element using shorthand notation (top, right, bottom, left) */
}
#outerWrapper #contentWrapper #rightColumn
{
background-color: #eef6ed;
border-left: solid 1px #8ab573; /* Sets the left border properties for an element using shorthand notation */
float: right;
padding: 10px; /* Sets the padding properties for an element using shorthand notation (top, right, bottom, left) */
width: 180px;
height: 200px;
}
#outerWrapper #contentWrapper #leftColumn
{
background-color: #eef6ed;
border-right: solid 1px #8ab573; /* Sets the right border properties for an element using shorthand notation */
float: left;
padding: 10px; /* Sets the padding properties for an element using shorthand notation (top, right, bottom, left) */
width: 180px;
height: 200px;
}
#outerWrapper #contentWrapper #content
{
margin: 0 16em 0 16em; /* Sets the margin properties for an element using shorthand notation (top, right, bottom, left) */
padding: 10px 10px 10px 10px; /* Sets the padding properties for an element using shorthand notation (top, right, bottom, left) */
}
#outerWrapper #contentWrapper .clearFloat
{
clear: both;
display: block;
}
#outerWrapper #footer
{
background-color: #8ab573;
border-bottom: solid 1px #628152; /* Sets the bottom border properties for an element using shorthand notation */
font-size: 1.5em;
font-weight: bold;
line-height: 1.7em;
padding: 10px 10px 10px 10px; /* Sets the padding properties for an element using shorthand notation (top, right, bottom, left) */
}
</style>
</head>
<body>
<div id="outerWrapper">
<div id="header">
<ui:insert name="header"/>
</div>
<div id="contentWrapper">
<div id="rightColumn">
<ui:insert name="rightColumn"/>
</div>
<div id="leftColumn">
<ui:insert name="leftColumn"/>
</div>
<div id="content">
<ui:insert name="content"/>
</div>
<br />
</div>
<div id="footer">
<ui:insert name="footer"/>
</div>
</div>
</body>
</html>
这是其中包含的页面之一。编辑:我在托管 bean 中将此页面设置为默认值。左侧的菜单目前不执行任何操作。因为暂时不需要。我唯一想要的是,如果我点击这个按钮,这个动作就会被调用:<h:commandButton id="btn_plan" value="Planen" action="#{hldyPlanningController.addHoliday()}" style="width: 170px; height: 30px"/>
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<f:facet name="first">
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
</f:facet>
</h:head>
<h:body>
<h:form id="frm_hldy_plan">
<p:panelGrid style="width: 100%;" >
<f:facet name="header">
<p:row>
<p:column colspan="2" style="height:50px;">
Urlaubsplanung
</p:column>
</p:row>
</f:facet>
<p:row>
<p:column style="width: 420px; vertical-align: top;" colspan="1">
<p:panel style="font-size: 12px; width: 420px; position: relative; border: 1px solid gray">
<f:facet name="header">
Urlaubsantrag Formular
</f:facet>
<p:panelGrid id="pnl_userinfo" style="font-size: 12px; width: 400px; border: 1px solid gray">
<f:facet name="header">
<p:row>
<p:column colspan="2">Persönliche Informationen</p:column>
</p:row>
</f:facet>
<p:row>
<p:column style="width:120px">
<h:outputText value="Name:"/>
</p:column>
<p:column>
<h:outputText value="#{loginController.sessionData.user_name}" />
</p:column>
</p:row>
<p:row>
<p:column style="width:120px">
<h:outputText value="Team:" />
</p:column>
<p:column>
<h:outputText value="#{loginController.sessionData.teams_name}" />
</p:column>
</p:row>
</p:panelGrid>
<br/>
<p:panelGrid id="pnl_time" style="font-size: 12px; width: 400px; border: 1px solid gray">
<f:facet name="header">
<p:row>
<p:column colspan="2">Zeitraum</p:column>
</p:row>
</f:facet>
<p:row>
<p:column style="width:120px">
<p:outputLabel for="cld_startdate" value="Startdatum:" />
</p:column>
<p:column>
<p:calendar value="#{hldyPlanningController.startdate}" id="cld_startdate" showOn="button" pattern="dd.MM.yyyy" required="true" requiredMessage="Startdatum ist ein Pflichtfeld!" showWeek="true"/>
</p:column>
</p:row>
<p:row>
<p:column style="width:120px">
<p:outputLabel for="cld_enddate" value="Enddatum:" />
</p:column>
<p:column>
<p:calendar value="#{hldyPlanningController.enddate}" id="cld_enddate" showOn="button" pattern="dd.MM.yyyy" required="true" requiredMessage="Enddatum ist ein Pflichfeld!" showWeek="true"/>
</p:column>
</p:row>
</p:panelGrid>
<br/>
<p:panelGrid id="pnl_misc" style="font-size: 12px; width: 400px; border: 1px solid gray">
<f:facet name="header">
<p:row>
<p:column colspan="2">Weiteres</p:column>
</p:row>
</f:facet>
<p:row>
<p:column style="width:120px">
<p:outputLabel for="opt_hType" value="Typ:"/>
</p:column>
<p:column>
<p:selectOneButton value="#{hldyPlanningController.type}" id="opt_hType" required="true" requiredMessage="Typ ist ein Pflichtfeld!">
<f:selectItem itemLabel="Urlaub" itemValue="U" />
<f:selectItem itemLabel="Absetzen" itemValue="A" />
</p:selectOneButton>
</p:column>
</p:row>
<p:row>
<p:column style="width:120px">
<p:outputLabel for="txta_note" value="Bemerkung:"/>
</p:column>
<p:column>
<p:inputTextarea maxlength="45" rows="2" cols="30" value="#{hldyPlanningController.note}" id="txta_note"/>
</p:column>
</p:row>
</p:panelGrid>
<br/>
<p:panelGrid id="pnl_actions" style="font-size: 12px; width: 400px; border: 1px solid gray">
<f:facet name="header">
<p:row>
<p:column colspan="2">Aktion</p:column>
</p:row>
</f:facet>
<p:row>
<p:column>
<h:commandButton id="btn_plan" value="Planen" action="#{hldyPlanningController.addHoliday()}" style="width: 170px; height: 30px"/>
</p:column>
<p:column>
<h:commandButton id="btn_submit" value="Abschicken" style="width: 170px; height: 30px"/>
</p:column>
</p:row>
</p:panelGrid>
</p:panel>
</p:column>
<p:column colspan="1" style="vertical-align: top;">
<p:panel style="font-size: 12px; border: 1px solid gray;">
<f:facet name="header">
Mitarbeiter, die in diesem Zeitraum auch Urlaub geplant haben
</f:facet>
<p:schedule value="#{calendarController.eventModel}" widgetVar="myschedule"></p:schedule>
</p:panel>
</p:column>
</p:row>
</p:panelGrid>
</h:form>
</h:body>
</html>
所有 Bean 都是@MangedBean
和@SessionScoped
。我在 Tomcat 7.x 上使用 JSF2.1 和 Primefaces 3.4.1;
我是 JSF 框架的新手,无法弄清楚在这种情况下我做错了什么。请帮我。
非常感谢。