2

你好吗?

也许现在是一个新手问题。现在我在表单中有一个输入和一个“提交”按钮。当我点击提交时,这不会调用任何方法,这只会打开一个<p:dialog>. 打开此对话框时,未设置输入中的变量,因此我输入的另一个输入不显示任何内容。

查看图片以了解: 点击进入之前

单击“提交”后(Adicionar): 点击进去后 第二张图片必须显示与第一个输入完全相同的值,但正如您所见,这只是显示一个空输入。


现在让我们转到我的代码。

这是我的JSF:

<h:form id="inserirDisciplina">

    <h:inputText styleClass="form-control" id="disciplina" value="#{cursoMBean.nome}"
      valueChangeListener="#{cursoMBean.atualizarListagemPesquisa}">
      // atualizarListagemPesquisa just update the arraylist to be shown in dataTable

        <f:ajax event="keyup" render=":meuForm:minhaTabela" />
    </h:inputText>

    <h:commandButton value="Adicionar" styleClass="btn btn-md btn-success">
        <p:ajax event="click" update=":meuForm:display" render=":meuForm:dialog" oncomplete="PF('insert').show();" onerror="alert('erro');" />
    </h:commandButton>

    <p:dialog id="dialog" header="Inserir Curso" widgetVar="insert" resizable="false" modal="true" width="600" height="500" hideEffect="clip" closeOnEscape="true" focus="enviar">
            <h:panelGrid id="display" styleClass="col-lg-10 center">
                 <label for="nome">Nome:</label>
                 <p:inputText styleClass="form-control adicionar" id="nome" value="#{cursoMBean.nome}" />
             </h:panelGrid>

                ...

MBean:

private String nome;

public String getNome() {
    return nome;
}

public void setNome(String nome) {
    this.nome = nome;
}

编辑(新视图):

<h:form id="inserirDisciplina">
    <div class="form-group">
        <div class="col-md-10">
            <h:inputText styleClass="form-control" id="disciplina" value="#{cursoMBean.nome}" valueChangeListener="#{cursoMBean.atualizarListagemPesquisa}">
                <f:ajax event="keyup" render=":meuForm:minhaTabela" />
            </h:inputText>
        </div>
        <div class="col-md-2">
            <h:commandButton value="Adicionar" styleClass="btn btn-md btn-success" process="disciplina" partialSubmit="true">
                <p:ajax event="click" update=":meuForm:display" render=":meuForm:dialog" partialSubmit="true" process="disciplina" oncomplete="PF('insert').show();" onerror="alert('erro');" />
            </h:commandButton>
        </div>
    </div>
</h:form>

<p:messages autoUpdate="true" />

<p:dialog id="dialog" header="Inserir Curso" widgetVar="insert"
                resizable="false" modal="true" width="600" height="500"
                hideEffect="clip" closeOnEscape="true">

<h:form>
    <h:panelGrid id="display" styleClass="col-lg-10 center" style="margin-top: 10px; margin-bottom: 15px;">
        <label for="nome">Nome:</label>
        <p:inputText styleClass="form-control adicionar" id="nome" value="#{cursoMBean.nome}">

        </p:inputText>
    </h:panelGrid>

    <h:panelGrid styleClass="col-lg-10 center">
        <p:columnGroup>
            <label for="disciplinas">Disciplinas do Curso:</label>
            <h:selectManyCheckbox style="margin-bottom: 40px;" id="disciplinas" value="#{cursoMBean.listaDisciplinasDoCurso}" converter="omnifaces.SelectItemsConverter">
                <f:selectItems value="#{cursoMBean.listaTodasDisciplinas}" var="disciplina" itemValue="#{disciplina}" itemLabel="#{disciplina.nome}" />
            </h:selectManyCheckbox>
        </p:columnGroup>
    </h:panelGrid>

    <h:panelGrid styleClass="col-lg-10 center">
        <p:columnGroup>
            <h:commandButton id="enviar" styleClass="btn btn-lg btn-success pull-right" value="Adicionar" action="#{cursoMBean.cadastrar}">
                    <f:ajax event="click" execute="@form" onevent="insert.hide()" render=":meuForm:minhaTabela" listener="#{cursoMBean.cadastrar}" />
            </h:commandButton>
        </p:columnGroup>
    </h:panelGrid>
</h:form>
</p:dialog>

我做错了什么?

4

1 回答 1

0

为按钮尝试以下代码:

<p:commandButton value="Adicionar" styleClass="btn btn-md btn-success"
   process="disciplina" partialSubmit="true" update=":inserirDisciplina:display"
   oncomplete="insert.show();" onerror="alert('erro');">
</p:commandButton>
于 2013-11-15T10:12:06.423 回答