• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Help - why does this code start a new session???
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help - why does this code start a new session???


  • Subject: Re: Help - why does this code start a new session???
  • From: Chris Pavicich <email@hidden>
  • Date: Sat, 1 May 2004 18:35:14 -0400

James:

Hmm. This is just a stab in the dark, but where are you expecting the session to come FROM when you call ((Session)session())? Most likely, there is no context
to derive the session from... How are you invoking this class?


When you call session() on WOComponent, if it doesn't exist, a new one is created. (http://developer.apple.com/documentation/WebObjects/Reference/API5.2/ index.html)

HTH
--CMP



On May 1, 2004, at 9:44, James Cicenia wrote:

Here is the code...
Where and why does it create a new session every time it is run????

// Generated by the WOLips Core at Sun Feb 29 12:06:45 CST 2004

package dashboard;

import Application;
import Session;

import org.jfree.chart.*;
import org.jfree.chart.labels.*;
import org.jfree.chart.plot.*;
import org.jfree.data.*;

import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.foundation.*;

import eo.*;
import er.extensions.*;

public class DashboardQ1 extends WOComponent {
	protected Number chartHeight = new Integer(450);
	protected Number chartWidth = new Integer(270);

	protected NSData jpgChart;
	protected JFreeChart chart;

	protected NSArray aCustomers = null;
	public PortfolioCustomer portfolioCustomerItem;
	public PortfolioCustomer selectedCustomer;

	//data object and NSArray to hold data
	protected DefaultPieDataset dataSetQ1;

	protected String chartName = "";
	protected static String key = "projectState.lifeCycleState";

	private static EOQualifier qualifier2 =
		EOQualifier.qualifierWithQualifierFormat(
			"projectState.lifeCycleState = 'Request'",
			null);

	private static EOQualifier qualifier3 =
		EOQualifier.qualifierWithQualifierFormat(
			"projectState.lifeCycleState = 'Pipeline'",
			null);

	private static EOQualifier qualifier4 =
		EOQualifier.qualifierWithQualifierFormat(
			"projectState.lifeCycleState = 'Project'",
			null);

	private static EOQualifier qualifier5 =
		EOQualifier.qualifierWithQualifierFormat(
			"projectState.lifeCycleState = 'Measure'",
			null);

     public DashboardQ1(WOContext context) {
         super(context);
     }

	public DefaultPieDataset dataSetQ1(){
		Portfolio portfolio = ((Session) session()).portfolio();
		if (portfolio != null) {
			if (portfolio.projects() != null) {
				if(selectedCustomer != null){
					EOQualifier qualifier1;
					NSMutableArray args = new NSMutableArray();
					args.addObject("customer");
					args.addObject(selectedCustomer);
					qualifier1 = EOQualifier.qualifierWithQualifierFormat("%@ = %@",
args);

					EOOrQualifier orQualifier1 =
						new EOOrQualifier(new NSArray(new Object[] {qualifier2,
qualifier3, qualifier4, qualifier5 }));

					EOAndQualifier andQualifier1 =
							new EOAndQualifier(new NSArray(new Object[] { qualifier1,
orQualifier1}));

					NSArray results = EOQualifier.filteredArrayWithQualifier(
										portfolio.projects(),andQualifier1);

if (results.count() == 0) {
return null;
}
dataSetQ1 = new DefaultPieDataset();
NSDictionary result=new NSDictionary();
result = ERXArrayUtilities.arrayGroupedByKeyPath(results,key);
java.util.Enumeration enumerator = result.keyEnumerator();
dataSetQ1.setValue(Application.LIFECYCLE_REQUEST,0);
dataSetQ1.setValue(Application.LIFECYCLE_PIPELINE,0);
dataSetQ1.setValue(Application.LIFECYCLE_PROJECT,0);
dataSetQ1.setValue(Application.LIFECYCLE_MEASURE,0);
while (enumerator.hasMoreElements()) {
String myKey = (String)enumerator.nextElement();

dataSetQ1.setValue(myKey,((NSArray)result.objectForKey(myKey)).count()) ;
}
}else{
EOOrQualifier orQualifier1 =
new EOOrQualifier(new NSArray(new Object[] {qualifier2,
qualifier3, qualifier4, qualifier5 }));

NSArray results = EOQualifier.filteredArrayWithQualifier(
portfolio.projects(),orQualifier1);

dataSetQ1 = new DefaultPieDataset();
NSDictionary result=new NSDictionary();
result = ERXArrayUtilities.arrayGroupedByKeyPath(results,key);
java.util.Enumeration enumerator = result.keyEnumerator();
dataSetQ1.setValue(Application.LIFECYCLE_REQUEST,0);
dataSetQ1.setValue(Application.LIFECYCLE_PIPELINE,0);
dataSetQ1.setValue(Application.LIFECYCLE_PROJECT,0);
dataSetQ1.setValue(Application.LIFECYCLE_MEASURE,0);
while (enumerator.hasMoreElements()) {
String myKey = (String)enumerator.nextElement();

dataSetQ1.setValue(myKey,((NSArray)result.objectForKey(myKey)).count()) ;
}
}
}
}
return dataSetQ1;
}



public NSArray aCustomers() { if (aCustomers == null) { aCustomers = new NSArray(); }

		Portfolio portfolio = ((Session) session()).portfolio();
		if (portfolio != null) {
			if (portfolio.customers() != null) {
				aCustomers = portfolio.customers();
			}
		}
		return aCustomers;
	}

	public NSData jpgChart() {
			try {

				// create the chart...
				JFreeChart chart = null ;

				chart = ChartFactory.createPieChart(chartName,  dataSetQ1(),  true,
  false, false);
				chart.setBackgroundPaint(Application.CHART_COLOR);
				chart.setBorderPaint(Application.CHART_COLOR);

				PiePlot plot = (PiePlot) chart.getPlot();

				plot.setBackgroundPaint(Application.CHART_COLOR);
				plot.setSectionLabelType(PiePlot.VALUE_AND_PERCENT_LABELS);
				plot.setNoDataMessage("No data available");
				plot.setItemLabelGenerator(new StandardPieItemLabelGenerator());

				//create byteOutputStream
				java.io.ByteArrayOutputStream baos = new
java.io.ByteArrayOutputStream();

				if (chartHeight == null) chartHeight = new Integer(400);
				if (chartWidth == null) chartWidth = new Integer(400);

				//create a Jpeg chart
				org.jfree.chart.ChartUtilities.writeChartAsJPEG(baos, chart,
chartHeight.intValue(), chartWidth.intValue() );

				//send the chart to NSData jpgChart
				jpgChart = new NSData(baos.toByteArray());

			} //try

catch (Exception e) {
NSLog.out.appendln("***** EXCEPTION "+e.toString() );
}
return jpgChart;
}
}
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Help - why does this code start a new session???
      • From: James Cicenia <email@hidden>
References: 
 >Help - why does this code start a new session??? (From: James Cicenia <email@hidden>)

  • Prev by Date: Help - why does this code start a new session???
  • Next by Date: Re: Help - why does this code start a new session???
  • Previous by thread: Help - why does this code start a new session???
  • Next by thread: Re: Help - why does this code start a new session???
  • Index(es):
    • Date
    • Thread