我正在使用JSF2和Richfaces 4的Java EE应用程序。我们决定使用模态窗口进行一些交互,我们选择了带有h:form的Jquery UI Dialog,因为我们已经在使用Jquery UI这个项目。
正确打开对话框,并提交表单,使用h:commandButton和a4j:ajax进行提交。 h:commandButton保持隐藏状态,并由对话框按钮触发。
一切看起来都很完美,但对话框/表单只能运行一次。如果我关闭并打开对话框而不刷新页面,我会在提交表单时收到消息:
javax.faces.application.ViewExpiredException: viewId:/frontend/inicial.xhtml - /frontend/inicial.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>
JS创建jQuery UI对话框:
$("#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);
}
});
有没有人知道我只能在一次拨号中执行该表单的原因,并且在第二次我收到消息“视图无法恢复”?
答案 0 :(得分:0)
问题是我在关闭对话框之前用来清除字段的JS:
$(this).find("input").val("");
它将输入隐藏的javax.faces.ViewState设置为null。
<input type="hidden" name="javax.faces.ViewState" value="" />