簡體   English   中英

JSF中的頁面加載調用命令按鈕

[英]onpage load call commandbutton in JSF

我正在嘗試在頁面加載時將值設置為隱藏變量並調用以將該值發送到ManagedBean.Onpage加載時我可以設置值並調用commandButton並在托管bean中獲取值,但是它會無條件循環並執行更多操作一旦。 這是我的代碼。

<script>
window.onload = setId ;

function setId(){
var facId = document.getElementById('formname:bId').value;
document.getElementById('formname:nameId').value = facId;
document.getElementById('formname:buttonId').click();
}
</script>

<h:inputText id="nameId" value="#{bean.nameId}"></h:inputText>
<h:commandButton id="buttonId" value="fId" action="#{bean.init()}" />

在頁面上連續加載其調用按鈕。

h:commandButton提交表單,並導致整個頁面重新加載,由於該腳本再次執行,因此重復此過程。 為了避免這種增加

  <h:commandButton id="buttonId" value="fId" >  
      <f:ajax event="click" listener="#{bean.init()}" />  
  </h:commandButton>  

希望這可以幫助

暫無
暫無

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

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