KonaKart Community Forum

Installation / Configuration => Configuration of KonaKart => Topic started by: rula on June 05, 2008, 08:29:50 am

Title: different formats
Post by: rula on June 05, 2008, 08:29:50 am
Hi KonaKarts,

I can't use different date-formats for en_GB and de_DE:

in Messages_en_GB:
date.format=dd/MM/yyyy

in Messages_de_DE:
date.format=dd.MM.yyyy

in debugger:
05-Jun 09:15:00 DEBUG (?:execute:?) Locale set from application = en_GB
05-Jun 09:16:01 DEBUG (?:execute:?) Constants.dateTemplate: dd.MM.yyyy

in stack-trace:
Exception Name = java.text.ParseException
Exception Message = Unparseable date: "01/01/2000"
Exception Stack Trace =
at java.text.DateFormat.parse(Unknown Source)
at com.konakart.actions.CustomerRegistrationSubmitAction.execute(Unknown Source)

After validation this exception occurs!
Why has been the false date-pattern (Constants.dateTemplate: dd.MM.yyyy) for this locale(en_GB) selected?

regards, rula
Title: Re: different formats
Post by: ryan on June 05, 2008, 08:55:07 am
Hi Rula,

If you want to use different formats within the same implementation you need to remove the struts validation from validation.xml since this is fixed to the format specified in validation.xml.

      <constant>
         <constant-name>DATE_PATTERN</constant-name>
         <constant-value>dd/MM/yyyy</constant-value>
      </constant>

Then you must search for all occurrences of Constants.dateTemplate in the action classes. If you take a look at CustomerRegistrationSubmitAction you'll see that the date entered is parsed using the template in the message catalog. If you get an exception at this point because the customer has entered an invalid date, you'll have to trap it and redirect back to the entry form. (i.e. You'll have to do your own error handling rather than using struts validation).

Title: Re: different formats
Post by: rula on June 05, 2008, 09:15:53 am
Hi KonaKards,

I used struts-validator with 3 formsets and according format-pattern:
default formset
en_GB formset
de_DE formset

The struts-validation of the input-values is correct,
the selection of the message-catalog in not correct.

debugger:
05-Jun 10:09:27 DEBUG (?:execute:?) Locale set from application = en_GB

action:
05-Jun 10:10:29 DEBUG (?:execute:?) request.getLocale(): de_DE
05-Jun 10:10:29 DEBUG (?:execute:?) Constants.dateTemplate: dd.MM.yyyy

Why this, I switch the language to en_GB and the request-locale is de_DE.
Is this okay!?

(Sorry, I have to answer later, thanks)

regards, rula

Title: Re: different formats
Post by: ryan on June 05, 2008, 09:39:46 am
Hi,

It looks like Constants.dateTemplate isn't getting updated. In the action classes, try using getResources(request).getMessage("date.format") instead.
Title: Re: different formats
Post by: rula on June 05, 2008, 02:37:03 pm
Hi ryan,

I replaced:

SimpleDateFormat sdf = new SimpleDateFormat(Constants.dateTemplate);

by:
String dateFormat = getResources(request).getMessage(getLocale(request), "date.format");
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);

and it works!

The parseing in the action is correct,
the formating in the jsp in incorrect.

I can't use:
value="<%=kkEng.getDateAsString(cust.getBirthDate())%>"
because this methode works also with the const.dateFormatTemplate

Are there any KonaKart-Tags for this work?

regards, rula


Title: Re: different formats
Post by: ryan on June 05, 2008, 02:46:18 pm
No, not at the moment. I think that the easiest approach is for you to to create your own formatter which can be called from the JSP. Alternatively you could just add the code directly to the JSP (i.e. create the SimpleDateFormat object in the JSP and call the format method.
Title: Re: different formats
Post by: rula on June 06, 2008, 07:28:19 am
Hi ryan,

I used jstl in the jsp to format the date according the locale:

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"   prefix="fmt" %>

<fmt:message var="dateFormat" key="date.format"/>
<fmt:formatDate var="birthDate" value="${cust.birthDate.time}" pattern="${dateFormat}"/>

Now parsing and formating for dates works.

regards, rula
Title: Re: different formats
Post by: rula on June 26, 2008, 09:54:11 am
Hi konakarts,

I have a small i18n problem in konakart client app.
It seems that the fallback locale not works how I image that.

I have these catalogs:
Messages.properties
Messages.properties_de
Messages.properties_es

If I switch the language the locale in sessionScope (for struts and jst) is correct changed to en_GB, de_DE or es_ES, but only the body-tiles were refreshed with the new language, the others stay in the old.

With the fmt:message tag the fallback mechanism seems to be o.k., with the bean-message tag there are
these problems.

If I create a new additional catalog Messages.properties_en, there no problems, but it makes no sense.

regards, rula
Title: Re: different formats
Post by: rula on June 27, 2008, 01:39:56 pm
Hi konakarts,

now I have replaced the bean:message tags by the fmt:message tags and now, locale switches with fallback to the default locale works correct for me. I could not find another solution.

regards, rula