On 30/09/2008, at 7:26 AM, David Holt wrote:

Is it possible to use a variable to replace "Component" in the pageWithName(Component.class.getName()); syntax?

There's a few options, yes.
a) the one Lon mentioned -- but beware that it will be slow. Class.for is a bottleneck if used a lot. But you can overcome this by keeping a Map<String,Class>.

b) If they're always in the same package, you can bypass the lookup.
String fullName = Main.class.getPackage().getName() + ".Main" + userGroupCodeString;
return pageWithName(fullName);

c) create a component that dynamically uses a differing template. Instantiate this component with and utilise WOSwitchComponent in it's html/wod
        java:
        protected String componentNameSuffix() {
                return session().currentUser().group().code();
        }

        protected String componentBaseName() {
                return "Main";
        }

        public String componentName() {
                return componentBaseName() + "." + componentNameSuffix();
        }

Now either do:
        html:
        <wo:WOSwitchComponent WOComponentName = "$componentName"/>

or the following (which won't require a separate Java file per component... not recommended unless really useful :-)
        java:
        protected String _templateName()
        {
                return componentName();
        }


For example how would I change the code below to the syntax above?

String usergroupcodestring = session.currentUser.group().code();
String pageName = "Main"+usergroupcodestring;
return pageWithName(pageName);

The following doesn't work.

String usergroupcodestring = session.currentUser.group().code();
String pageName = "Main"+usergroupcodestring;
return pageWithName(pageName.class.getName());

Thanks,
David _______________________________________________
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/lachlan.deck%40gmail.com

This email sent to [EMAIL PROTECTED]

with regards,
--

Lachlan Deck



_______________________________________________
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