簡體   English   中英

如何使commandButton不重新加載/刷新頁面

[英]How to make commandButton don't reload / refresh the page

實際上,我只有一個輸入,並且我想發送請求而無需重新加載頁面(可能是Ajax)。 我的代碼在下面,但是首先我要說我已經看到了這個問題,並且不能解決我的問題。

以下是我的代碼:

<h:form>
    <div class="form-group">
        <div class="col-md-10">
            <h:inputText styleClass="form-control" id="disciplina" value="#{disciplinaMBean.nome}" valueChangeListener="#{disciplinaMBean.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" action="#{disciplinaMBean.cadastrar}">
                 <f:ajax event="click" execute="@form" render=":meuForm:minhaTabela"/>
            </h:commandButton>
        </div>
    </div>
</h:form>

“渲染”中的內容是更新頁面中的dataTable。

所以,我做錯了什么?

記住,我想要:

  1. 當用戶插入文本並單擊按鈕時,正常發送表單。
  2. 但是在發送請求/表單時,請勿刷新/重新加載頁面。

謝謝!

找到答案:

我在Google中進行搜索,找到了一些解決方案,因此我將所找到的答案用於自己的問題。

以下是我最新的代碼:

<h:form id="inserirDisciplina">
    <h:inputText id="disciplina" value="#{disciplinaMBean.nome}" />
    <h:commandButton value="Adicionar" action="#{disciplinaMBean.cadastrar}">
        <f:ajax event="click" listener="#{disciplinaMBean.cadastrar}"/>
    </h:commandButton>
</h:form>

如果您遇到相同的問題,則可能需要的是在listener屬性內帶有#{yourBean.yourMethod}的標記f:ajax

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM