Hi David,

On Sep 29, 2008, at 3: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?

You have three choices:

1. Make each page implement a Java interface with setSelection(String) and cast nextPage to this interface 2. Make each page inherit from a WOComponent sub-class with setSelection(String) and cast nextPage to this class 3. Hack and use nextPage.takeValueForKey(partSelectionString+"A", "selection");


Chuck


--
Chuck Hill             Senior Consultant / VP Development

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects






_______________________________________________
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