On 29-Sep-08, at 6:53 PM, David Holt wrote:

I display a different page Component for a user depending on what group they belong to. On each page there is a WOSwitchComponent. There are navigation buttons to reset the selection in a WOSwitchComponent.

I am using a pageName string that is dynamically generated by adding the group code to the component name.

I would prefer the action method names to remain constant so that I can use the same ERXNavigationMenu labels no matter what group the user belongs to.

To do this, it would seem that I need to dynamically cast the WOComponent that is returned when the button is clicked. Is there a way to do this? Here is what I have tried and trying to setSelection(String) on a generic WOComponent generates a compiler error (obviously).

As an example setSelection(String) is a method on the Main1 component and a typical action method to move between sections looks like this:

        public WOActionResults toSectionA() {
                WOComponent nextPage = null;
ERXNavigationManager .manager().navigationStateForSession(session()).setState(new NSArray(new Object[] {
                                "my page",
                                "A. Background"
                }));
String usergroupcodestring = _currentUser.surveyGroup().codeNumber();
                String pageName = "Main"+usergroupcodestring;
                String partSelectionString = "Section"+usergroupcodestring;
                
                nextPage = context().page().pageWithName(pageName);
                nextPage.setSelection(partSelectionString+"A");
                return nextPage;
        }


How do I cast nextPage to the Main1 class so that it can set the selection for the switch component? Or is there a way to setSelection() after the nextPage has been returned and the Class is known?

Use KVC, ie:

        nextPage.takeValueForKey(partSelectionString+"A", "selection");

;david

--
David LeBer
Codeferous Software
'co-def-er-ous' adj. Literally 'code-bearing'
site:   http://codeferous.com
blog:   http://davidleber.net
profile:        http://www.linkedin.com/in/davidleber
twitter:        http://twitter.com/rebeld
--
Toronto Area Cocoa / WebObjects developers group:
http://tacow.org




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to