Readonly Property and Editing

Readonly Property and Editing

Old forum URL: forums.lhotka.net/forums/t/3522.aspx


culprit posted on Wednesday, September 12, 2007

I am looking for the best way to have the UI handle enabling/disabling (or readonly/ not readonly) text boxes for ReadOnly properties in a BusinessBase class. For now I have created these rules in the AuthoriationRules section but it seems like there might be a better/cleaner way:

AuthorizationRules.AllowWrite("BillTo", "CANNOTEDIT")

Where there is no "CANNOTEDIT" group.

Thank You,

Rob

ajj3085 replied on Wednesday, September 12, 2007

Well, you can do that, use a group name that won't exist.

Alternately (and more clean, IMO), would be to override CanWriteProperty and test for the properties which should only be readonly.  If you hit one, simply return false always.  Same effect, just a different method for doing so.  It may be quicker too, since there's no need to look through any dictionaries to determine if the user can or cannot write the property.

HTH
Andy

culprit replied on Wednesday, September 12, 2007

Thanks to everyone for the suggestions. I think I will go with overriding the CanWriteProperty as I want to keep everything as simple as possible and easily move to newer versions of the framework.

Rob

DansDreams replied on Thursday, September 13, 2007

Are we talking about properties that are always ReadOnly, or a case where its determined by the user's permissions or other circumstances?

If it's the former, then the property is readonly by not having a set accessor.  That is discoverable via reflection.  I modified the ReadWriteAuthorization to do so.

triplea replied on Wednesday, September 12, 2007

Not sure if this is cleaner but you could add an attribute to all your read-only properties. Make sure you extend from a custom base class or implement an interface that is smart enough to detect if the property exists and return a bool to your custom control, notifying it if it should be read only or not. That would make the code a bit more readable I guess...

ReadOnlyChild replied on Wednesday, September 12, 2007

how does this sound....

going into the readWriteAuthorization component and adding a new extended property to say to always return "ReadOnly" | false so this "feature and be applied at design time and outside the BO code...

so this would rely on UI, seems that's the approach culprit is looking for,
an side-effect of this would be accessing the BO by other means than your UI will not contain this authorization mechanism, so maybe this is NOT what you are expecting...

Copyright (c) Marimer LLC