Call datasource in external java method
<p>I want to split managed bean into several files because the source code is repeated several times.</p>

<p>This is the external Java method which I want to put into external file:</p>

<pre><code>public class CalcWeight implements Serializable
{

    // Call the Oracle JDBC Connection driver as service
    @Resource(name = "jdbc/Oracle")
    // Data source
    private DataSource ds;

    public float TotalDCWeightCalc(int dcId) throws SQLException
    {

        float DCWeight = 0;

        if (ds == null)
        {
            throw new SQLException("Can't get data source");
        }

        ........... SQL query

        return DCWeight;
    }
}
</code></pre>

<p>I use this code to call the external Java method:</p>

<pre><code>@ViewScoped
public class DCProfileTabGeneral implements Serializable
{

    // Call the Oracle JDBC Connection driver as service
    @Resource(name = "jdbc/Oracle")
    // Data source
    private DataSource ds;

    // Weight initialization
    private CalcWeight weight;
    // Power initialization
    private CalcPower power;
    // Cooling initialization
    private CalcCooling cooling;

    // Constructor
    public DCProfileTabGeneral()
    {

        // Weight initialization
        weight = new CalcWeight();

    }
    ..........................
    weight.TotalDCWeightCalc(id)
    .....................
}
</code></pre>

<p>I get this error message when I run this code:</p>

<pre><code>java.sql.SQLException: Can't get data source
</code></pre>

<p>How I can solve this problem?</p>
