Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can create a custom function as explained in the following tutorials:</p> <ol> <li><a href="http://anshulsood2006.blogspot.in/2012/03/creating-custom-functions-in-jsp-using.html" rel="nofollow noreferrer">Creating Custom functions in JSP using JSTL</a></li> <li><a href="http://www.noppanit.com/how-to-create-a-custom-function-for-jstl/" rel="nofollow noreferrer">How to create a custom Function for JSTL</a></li> <li><a href="http://www.javaworld.com/javaworld/jw-05-2003/jw-0523-calltag.html?page=2" rel="nofollow noreferrer">Another tutorial</a></li> </ol> <hr> <p><strong>Steps to create a function from the above links:</strong></p> <ol> <li><p>Create a <code>.tld</code> file under <code>/WEB-INF</code>:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"&gt; &lt;tlib-version&gt;1.0&lt;/tlib-version&gt; &lt;short-name&gt;functionalTlds&lt;/short-name&gt; &lt;uri&gt;http://www.rasabihari.com/functionalTlds&lt;/uri&gt; &lt;function&gt; &lt;name&gt;isNumeric&lt;/name&gt; &lt;function-class&gt;com.expressions.Functions&lt;/function-class&gt; &lt;function-signature&gt;boolean isNumeric(java.lang.String)&lt;/function-signature&gt; &lt;/function&gt; &lt;/taglib&gt; </code></pre></li> <li><p>Create a class with the method (the logic of the method is taken from <a href="http://www.zparacha.com/best-way-to-check-if-a-java-string-is-a-number/#.UIVZe0b9di0" rel="nofollow noreferrer" title="Best way to check if a Java String is a Numeric">here</a>, it uses <a href="https://stackoverflow.com/tags/regex/info" title="StackOverflow Tag wiki: Regex">Regular Expression</a>)</p> <pre><code>package com.expressions; /** * * @author rasabihari */ public class Functions { public static boolean isNumeric(String number) { boolean isValid = false; /* Explaination: [-+]?: Can have an optional - or + sign at the beginning. [0-9]*: Can have any numbers of digits between 0 and 9 \\.? : the digits may have an optional decimal point. [0-9]+$: The string must have a digit at the end. If you want to consider x. as a valid number change the expression as follows. (but I treat this as an invalid number.). String expression = "[-+]?[0-9]*\\.?[0-9\\.]+$"; */ String expression = "[-+]?[0-9]*\\.?[0-9]+$"; CharSequence inputStr = number; Pattern pattern = Pattern.compile(expression); Matcher matcher = pattern.matcher(inputStr); if(matcher.matches()){ isValid = true; } return isValid; } } </code></pre></li> <li><p>And then use it in the JSP as:</p> <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt; &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt; &lt;%@taglib uri="http://www.rasabihari.com/functionalTlds" prefix="ftld" %&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;JSP Page&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;c:if test="${ftld:isNumeric('123')}"&gt; &lt;!-- ... do something ... This block will run --&gt; &lt;/c:if&gt; &lt;/body&gt; &lt;/html&gt; </code></pre></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload