我正在尝试使用 JSF 构建一个刽子手游戏。我有一个 Facelet 文件,我在其中放置了 abecedary 字母的命令按钮。
<ui:composition template="/template.xhtml">
<ui:define name="title">
<h:outputText value="Dak's Hangman"></h:outputText>
</ui:define>
<ui:define name="body">
<h:panelGroup id="messagePanel" layout="block">
<h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
</h:panelGroup>
<h:form id="formJuego">
<h:head id="demo" >Opportunities: </h:head>
<h:outputText value="${partidaController.getRemainingOp()}"/>
<br/>
<h:outputText value="${partidaController.getNombreJugador()}"/>
<br/>
<h:form>
<c:forEach var="x" items="${partidaController.getLetrasColocadas()}" >
<h:inputText disabled="true" size="1" value="${x}"/>
</c:forEach>
</h:form>
<br/>
<h:panelGrid columns="2">
<h:form>
<h:panelGrid columns="9">
<p:commandButton style="height: 30px; width: 30px;" value="a" action="#{turnoController.createTurno('a')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="b" action="#{turnoController.createTurno('b')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="c" action="#{turnoController.createTurno('c')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="d" action="#{turnoController.createTurno('d')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="e" action="#{turnoController.createTurno('e')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="f" action="#{turnoController.createTurno('f')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="g" action="#{turnoController.createTurno('g')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="h" action="#{turnoController.createTurno('h')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="i" action="#{turnoController.createTurno('i')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="j" action="#{turnoController.createTurno('j')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="k" action="#{turnoController.createTurno('k')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="l" action="#{turnoController.createTurno('l')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="m" action="#{turnoController.createTurno('m')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="n" action="#{turnoController.createTurno('n')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="o" action="#{turnoController.createTurno('o')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="p" action="#{turnoController.createTurno('p')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="q" action="#{turnoController.createTurno('q')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="r" action="#{turnoController.createTurno('r')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="s" action="#{turnoController.createTurno('s')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="t" action="#{turnoController.createTurno('t')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="u" action="#{turnoController.createTurno('u')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="v" action="#{turnoController.createTurno('v')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="w" action="#{turnoController.createTurno('w')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="x" action="#{turnoController.createTurno('x')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="y" action="#{turnoController.createTurno('y')}"/>
<p:commandButton style="height: 30px; width: 30px;" value="z" action="#{turnoController.createTurno('z')}"/>
</h:panelGrid>
<h:graphicImage value="../resources/images/hangman.jpg" width="480" height="400" />
<br/>
</h:form>
</h:panelGrid>
<h:link outcome="/index" value="#{bundle.CreateJugadorIndexLink}"/>
</h:form>
</ui:define>
</ui:composition>
这是支持 bean 类:
public class TurnoController implements Serializable {
private Turno current;
private DataModel items = null;
@EJB
private DBClasses.TurnoFacade ejbFacade;
private PaginationHelper pagination;
private int selectedItemIndex;
其中有一个createTurno()
方法:
public String createTurno(String s) {
try {
Map<String, Object> sesionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
Integer id = (Integer) sesionMap.get("id_partida");
Partida p = new Partida();
p.setIdPartida(id);
current= new Turno();
current.setIdPartida(p);
current.setLetraTurno(s);
ejbFacade.create(current);
return "tablero";
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
return null;
}
}
我想要做的是从更新数据库中的移动的类控制器中调用方法(我使用 PostgreSQL)。
但是,按下命令按钮时不会调用该方法。这是如何引起的,我该如何解决?