Re: conversion error repopulation not working

2012-05-31 Thread Łukasz Lenart
I'll add this code as an additional example, but I'm wondering is it a
good way to base on fieldErrors as they can be also populated by
validators.
Maybe adding ConversionAware interface with specific method to
populate conversionErrors would be better ?

Then I could extend ActionSupport with getFormatted() but base on
conversionErrors instead. WDYT ?


Regards
-- 
Łukasz
mobile +48 606 323 122 http://www.lenart.org.pl/
Warszawa JUG conference - Confitura http://confitura.pl/

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: conversion error repopulation not working

2012-05-31 Thread J. Garcia
This works nicely.
Thanks!

Cheers,
J.

On Thu, May 31, 2012 at 3:07 PM, Łukasz Lenart  wrote:

> Can be reduced to this:
>
> public String getFormatted(String key, String fieldName, List args) {
>   if (getFieldErrors().isEmpty()) {
>   return getText(key, args);
>   } else {
>   return
> ActionContext.getContext().getValueStack().findString(defaultValue);
>   }
> }
>
> and it works just for one field ;-) There should check if there is a
> error for given fieldName
>
>
> Regards
> --
> Łukasz
> mobile +48 606 323 122 http://www.lenart.org.pl/
> Warszawa JUG conference - Confitura http://confitura.pl/
>


Re: conversion error repopulation not working

2012-05-31 Thread Łukasz Lenart
Can be reduced to this:

public String getFormatted(String key, String fieldName, List args) {
   if (getFieldErrors().isEmpty()) {
   return getText(key, args);
   } else {
   return
ActionContext.getContext().getValueStack().findString(defaultValue);
   }
}

and it works just for one field ;-) There should check if there is a
error for given fieldName


Regards
-- 
Łukasz
mobile +48 606 323 122 http://www.lenart.org.pl/
Warszawa JUG conference - Confitura http://confitura.pl/

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: conversion error repopulation not working

2012-05-31 Thread Łukasz Lenart
2012/5/31 J. Garcia :
> The short-circuiting option sounds good. There could even be a specially
> dedicated getText() (or alternative method name) for this scenario, which
> should be rather frequent in l10n apps.

Not the best solution, but works:



and in ExampleAction (or any other base action class):

public String getFormatted(String key, String defaultValue, List args) {
TextProviderFactory tpf = new TextProviderFactory();
if (container != null) {
container.inject(tpf);
}
TextProvider tp = tpf.createInstance(getClass(), this);
if (getFieldErrors().isEmpty()) {
return tp.getText(key, args);
} else {
return
ActionContext.getContext().getValueStack().findString(defaultValue);
}
}


Regards
-- 
Łukasz
mobile +48 606 323 122 http://www.lenart.org.pl/
Warszawa JUG conference - Confitura http://confitura.pl/

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: conversion error repopulation not working

2012-05-31 Thread Łukasz Lenart
2012/5/31 Łukasz Lenart :
> Ok, looks like a problem is with getText() in jsp but I think there is
> no other way ... you can use String instead and check for errors in
> getter/setter but I'm not sure if it does the trick

The problem is a bit complicated here as getText(String key, String[]
args) accepts only strings, so getText("format.number", {user.born})
is converted to call getText("{0,number,#,##0.#}", String[]{"1980"}) -
notice that all params are Strings - and then MessageFormat throws
exception as it cannot format String as a Number.

Right now I don't see any bright solution, I think there should be a
short-circuit when conversion error occurs to  skip evaluating
getText() expression and just return what was specified as a key /
name property.


Regards
-- 
Łukasz
mobile +48 606 323 122 http://www.lenart.org.pl/
Warszawa JUG conference - Confitura http://confitura.pl/

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: conversion error repopulation not working

2012-05-31 Thread Łukasz Lenart
2012/5/31 J. Garcia :
> Ok. Sorry.
> Fixed the example to match the real situation. Prepare() will only execute
> now if the request is a get method.

Ok, looks like a problem is with getText() in jsp but I think there is
no other way ... you can use String instead and check for errors in
getter/setter but I'm not sure if it does the trick


Regards
-- 
Łukasz
mobile +48 606 323 122 http://www.lenart.org.pl/
Warszawa JUG conference - Confitura http://confitura.pl/

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org