我想问你关于 xhtml 是如何工作的。
这是我的 tablero.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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<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:head id="demo" >Opportunities: </h:head>
<h:outputText value="#{partidaController.getRemainingOp()}"/>
<br/>
<h:outputText value="#{partidaController.getNombreJugador()}"/>
<br/>
<c:forEach var="x" items="#{partidaController.getLetrasColocadas()}" >
<h:inputText disabled="true" size="1" value="${x}"/>
</c:forEach>
<br/>
<h:panelGrid>
<h:form>
<p:commandButton id="b1" style="height: 30px; width: 30px;" value="a" action="#{turnoController.createTurno('a')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b2" style="height: 30px; width: 30px;" value="b" action="#{turnoController.createTurno('b')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b3" style="height: 30px; width: 30px;" value="c" action="#{turnoController.createTurno('c')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b4" style="height: 30px; width: 30px;" value="d" action="#{turnoController.createTurno('d')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b5" style="height: 30px; width: 30px;" value="e" action="#{turnoController.createTurno('e')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b6" style="height: 30px; width: 30px;" value="f" action="#{turnoController.createTurno('f')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b7" style="height: 30px; width: 30px;" value="g" action="#{turnoController.createTurno('g')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b8" style="height: 30px; width: 30px;" value="h" action="#{turnoController.createTurno('h')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b9" style="height: 30px; width: 30px;" value="i" action="#{turnoController.createTurno('i')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b10" style="height: 30px; width: 30px;" value="j" action="#{turnoController.createTurno('j')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b11" style="height: 30px; width: 30px;" value="k" action="#{turnoController.createTurno('k')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b12" style="height: 30px; width: 30px;" value="l" action="#{turnoController.createTurno('l')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b13" style="height: 30px; width: 30px;" value="m" action="#{turnoController.createTurno('m')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b14" style="height: 30px; width: 30px;" value="n" action="#{turnoController.createTurno('n')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b15" style="height: 30px; width: 30px;" value="o" action="#{turnoController.createTurno('o')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b16" style="height: 30px; width: 30px;" value="p" action="#{turnoController.createTurno('p')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b17" style="height: 30px; width: 30px;" value="q" action="#{turnoController.createTurno('q')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b18" style="height: 30px; width: 30px;" value="r" action="#{turnoController.createTurno('r')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b19" style="height: 30px; width: 30px;" value="s" action="#{turnoController.createTurno('s')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b20" style="height: 30px; width: 30px;" value="t" action="#{turnoController.createTurno('t')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b21" style="height: 30px; width: 30px;" value="u" action="#{turnoController.createTurno('u')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b22" style="height: 30px; width: 30px;" value="v" action="#{turnoController.createTurno('v')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b23" style="height: 30px; width: 30px;" value="w" action="#{turnoController.createTurno('w')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b24" style="height: 30px; width: 30px;" value="x" action="#{turnoController.createTurno('x')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b25" style="height: 30px; width: 30px;" value="y" action="#{turnoController.createTurno('y')}" onclick="document.getElementById(this.id).disabled=true;"/>
<p:commandButton id="b26" style="height: 30px; width: 30px;" value="z" action="#{turnoController.createTurno('z')}" onclick="document.getElementById(this.id).disabled=true;"/>
<br />
</h:form>
<h:graphicImage value="../resources/images/hangman.jpg" width="480" height="400" />
<h:link outcome="/index" value="#{bundle.CreateJugadorIndexLink}"/>
</h:panelGrid>
</ui:define>
</ui:composition>
</html>
这是我每次单击buttonCommand时调用的bean:
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;
}
}
这是我要调用来更新项目的方法...
public List getLetrasColocadas()
{
String lc = getFacade().letrasColocadasById(current.getIdPartida());
ArrayList<String> lista = new ArrayList<String>();
int i;
for (i=0; i<lc.length(); i++){
String h = "" + lc.charAt(i) + "";
lista.add(h);
}
return lista;
}
partidaController.getLetrasColocadas() 工作正常(我已经调试过它,它做了我想要的)。问题是 inputText 值一旦显示,如果单击命令按钮,例如调用返回带有此 xhtml 文件名称的字符串的 bean,它们将永远不会再次更新......它始终保持不变。
我应该知道关于 xhtml 的任何魔法???