Hello,

Thank you for your feedback.
I managed to localized my warning, here is how I did, maybe it can help
someone with the same concern: 

public class ValidatorWithWarningOption implements IValidator<String> {

         final private TextField<String> field;
         final private boolean warning;

         public ValidatorWithWarningOption(TextField<String> field,
 boolean warning) {
                 this.field = field;
                 this.warning = warning;
         }

         @Override
         public void validate(IValidatable<String> validatable) {
                 String error = null;

                 if(/*condition for error*/) {
                         error = "ERROR";
                 }

                 if( errors != null ){
                         if( this.warning ){
                                 field.warn( formatError(error) );
                         }else{
                                 field.error( formatError(error) );
                         }
                 }
         }

        private String formatError(String errorKey) {
                String error = field.getString( errorKey );
                error = error.replace( "${label}",
field.getLabel().getObject() );
                return error;
        }
 }


In ValidatorWithWarningOption.properties file: 
ERROR = The field ${label} is not well formatted.




On Wed, 2017-07-05 at 16:04 +0700, Maxim Solodovnik wrote:
> +1 to unify this
> I would expect similar behavior from all 3 (error, warn, info)
> Never used warn BTW
> 
> On Wed, Jul 5, 2017 at 3:56 PM, Martijn Dashorst
> <martijn.dasho...@gmail.com> wrote:
> > Hi Virginie,
> > 
> > Your code doesn't look wrong.
> > 
> > Here's a snippet from one of our applications that validates a social
> > security number. It's a bit less verbose than your example, but seems to
> > work similarly. And you've already used ValidationError so you are aware of
> > its existence.
> > 
> > public class BsnValidator implements IValidator<String>
> > {
> > private static final long serialVersionUID = 1L;
> > 
> > @Override
> > public void validate(IValidatable<String> validatable)
> > {
> > if (!ElfProef.isGeldigSofiNummer(sofinummer))
> > validatable.error(new ValidationError(this));
> > }
> > }
> > 
> > As you can see, we just call validatable.error(new ValidationError(this));
> > This gives Wicket the opportunity to locate the error message in localized
> > resource bundles.
> > 
> > E.g. in our Application_nl.properties we have this line:
> > 
> > BsnValidator=Veld '${label}' bevat geen geldig BSN
> > 
> > As for your second point: it appears that that is a functional omission. I
> > typically would expect this to work for info, warn and error messages in a
> > similar vain. Probably we should fix that in a future release (but would
> > have to consult with the other wicket devs)
> > 
> > For what I'm worth, in our applications we haven't seen the need for
> > warnings using localization and substitutions, so we never encountered this
> > omission.
> > 
> > Martijn
> > 
> > 
> > 
> > 
> > 
> > On Wed, Jul 5, 2017 at 10:30 AM, Virginie Garcin <
> > virginie.gar...@equitativa.com> wrote:
> > 
> > > Hello,
> > > 
> > > I have a field validator. I want to be able to choose if it will be an
> > > error (blocking the action) or a warning (just display a non-blocking
> > > warning).
> > > 
> > > Here is the code I use, that is working except the error/warning is not
> > > localized:
> > > 
> > > 
> > > public class ValidatorWithWarningOption implements IValidator<String> {
> > > 
> > >         final private TextField<String> field;
> > >         final private boolean warning;
> > > 
> > >         public ValidatorWithWarningOption(TextField<String> field,
> > > boolean warning) {
> > >                 this.field = field;
> > >                 this.warning = warning;
> > >         }
> > > 
> > >         @Override
> > >         public void validate(IValidatable<String> validatable) {
> > >                 String error = null;
> > > 
> > >                 if(/*condition for error*/) {
> > >                         error = "The field " +
> > > field.getLabel().getObject() + " is not well formatted.";
> > >                 }
> > > 
> > >                 if( errors != null ){
> > >                         if( this.warning ){
> > >                                 field.warn( error );
> > >                         }else{
> > >                                 field.error( error );
> > >                         }
> > >                 }
> > >         }
> > > }
> > > 
> > > 1/ Am I using the framework properly ?
> > > There might be a better way to do it. Idealy, if it'd exist, I would have
> > > used a method such as validatable.warn(IValidationError error) (like
> > > validatable.error(IValidationError error)), so I would not have to pass
> > > the field itself to the class and I would get proper localized warning, as
> > > I get for errors.
> > > Is there a way to do it ?
> > > 
> > > 
> > > 2/ If I set the error like this:
> > > ValidationError error = new ValidationError( this, "ERROR" );
> > > (with "ValidatorWithWarningOption.ERROR = The field ${label} is not well
> > > formatted." in the properties files)
> > > => For field.error( error ); I get a proper localized message (This call
> > > the method error(IValidationError error) from FormComponent)
> > > => But for field.warn( error ); I don't. As FormComponent has no method
> > > warn, this calls Component.warn(final Serializable message) so there is no
> > > localization handeling at all.
> > > How can I get my warnings localized ?
> > > 
> > > 
> > > Thanks for any help !
> > > 
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> > > For additional commands, e-mail: users-h...@wicket.apache.org
> > > 
> > > 
> > 
> > 
> > --
> > Become a Wicket expert, learn from the best: http://wicketinaction.com
> 
> 
> 
-- 

        
        
                
                        Virginie Garcin

                        Software Developer
                                
                                        T +971 4 405 REIT (+971 4 405 7349) M 
+971 55 381 2983

                                        E virginie.gar...@equitativa.com W 
reit.ae
                                

                                
                                        Equitativa (Dubai) Limited

                                        Index Tower, Office 905, West Entrance, 
DIFC, Dubai, UAE
                                

                        
                        
                                
                        
                
                
                This message, including any attachments may contain 
confidential and privileged material; it is intended only for the person to 
whom it is addressed.
        Its contents do not constitute a commitment by Emirates REIT Management 
(Private) Limited except where provided for in a written agreement.
        Emirates REIT Management (Private) Limited assumes no liability or 
responsibility for the consequences arising out of a delay and/or loss in 
transit of this message, or for corruption or other error(s) arising in its 
transmission and for any misuse or fraudulent use which may be made thereof. If 
you are not the intended recipient, please contact us and abstain from any 
disclosure, use or dissemination. To the extent that this message contains 
recommendations, these are provided on the same basis as Emirates REIT 
Management (Private) Limited's published research and the recipient must have 
regard to all disclosures and disclaimers contained therein.
        Emirates REIT Management (Private) Limited is a wholly owned subsidiary 
of Equitativa Real Estate Limited and is duly licensed and regulated by the 
Dubai Financial Services Authority (DFSA).
                
                
        

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

Reply via email to