You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@beehive.apache.org by Steven Dalton <St...@mswl.com.au> on 2007/03/26 04:35:03 UTC

Programmatically creating controls which access system controls (JDBC)

Hi All,

 

I have a problem I hope someone can help me with:

 

What I'm trying to do is programmatically create controls which access
system controls ie JDBC 

 

I can create the control and I can also access sub controls (non system)
within the parent which are defined declaratively and they work fine.
The problem arises when I try to access a control that requires a
contextual service. IE JDBC.  

 

Is this even possible?

 

I've tried this from an extension of the XmlHttpRequestServlet (doPost
method)

 

The ReceivablesControlImpl is a basic control which references a number
of JDBC controls.  The error is in the method (viewReceivable) that
calls methods on the JDBC  controls.

 

            ReceivablesControlImpl rec = (ReceivablesControlImpl)
java.beans.Beans.instantiate(

 
getClass().getClassLoader(), 

"controls.receivables. ReceivablesControlImpl");

 

 
org.apache.beehive.controls.api.bean.Controls.initializeClient( null,
rec,null );

 

            Receivable r = rec.viewReceivable(1L);

 

gives me:

 

org.apache.beehive.controls.api.ControlException: Control initialization
failure[org.apache.beehive.controls.api.Con

trolException: Contextual service
org.apache.beehive.controls.api.context.ResourceContext is not
available]

        at
org.apache.beehive.controls.runtime.bean.ControlBean.ensureControl(Contr
olBean.java:326)

        at
controls.database.receivables.JdbcReceivablesBean.viewReceivable(JdbcRec
eivablesBean.java:251)

        at
controls.receivables.ReceivablesControlImpl.viewReceivable(ReceivablesCo
ntrolImpl.java:60)

 

Environment:

Tomcat 5.5

Beehive 1.02

 

Help would be much appreciated

 

Thank you,

 

Steven Dalton

 


Re: Programmatically creating controls which access system controls (JDBC)

Posted by Chad Schoettger <ch...@gmail.com>.
Hi Steve,

The reason you are getting the error is because there is not a control
container context available for the JDBC controls to acquire resources
from.

The Beehive distribution includes the ControlFilter servlet filter
which can be used to establish a control context for your servlet and
controls contained within that servlet.

You can find the Java doc for this class at:

http://beehive.apache.org/docs/1.0.2/controls/apidocs/javadoc/org/apache/beehive/controls/runtime/servlet/ControlFilter.html

You'll need to modify you web.xml to include something like:

  <filter>
    <filter-name>ControlFilter</filter-name>
    <filter-class>
       org.apache.beehive.controls.runtime.servlet.ControlFilter
    </filter-class>
  </filter>

  <filter-mapping>
    <filter-name>ControlFilter</filter-name>
    <url-pattern>*/Myservlet*</url-pattern>
  </filter-mapping>

You man also need to include a control context in your instantiate call,

org.apache.beehive.controls.api.bean.Controls.initializeClient( null,
rec, ControlThreadContext.getContext() );


Hope this helps, let me know if still not working.

  - Chad





On 3/25/07, Steven Dalton <St...@mswl.com.au> wrote:
> Hi All,
>
>
>
> I have a problem I hope someone can help me with:
>
>
>
> What I'm trying to do is programmatically create controls which access
> system controls ie JDBC
>
>
>
> I can create the control and I can also access sub controls (non system)
> within the parent which are defined declaratively and they work fine.
> The problem arises when I try to access a control that requires a
> contextual service. IE JDBC.
>
>
>
> Is this even possible?
>
>
>
> I've tried this from an extension of the XmlHttpRequestServlet (doPost
> method)
>
>
>
> The ReceivablesControlImpl is a basic control which references a number
> of JDBC controls.  The error is in the method (viewReceivable) that
> calls methods on the JDBC  controls.
>
>
>
>             ReceivablesControlImpl rec = (ReceivablesControlImpl)
> java.beans.Beans.instantiate(
>
>
> getClass().getClassLoader(),
>
> "controls.receivables. ReceivablesControlImpl");
>
>
>
>
> org.apache.beehive.controls.api.bean.Controls.initializeClient( null,
> rec,null );
>
>
>
>             Receivable r = rec.viewReceivable(1L);
>
>
>
> gives me:
>
>
>
> org.apache.beehive.controls.api.ControlException: Control initialization
> failure[org.apache.beehive.controls.api.Con
>
> trolException: Contextual service
> org.apache.beehive.controls.api.context.ResourceContext is not
> available]
>
>         at
> org.apache.beehive.controls.runtime.bean.ControlBean.ensureControl(Contr
> olBean.java:326)
>
>         at
> controls.database.receivables.JdbcReceivablesBean.viewReceivable(JdbcRec
> eivablesBean.java:251)
>
>         at
> controls.receivables.ReceivablesControlImpl.viewReceivable(ReceivablesCo
> ntrolImpl.java:60)
>
>
>
> Environment:
>
> Tomcat 5.5
>
> Beehive 1.02
>
>
>
> Help would be much appreciated
>
>
>
> Thank you,
>
>
>
> Steven Dalton
>
>
>
>