2011-02-18 266 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;"/> 

记住,你仍然可以他们的风格是在原来的秩序,使设计不更改。