我在Facelet中有一个按钮,当我单击它时,我想调用bean函数。但是,由于没有调用该函数,因此页面重新加载并崩溃,而不是调用函数。
当我单击<h:commandButton action="#{trainingsplanBean.changeWeek}" value="OK" />
时,函数changeWeek
不会被调用,并且页面会重新加载。由于缺少数据,导致应用程序崩溃。
Facelet(XHTML文件):
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
template="../WEB-INF/templates/internalTemplate.xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:define name="content">
<p align="center">
<b style="color: red;">Bitte nicht vergessen die durchgeführten Änderungen mit einem Klick auf den "Speichern" Button zu sichern!</b>
<h:commandButton value="Speichern!" class="button">
<f:actionListener binding="#{trainingsplanBean.save()}" />
<f:actionListener binding="#{bereichLaufenBean.save()}" />
<f:actionListener binding="#{bereichRadfahrenBean.save()}" />
</h:commandButton>
</p>
<div style="overflow-x: auto;" align="center">
<table cellspacing="0" cellpadding="5" id="plan_table">
<thead>
<tr>
<th colspan="2" rowspan="2" class="kw_cell tp_table_border">
KW
<h:selectOneMenu id="kw" value="#{trainingsplanBean.kw}">
<f:selectItems value="#{trainingsplanBean.weeks}" />
</h:selectOneMenu>
/
<h:selectOneMenu id="year" value="#{trainingsplanBean.year}">
<f:selectItems value="#{trainingsplanBean.years}" />
<f:ajax execute="year" render="kw" listener="#{trainingsplanBean.prepareWeeks()}" />
</h:selectOneMenu>
<h:commandButton action="#{trainingsplanBean.changeWeek}" value="OK" />
<h:commandButton action="#{trainingsplanBean.today}" value="Heute" immediate="true" />
<br />
<h:commandButton action="#{trainingsplanBean.prevWeek}" value="vorige Woche" immediate="true" /> <h:commandButton action="#{trainingsplanBean.nextWeek}" value="folgende Woche" immediate="true" />
</th>
<th class="date_cell tp_table_border"><h:outputText value="#{trainingsplanBean.getDayOfWeek(1)}" /><br />MO</th>
<th class="date_cell tp_table_border"><h:outputText value="#{trainingsplanBean.getDayOfWeek(2)}" /><br />DI</th>
<th class="date_cell tp_table_border"><h:outputText value="#{trainingsplanBean.getDayOfWeek(3)}" /><br />MI</th>
<th class="date_cell tp_table_border"><h:outputText value="#{trainingsplanBean.getDayOfWeek(4)}" /><br />DO</th>
<th class="date_cell tp_table_border"><h:outputText value="#{trainingsplanBean.getDayOfWeek(5)}" /><br />FR</th>
<th class="date_cell tp_table_border"><h:outputText value="#{trainingsplanBean.getDayOfWeek(6)}" /><br />SA</th>
<th class="date_cell tp_table_border"><h:outputText value="#{trainingsplanBean.getDayOfWeek(7)}" /><br />SO</th>
<th rowspan="2" style="font-weight: bold;" class="tp_table_border">GESAMT</th>
</tr>
</thead>
<tbody>
<!-- Schwimmen -->
<tr>
<td rowspan="4" class="type_cell schwimmen">Schwimmen</td>
<td class="desc_cell schwimmen">Ist-Zeit</td>
<td class="schwimmen"><p:calendar value="#{trainingsplanBean.getDay(1).schwimmen.istdauer}" timeOnly="true" pattern="HH:mm" /></td>
<td class="schwimmen"><p:calendar value="#{trainingsplanBean.getDay(2).schwimmen.istdauer}" timeOnly="true" pattern="HH:mm" /></td>
<td class="schwimmen"><p:calendar value="#{trainingsplanBean.getDay(3).schwimmen.istdauer}" timeOnly="true" pattern="HH:mm" /></td>
<td class="schwimmen"><p:calendar value="#{trainingsplanBean.getDay(4).schwimmen.istdauer}" timeOnly="true" pattern="HH:mm" /></td>
<td class="schwimmen"><p:calendar value="#{trainingsplanBean.getDay(5).schwimmen.istdauer}" timeOnly="true" pattern="HH:mm" /></td>
<td class="schwimmen"><p:calendar value="#{trainingsplanBean.getDay(6).schwimmen.istdauer}" timeOnly="true" pattern="HH:mm" /></td>
<td class="schwimmen"><p:calendar value="#{trainingsplanBean.getDay(7).schwimmen.istdauer}" timeOnly="true" pattern="HH:mm" /></td>
<td class="schwimmen tp_table_border"><h:outputText value="#{trainingsplanBean.wochensumme_schwimmen_istdauer_str()}" /></td>
</tr>
and so on ...
Bean:
@ManagedBean(name = "trainingsplanBean", eager = true)
@ViewScoped
public class TrainingsplanBean implements Serializable {
public void changeWeek() {
for (int i = 1; i <= 7; i++) {
Date date = Utilities.getDayOfWeek(year, kw, i);
System.out.println("CHANGE WEEK : DAY " + i);
try {
Trainingstag tag = TrainingsplanService.inst().readTrainingstag(getCurrentUser(), date);
System.out.println(tag);
trainingstage[i - 1] = tag;
} catch (DatabaseException ex) {
}
}
}
}