0

我在使用 JSF2 和 Richfaces 4 的 Java EE 应用程序中工作。我们决定使用模态窗口进行一些交互,我们选择了带有 h:form 的 Jquery UI Dialog,因为我们已经在这个项目中使用了 Jquery UI。

对话框正确打开,并提交表单,提交是使用 ah: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" />
                    &#160;
                    <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);
        }
    }); 

有谁知道我只能在拨号中执行表单一次而第二次收到消息“无法恢复视图”的原因?

4

1 回答 1

0

问题是我在关闭对话框之前用来清除字段的 JS:

$(this).find("input").val("");

它在表单中将输入隐藏 javax.faces.ViewState 设置为 null。

<input type="hidden" name="javax.faces.ViewState" value="" />
于 2013-03-23T13:18:09.097 回答