jsp - JSTL Formatting: Confusing IllegalargumentException -


i have object formatobject in session scope, member of type simpledateformat sdf based on pattern "dd.mm.yyyy hh:mm:ss".

i want use jstl formatting tag library format output:

<fmt:formatdate value="${dataobject.date}" pattern="${formatobject.sdf}"/> 

this gives me following exception:

org.apache.jasper.jasperexception: java.lang.illegalargumentexception: illegal pattern character 'j' 

when try following, works expected:

<fmt:formatdate value="${dataobject.date} pattern="dd.mm.yyyy hh:mm:ss"/> 

confusing ... have idea?

the pattern attribute has refer string representing pattern, not concrete simpledateformat instance constructed around pattern.


unrelated concrete problem, simpledateformat not threadsafe, yet attempt implies it's been created in constructor of formatobject , reused session/application wide. not right. simpledateformat must declared , created on thread local basis (i.e. inside method block). pattern part can constant.

so, all, right:

public class formatter {      private static final string pattern = "dd.mm.yyyy hh:mm:ss";      public string format(date date) { // example. no idea how you're further using it.         return new simpledateformat(pattern).format(date); // create simpledateformat in method local scope. never create instance variable.     }      public string getpattern() {         return pattern;     }  } 

with

<fmt:formatdate ... pattern="#{formatter.pattern}" /> 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -