Jan Stary wrote:
> :Elementry, my dear Watson.
> :
> :public class Hans implements Component, Composable, Disposable {
> : ComponentManager manager;
> : DataSourceComponent datasrc;
> :
> : public void compose(ComponentManager manager) {
> : if (this.manager == null) {
> : this.manager = manager;
> : ComponentSelector selector = (ComponentSelector) this.manager.lookup(
> : DataSourceComponent.ROLE + "Selector");
> :
> : datasrc = (DataSourceComponent) selector.select("documents");
> : }
> : }
> :}
> :
>
> Firstly, thank you for guiding a stupido on the way through
> the Avalon area.
>
> 1.
>
> Now that my classes compile, thanks to Mr. Holmes, I'm in
> the mood to use them ...
>
> When writing a JSP page, how should I call the Hans.compose(),
> I mean, what ComponentManager should I provide as an argument?
> The class has it's own manager, so I tried suplying null,
> which (surprise!) throws NullPointerException.
> I suppose I have to call hans.compose() before I can use
> the datasrc (and actually retrieve data from DB).
>
> - cut ---
> <%@ page language="java" session="true"
> import="org.apache.bizserver.docs.*" %>
>
> <jsp:useBean id="container" scope="page"
> class="org.apache.bizserver.docs.ContainerComponent"/>
>
> <jsp:useBean id="hans" scope="page"
> class="org.apache.bizserver.docs.Hans"/>
>
> <pre>
> initializing container ... <% container.initialize(); %> done
> user class composing components ... <%-- hans.compose(null); --%> done
> disposing container ... <% container.dispose(); %> done
> </pre>
First, you should not create and destroy a Component manager for
*each* request. This is not only wasteful, but it degrades performance
and makes you loose all benefit of pooled connections.
Bind a ComponentManager to JNDI, and use it to look up the ComponentManager.
That way, the CM is created once for the life of the webapp.
>
> - cut ---
>
>
> 2.
>
> I use scope="page", because when using scope="session",
> reloading the page says
>
> javax.servlet.ServletException: Could not get class
>
> and the log gently wheeps
>
> ERROR 10111 [casopis ] (): Could not get class
> org.apache.avalon.excalibur.component.ExcaliburComponentSelector for role
> org.apache.avalon.excalibur.datasource.DataSourceComponentSelector on
> configuration element datasources
> org.apache.avalon.framework.component.ComponentException: Cannot add components
> to an initialized ComponentManager
>
> What's a natural way to solve this - conditionally include a
> 'container.initialize()'ing code on the top of every page?
See my solution above. You may want to have a Servlet to initialize your
environment with the init() method, and all requests resolved by your
JSPs. I am not as familiar with JSP, but you can have a Servlet load
on startup, taking care of the initial CM.
--
"They that give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety."
- Benjamin Franklin
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>