-
1. Re: Access Component Name
pmuir May 14, 2008 1:58 PM (in response to wrzep)Put a method like
public Component getComponent() { return null; }
and it will magically return the Component for your Seam component.
-
2. Re: Access Component Name
wrzep May 14, 2008 3:37 PM (in response to wrzep)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
-
3. Re: Access Component Name
pmuir May 14, 2008 6:31 PM (in response to wrzep)Ah, yes.
I guess an API like (2) would be ok - file a JIRA FR.
-
4. Re: Access Component Name
coralfe May 15, 2008 4:40 PM (in response to wrzep)Try
Classname whatever = (Classname) Component.getInstance("name");
-
5. Re: Access Component Name
durdina Mar 30, 2011 2:27 PM (in response to wrzep)In seam 2.2.0, there are some undocumented builtin components on method scope (undocumented as well).
org.jboss.seam.this
org.jboss.seam.method
org.jboss.seam.parameters
org.jboss.seam.componentSo this prints out component name of current instance:
log.info("My name is #{org.jboss.seam.component.name}");
-
6. Re: Access Component Name
markwigmans Mar 31, 2011 3:18 PM (in response to wrzep)Component.getComponentName(getClass())
works for me