Skip to content

How to use JavaScript paste event to allow numbers in Struts 2 [closed]

I have a textfield which should allow pasting only numbers in Struts 2.

I tried using onPaste attribute in textfield but it throws below exception

org.apache.jasper.JasperException:
 /WEB-INF/**.jsp Attribute onPaste invalid for tag textfield according to TLD

Is there anyway to do above function without paste event?

Answer

Dynamic attributes not allowed in Struts 2.0. You should upgrade to the latest version. Currently 2.3.20 is available.

Struts 2.3.20 is the “best available” version of Struts in the 2.3 series.

onpaste is a HTML attribute to dynamically bind the event handler to the element. But you can also use a jQuery code to do it manually

$("input[type=text]").on("paste", function() {
  return isAllowNu();
});

It will handle paste event for all input text elements. The texfields are generating these HTML tags.