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.
| Online: | 30 Members of 4507 |
| Forum: Seam Users |
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: | |||
|---|---|---|---|
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. |
|||
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 |
|||
Ah, yes. I guess an API like (2) would be ok - file a JIRA FR. Read about how to report a bug. |
|||
pawel.wrzesz.cz/blog