【发布时间】:2013-03-12 20:03:13
【问题描述】:
我正在使用 JSF2 和 Richfaces 4 的 Java EE 应用程序工作。我们决定使用模态窗口进行一些交互,我们选择了带有 h:form 的 Jquery UI Dialog,因为我们已经在使用 Jquery UI这个项目。
对话框正确打开,并提交表单,提交是使用 h:commandButton 和 a4j:ajax 进行的。 h:commandButton 保持隐藏状态,由对话框按钮触发。
一切看起来都很完美,但对话框/表单只能运行一次。如果我在不刷新页面的情况下关闭并打开对话框,我会在提交表单时收到消息:
javax.faces.application.ViewExpiredException: viewId:/frontend/initial.xhtml - /frontend/initial.xhtml 无法恢复
对话框的JSF/HTML:
<h:panelGroup id="dialog-nova-intercorrencia" styleClass="ui-dialog-content ui-widget-content">
<h:form id="frm-dialog-nova-intercor" prependId="false">
<table>
<tr>
<td>Paciente</td>
<td>
<h:selectOneMenu id="sel-intern-intercor" value="#{intercorrenciaController.novaIntercorrencia.internacao.internacaoID}" styleClass="ui-widget-content ui-corner-all">
<f:selectItems value="#{internacaoController.listInternacoesSelectItem}" />
</h:selectOneMenu>
</td>
</tr>
<tr>
<td>Impacto</td>
<td>
<h:selectOneMenu id="sel-impacto" value="#{intercorrenciaController.novaIntercorrencia.impacto.impactoID}" styleClass="ui-widget-content ui-corner-all">
<f:selectItems value="#{intercorrenciaController.listaImpactosSelectItem}" />
</h:selectOneMenu>
</td>
</tr>
<tr>
<td>
Data e Hora
</td>
<td>
<h:inputText value="#{intercorrenciaController.dataIntercorrencia}" styleClass="ui-widget-content ui-corner-all" style="width: 130px" />
 
<h:inputText value="#{intercorrenciaController.horaIntercorrencia}" styleClass="ui-widget-content ui-corner-all" style="width: 70px" />
</td>
</tr>
<tr>
<td>Resumo</td>
<td><h:inputText value="#{intercorrenciaController.novaIntercorrencia.resumo}" size="25" styleClass="ui-widget-content ui-corner-all" /></td>
</tr>
<tr>
<td colspan="2">
Comentarios
<br />
<h:inputTextarea cols="30" rows="3" value="#{intercorrenciaController.novaIntercorrencia.descricao}" />
</td>
</tr>
</table>
<h:commandButton id="btt-add-nova-intercor" action="#{intercorrenciaController.cadastrarIntercorrencia}" style="display:none">
<a4j:ajax execute="@form" render="@form frm-dialog-nova-intercor panel-lista-intercorrencias" />
</h:commandButton>
</h:form>
</h:panelGroup>
创建 jQuery UI Dialog 的 JS:
$("#dialog-nova-intercorrencia").dialog({
position: {
my: "top top",
at: "top top",
of: window
},
autoOpen: false,
height: 350,
width: 400,
draggable: false,
resizable: false,
modal: true,
buttons: {
"Cadastrar": function() {
$("#btt-add-nova-intercor").trigger("click");
},
"Cancelar": function() {
$( this ).dialog( "close" );
$(this).find("input").val("");
$(this).find("textarea").val("");
$(this).find("select").val(0);
}
},
close: function() {
$(this).find("input").val("");
$(this).find("textarea").val("");
$(this).find("select").val(0);
}
});
有谁知道我只能在拨号中执行表单一次而第二次收到消息“无法恢复视图”的原因?
【问题讨论】:
-
为什么不用 RichFaces 自己的
<rich:popupPanel>? -
之前这个项目使用的是JSF 1.2和richfaces 3,这次我判断Richface的模态窗口没有我需要的所有功能,具体原因我不记得了。
-
@BalusC 感谢您的评论和提示。我认为文本不是完全可以理解的。问题出在第二次提交而不是第二次打开。打开可以,一,二,三次,但是在第一次提交后我收到错误消息。
-
是的,我已经猜到了,但这对我来说只是一个细节。原因很清楚,表单的 JSF 视图状态未在提交响应时更新。因此解决方案很明显:确保表单的 JSF 视图状态在提交响应时更新。但是我无法从头顶回答确切的解决方案,因为您基本上不是直接使用 JSF,而是尝试使用一些自定义 HTML/CSS/JS 来解决它。
-
问题是我在关闭对话框之前用来清理字段的 JS:
$(this).find("input").val("");它正在将表单中的输入隐藏 javax.faces.ViewState 设置为 null。<input type="hidden" name="javax.faces.ViewState" value="" />谢谢@BalusC