Print Page | Close Window

Localization Clarification

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2442
Printed Date: 13-May-2026 at 12:55am


Topic: Localization Clarification
Posted By: yimbot
Subject: Localization Clarification
Date Posted: 15-Jan-2011 at 5:28am
Hi,
 
I am only new to DevForce and relatively new to Silverlight, so please excuse my ignorance...
 
I am encountering an issue whereby my customised validation messages are not displaying in the UI.
 
A breif rundown of the steps I have taken so far:
 
  • New Resources File (ValidationErrorResources) created in the server side project with custom messages
  • Resources file added as link to client (silverlight) project (interstingly, the heirarchy of Designer.cs under resx does not show)
  • Custom properties class set up as per the following link using a 'Buddy Class'
  • http://drc.ideablade.com/xwiki/bin/view/Documentation/Verify_MetadataType - http://drc.ideablade.com/xwiki/bin/view/Documentation/Verify_MetadataType
  • Added as Link the Class file to Silverlight Project
  • In the constructor for my ViewModel, I have instanciated a new MyApplicationEntities Mgr
  • I have a Validate() method in the ViewModel which is called before executing the Save.
  • The validate method is:

private bool Validate()

{

Mgr.VerifierEngine.ErrorsResourceManager = ValidationErrorResources.ResourceManager;

var verifierResults = Mgr.VerifierEngine.Execute(this.Account);

return (!this.HasErrors && !verifierResults.HasErrors);

}

 

Code compiles fines and executes fine, but my custom messages never diplay, I only get 'Name is Required' or similar which comes from the fallback resources.

I do not really require real-time validation or complex rules, but a customised message would be nice.
 
Not sure where I am going wrong here, so a point in the right direction would be appreciated!



Replies:
Posted By: yimbot
Date Posted: 17-Jan-2011 at 3:27pm
Bump ;)


Posted By: DenisK
Date Posted: 18-Jan-2011 at 7:37pm
Hi yimbot;

Could you post me the generated code attributes decorating your Name property? For example,

#region LastName property

    /// <summary>Gets or sets the LastName. </summary>
    [Bindable(true, BindingDirection.TwoWay)]
    [Editable(true)]
    [Display(Name="LastName", AutoGenerateField=true)]
    [IbVal.StringLengthVerifier(MaxValue=30, IsRequired=true, ErrorMessageResourceName="Employee_LastName")]
    [DataMember]
    public string LastName {
      get { return PropertyMetadata.LastName.GetValue(this); }
      set { PropertyMetadata.LastName.SetValue(this, value); }
    }

 #endregion LastName property


Posted By: yimbot
Date Posted: 19-Jan-2011 at 12:41am
Thanks Denisk,
 

#region Name property

/// <summary>Gets or sets the Name. </summary>

[Bindable(true, BindingDirection.TwoWay)]

[Editable(true)]

[Display(Name="Name", AutoGenerateField=true)]

[IbVal.StringLengthVerifier(MaxValue=50, IsRequired=true, ErrorMessageResourceName="Account_Name")]

[DataMember]

public string Name {

get { return PropertyMetadata.Name.GetValue(this); }

set { PropertyMetadata.Name.SetValue(this, value); }

}

#endregion Name property



Posted By: DenisK
Date Posted: 19-Jan-2011 at 12:23pm
Hi yimbot;

I'm assuming the way you trigger the validation error "Name is required" is by assigning empty or null string to the Name property. The custom message, in this case, won't be triggered because if you look at the following line:

[IbVal.StringLengthVerifier(MaxValue=50, IsRequired=true, ErrorMessageResourceName="Account_Name")]

The ErrorMessageResourceName, "Account_Name" is assigned to a StringLengthVerifier so the custom message will only be displayed if the input string exceeds the MaxValue.

The following implementation using buddy class,

public class EmployeeMetadata {
      /// <summary>
      /// Override Name to make it required.
      /// </summary>
      [RequiredValueVerifier(IsRequired = true, ErrorMessageResourceName = "Account_Name")]
      public static string Name;
    }

will, unfortunately, not work as well. It's possibly a bug and I'm going to confirm it. 

For the time being, you can use the "global" ErrorMessageResourceName located in the fallback resources. For example, to customize all RequiredValueVerifier, you can use the following ErrorMessageResourceName:

<data name="VerifierRequired" xml:space="preserve">
    <value>{0} is required</value>
  </data>

inside your custom message resources:

CustomErrorMessages.resx

Name = VerifierRequired
Value = Some customized message for {0} property

Please see  http://drc.ideablade.com/xwiki/bin/view/Documentation/Verify_Localization - http://drc.ideablade.com/xwiki/bin/view/Documentation/Verify_Localization  to see the complete ErrorMessageResouceName in the fallback resources.

Hope this helps. Let me know if something is not clear for you.


Posted By: yimbot
Date Posted: 20-Jan-2011 at 1:05am
Thanks again DenisK,
 
Yes, you are correct. I am looking to override the message for the RequiredValueVerifier. It is a shame if I cannot do it, but at least I will not waste any more time attempting it.
I don't really see any value in altering the "global" ErrorMessageResourceName as it will affect every field and it for that purpose, the message is fine.
 
The only way I could think to do it is to change the EDM so that it is not required, but I am not really comfortable with lowering that defence.
 
Any other ideas welcomed.
 
Cheers.


Posted By: DenisK
Date Posted: 21-Jan-2011 at 10:21am
Hi yimbot;

I've got some updates regarding the override of validation attributes using a metadata buddy class.

You can override your validation attributes but before it can be used, you need to regenerate your model first so that the code generation can replace the old validation attributes with your new validation attributes on the property.

This will be available as of 6.0.8 release.

Hope this helps.


Posted By: yimbot
Date Posted: 21-Jan-2011 at 5:06pm
Thanks, I look forward to the release.

Do you know if the implementation I have described above will work as it is?


Posted By: DenisK
Date Posted: 21-Jan-2011 at 5:29pm
It should if you have override the validation attributes using the metadata buddy class and regenerated your code.



Print Page | Close Window