Help

Controls

PermLinkWikiLink

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Forum: Seam Users Forum ListTopic List
14. May 2008, 12:45 CET | Link

Hi there,

I'd like to access component name programmatically, in a Java method. Is there a way to do this?

There is a org.jboss.seam.Component class, but I don't know how to get its instance for the current component.

It could be useful for logging :)

Cheers, -Pawel

4 Replies:
14. May 2008, 13:58 CET | Link

Put a method like

public Component getComponent() {
   return null;
}

and it will magically return the Component for your Seam component.

 

Read about how to report a bug.

14. May 2008, 15:37 CET | Link

Tricky! :)

It works fine, but there is one major drawback. A call to the getComponent() mehtod must be intercepted (by ClientSideInterceptor or JavaBeanInterceptor as it seems from the code).

So, for example, the following code:

log.info("My name is '" + getComponent().getName() + "'");

would fail with NPE, because getComponent() call to myself is not intercepted.

Thoughts that came to my mind:

1. Thing like EJB3 sessionContext.getBusinessObject() for Seam components would solve the problem with interceptors :)

2. How about API to get current component? Like Component.current()?

-Pawel

14. May 2008, 18:31 CET | Link

Ah, yes.

I guess an API like (2) would be ok - file a JIRA FR.

 

Read about how to report a bug.

15. May 2008, 16:40 CET | Link

Try


Classname whatever = (Classname) Component.getInstance("name");