Re: Access bindings at runtime
Re: Access bindings at runtime
- Subject: Re: Access bindings at runtime
- From: David Griffith <email@hidden>
- Date: Tue, 03 Feb 2004 23:55:28 +0100
Ok, to use your example:
The name of the WOString below is DateTitle. Perfect. I want to take the
name of the WOString (i.e. DateTitle), as that is a logical name that is
recognisable when looking at the WOComponent in design mode, and I want to
combine that with a Language setting (say from the session or from a user
selected language option from the DB) which is for example 'en' for english.
I then want to lookup DateTitle in the database, returning the resulting
string to be displayed in English in this case, or whatever language.
So, if I was to describe it in steps:
Create a WOString in the WOComponent called DateTitle.
Bind a method called getDisplayString to it.
getDisplayString would need access to the name of the current Dynamic
Element being processed, i.e. In this case DateTitle.
A language setting, for example 'en' as chosen by the user held in a
variable called currentLanguage.
GetDisplayString looks up the database for a record which matches DateTitle
and 'en' and returns the relevant string for the relevant language.
The string is passed back to the binding and displayed in the WOComponent.
This would allow me to display all the relevant strings on the WOComponent
in the correct language using one method. If I could get access to the name
of the current element. Which apparently I can't.
Hopefully this makes sense, although I'm sure you'll tell me it's a load of
rubbish ;-)
Bear in mind, I'm pretty new to WO.
Regards,
Dave.
P.s. Looking at the example below, at first I didn't really understand it.
Like I said, I don't really understand how the WO Localisation works. Where
you have put 'session.localizedString.todaysDateIs' - is 'todaysDateIs' like
a placeholder or identifier for the string to be looked up? That's
basically what I am looking for. And by implementing 'stringInLocale' to
search in the database, is this intended to search the database instead of
the localised.strings file? If so, how does
'session.localizedString.todaysDateIs' pass the value to the method in the
session? I.e. The 'key'
> I'm still a little confused on how you want this to work. Maybe an
> example will help me. Let's imagine a string:
>
> DateTitle : WOString {
> value = "Today's date is";
> }
>
> I'm not clear on what binding you want, or what you are going to do
> with it. I would start by looking at something like this:
>
> DateTitle : WOString {
> value = session.localizedString.todaysDateIs;
> }
>
> Then in session add the method:
>
> public String localizedString(String key) {
>
> String localizedString = null;
> for (int i = 0; localizedString == null && i <
> languages().count(); i++) {
> localizedString = stringInLocale(key,
> languages().objectAtIndex(i));
> }
>
> return localizedString;
> }
>
> And implement stringInLocale to look up the localized version in the
> database (I'd cache it in memory for performance reasons) and return
> null if there is no version.
>
>
> Chuck
>
>
> David Griffith wrote:
>
>> Hi Chuck,
>>
>> I am trying to create a custom localisation technique - I want to identify
>> each dynamic element on the component by name, so that when I bind a
>> variable to a dynamic element, I can get a logical reference to look up the
>> text from a database by cross referencing it with the language.
>>
>> Yes, I know WebObjects has some built in localisation, but from what I have
>> read it is not very flexible. We will be supporting many, many languages
>> and I want to ensure we have full control over it.
>>
>> If you have (or anyone else for that matter has) a better way of doing this,
>> please do feel free to let me know. Obviously there are many rollovers that
>> need localising as well as text elements etc. I also want to be able to
>> update these things via a database rather than directly through the
>> localisation files of WO.
>>
>> Any suggestions are very welcome.
>>
>> Regards,
>> Dave.
>>
>>
>>> What, specifically, is it that you are trying to accomplish by doing
>>> getting such access? It seems that you might be trying to do
>>> something the wrong way...
>>>
>>> Chuck
>>>
>>>
>>> David Griffith wrote:
>>>
>>>> Hi Jonathan,
>>>>
>>>> Having had a closer look, I think that method will only return the bindings
>>>> of the component rather than the bindings of each dynamic element. I'll
>>>> take a look at it more closely - any other suggestions?
>>>>
>>>> Regards,
>>>> Dave.
>>>>
>>>>
>>>>
>>>>> Jonathan,
>>>>>
>>>>> Thanks for that - I should have thought of looking there, still having a
>>>>> little trouble finding my way around WO. I think that's exactly what I
>>>>> was
>>>>> looking for - what I was wondering is, will WO complain if I add a binding
>>>>> to each Dynamic Object called, for example, myName and bind the name I
>>>>> want
>>>>> it to have to that? Like, myName="header". I will try it and see, if it
>>>>> does not complain about 'nonsensical' bindings, I think this will solve my
>>>>> problem.
>>>>>
>>>>> Cheers!
>>>>> Dave.
>>>>>
>>>>>
>>>>>
>>>>>> David Griffith, email@hidden, wrote:
>>>>>>
>>>>>>
>>>>>>> I need to access the name of the element, but from other posts I have
>>>>>>> seen
>>>>>>> apparently that is not possible. So I was wondering if I could bind an
>>>>>>> internal name of my own to a custom binding for each element so that I
>>>>>>> could
>>>>>>> access it at runtime. I need to lookup some data in the db based on
>>>>>>> this
>>>>>>> name.
>>>>>>
>>>>>> I don't fully understand what you're trying to accomplish, but I want to
>>>>>> ensure you know about this method:
>>>>>>
>>>>>> <http://developer.apple.com/documentation/WebObjects/Reference/API/com/we
>>>>>> bo
>>>>>> bjects/appserver/WOComponent.html#bindingKeys()>
>>>>>>
>>>>>> I think this will enable you to discover all of a component's bindings at
>>>>>> runtime.
>>>>>>
>>>>>> .......................................................
>>>>>> Jonathan 'Wolf' Rentzsch http://rentzsch.com
>>>>>> Red Shed Software http://redshed.net (847) 584-7465
>>>>>> PGP: b2af 1a09 f881 ebde c9d6 c4d2 c04f a3c0 3ec5 d5f2
>>>>>>
>>>>>> "better" necessarily means "different"
>>>>>> _______________________________________________
>>>>>> webobjects-dev mailing list | email@hidden
>>>>>> Help/Unsubscribe/Archives:
>>>>>> http://www.lists.apple.com/mailman/listinfo/webobjects-dev
>>>>>> Do not post admin requests to the list. They will be ignored.
>>>>>
>>>>> _______________________________________________
>>>>> webobjects-dev mailing list | email@hidden
>>>>> Help/Unsubscribe/Archives:
>>>>> http://www.lists.apple.com/mailman/listinfo/webobjects-dev
>>>>> Do not post admin requests to the list. They will be ignored.
>>>>
>>>> _______________________________________________
>>>> webobjects-dev mailing list | email@hidden
>>>> Help/Unsubscribe/Archives:
>>>> http://www.lists.apple.com/mailman/listinfo/webobjects-dev
>>>> Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.