Note that there are some explanatory texts on larger screens.

plurals
  1. POError in Spring MVC Custom EL Function to Format String
    primarykey
    data
    text
    <p>I am using Spring and building a web app. I am creating a custom EL Function and I am trying to format a phone number which is a String from 1234567890 to 123-456-7890 output.</p> <p>I tested the method 'phoneFormat' in a standalone java application and passed a string, ex "3101234567", and it correctly formatted it. When I use it in phones.jsp, I am passing 'phone.number' <strong>Can I pass phones.number the way I did - ${myTags:phoneFormat(phone.number)} ?</strong></p> <p>You can see below the files I am working with. <strong>Do you see anything wrong that prevents this from working?</strong> When I load that page, it currently does not display the Phone number at all.</p> <p><strong>/StudentWebMVC/src/main/webapp/WEB-INF/views/personal/phones.jsp</strong> This is a portion of the file where I output the phone number</p> <pre><code>&lt;c:otherwise&gt; &lt;div&gt; &lt;%@ taglib prefix="myTags" uri="/WEB-INF/tags/functions.tld" %&gt; ${myTags:phoneFormat(phone.number)} *this is how I am trying to format the phone number to 123-456-7890 output* &lt;%-- ${phone.number} --%&gt; *this is how it is currently, it outputs the number to the screen* &lt;/div&gt; &lt;c:if test="${phone != null &amp;&amp; type == 'personal' }"&gt; &lt;div&gt;Send emergency text messages: &lt;spring:message code="studentContact.emergency.notification.${phone.notificationFlag}" /&gt;&lt;/div&gt; &lt;/c:if&gt; &lt;/c:otherwise&gt; </code></pre> <p><strong>/StudentWebMVC/src/main/webapp/WEB-INF/functions.tld</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;taglib 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" version="2.1"&gt; &lt;display-name&gt;phoneFormatUtil&lt;/display-name&gt; &lt;tlib-version&gt;1.0&lt;/tlib-version&gt; &lt;short-name&gt;myPhoneFormat&lt;/short-name&gt; &lt;uri&gt;/StudentWebMVC/src/main/webapp/WEB-INF/tags/functions.tld&lt;/uri&gt; &lt;function&gt; &lt;name&gt;phoneFormat&lt;/name&gt; &lt;function-class&gt;/StudentWebMVC/src/main/java/edu/dt/studentweb/mvc/utils/PhoneFormatUtil.phoneFormat&lt;/function-class&gt; &lt;function-signature&gt;java.lang.String phoneFormat(java.lang.String)&lt;/function-signature&gt; &lt;/function&gt; &lt;/taglib&gt; </code></pre> <p><strong>/StudentWebMVC/src/main/java/edu/dt/studentweb/mvc/utils/PhoneFormatUtil.java</strong></p> <pre><code>public final class PhoneFormatUtil { static String exStr; public static java.lang.String phoneFormat(java.lang.String str) { MaskFormatter mf; try { mf = new MaskFormatter("###-###-####"); mf.setValueContainsLiteralCharacters(false); exStr = mf.valueToString(str); } catch (ParseException e) { e.printStackTrace(); } return exStr; } } </code></pre> <p>Thanks in advance for your help!</p>
    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. 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