How to stop page refresh when hit enter button from rich:inputNumberSpinner field?

Posted by eswaramoorthy-nec on Stack Overflow See other posts from Stack Overflow or by eswaramoorthy-nec
Published on 2010-06-09T01:25:34Z Indexed on 2010/06/09 1:32 UTC
Read the original article Hit count: 322

Filed under:
|
|
|
|

Hi,
I use rich:inputNumberSpinner tag.

The problem is :

I set cursor focus to inside of rich:inputNumberSpinner field, then i hit the enter button from my keyboard, that time page will be automatically refresh.

But i don't need page refresh when i hit the enter button from my keyboard.

The code :

spinnerTagTest.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<f:view>
    <html>
       <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
          <title>Spinner Tag Test</title>
       </head>

<body>
      <h:form id="SpinnerForm">
           <rich:panel id="SpinnerPanel">
                <h:outputText value="Input Spinner Tag : "/>
                <rich:inputNumberSpinner id="spinnerField" value="" maxValue="23" 
                                         inputSize="2"/>
           </rich:panel>
      </h:form>
 </body>

I also use rich:hotKey for that inputNumberSpinner field. But Page refreshed.

<rich:hotKey key="return"
             selector="#spinnerField"
             handler="event.stopPropagation();event.preventDefault();
             return false;"/>

And i check anotherway using javasccript, but page refreshed.

The specific tag and javascript is :

<rich:inputNumberSpinner id="spinnerField"  value="" maxValue="23" inputSize="2"
                         oninputkeypress="return stopPageRefresh();"/>

<script type="text/javascript">

    function stopPageRefresh()
    {
        return false;
    }
</script>

Here i use one alert message inside of stopPageRefresh().
But i hit enter button, first page refreshing and then alert message displayed.

Help me about this. Thanks in advance.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jsf