2011-02-18 277 views
-1

此頁面在newwindow中打開。 我有一個文本框和兩個按鈕(h:commandbutton和a4j:commandButton)。防止默認操作

我將(設置)光標焦點移動到文本字段中。

我的問題是,我從文本框命中輸入按鈕,然後自動調用h:comandButton動作並關閉新窗口。如何避免這一點。

但是,我需要的,當我按下回車鍵,將光標移動焦點到A4J:的commandButton

<f:view> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <script type="text/javascript"> 

      function a4jButtonClick() 
      { 
       alert("A4J Command Buton clicked..."); 
      } 
     </script> 

    </head> 
    <body> 
     <h:form id="sampleForm"> 
      <rich:panel id="samplePanel"> 

      <h:outputText value="User Name : "/> 
      <h:inputText/> 

      <h:commandButton value="Closing-CommandButton" 
          onclick="javascript:window.close();return false;"/> 

      <a4j:commandButton value="A4JCommandButton" onclick="a4jButtonClick()"/>      

      </rich:panel> 
     </h:form> 
    </body> 
</html> 
</f:view> 

如果我打從textfiled回車鍵,我想調用腳本警報(「A4J Command Buton clicked ...「);

幫幫我。 提前致謝。

回答

1

嘗試添加回在onclick處理錯誤:

<h:commandButton value="HCommandButton" onclick="hButtonClick();return false;"/> 
<a4j:commandButton value="A4JCommandButton" onclick="a4jButtonClick();return false;"/> 

但是當你按下按鈕,你的表單不會被提交。

+0

感謝您的回覆。現在我更新我的問題。我使用return false。儘管窗戶關閉。 – Eswar 2011-02-18 06:19:26

0

當您按鍵盤上的Enter/Return鍵時,標記中的第一個按鈕被激活。

所以你需要在標記更改按鈕的順序,以這樣的:

<a4j:commandButton value="A4JCommandButton" onclick="a4jButtonClick()"/> 
<h:commandButton value="Closing-CommandButton" onclick="javascript:window.close();return false;"/> 

記住,你仍然可以他們的風格是在原來的秩序,使設計不更改。