tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From java_is_everything <ajaygargn...@gmail.com>
Subject Re: Doubt on lifecycle of a class in "shared" folder
Date Thu, 17 Jul 2008 10:39:25 GMT

Shared Class :

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package client;

import java.util.ArrayList;

public class Sharer
{
	public static ArrayList listForOthers  = null;	
	
	static
	{
		System.out.println("STATIC ON WORK !!!!");		
	}

	public static ArrayList getListForOthers()
	  {
		  if(listForOthers != null)
		  {
			  System.out.println("Returned is NOT NULL.");
		  }
		  else
		  {
			  System.out.println("Returned is NULL");
		  }
		  return listForOthers;
	  }
	  
	  public static void setListForOthers(ArrayList list)
	  {
		  listForOthers = new ArrayList();
		  
		  for(int i = 0; i < list.size(); i++)
		  {			  
			  ClientSideEvent ce = new ClientSideEvent();
			  ClientSideEvent ce2 = (ClientSideEvent) list.get(i);
			  ce.setTimestamp(ce2.getTimestamp());
			  ce.setId(ce2.getId());
			  ce.setType(ce2.getType());
			  ce.setDescription(ce2.getDescription());
			  listForOthers.add(ce);
		  } 
	  
	  }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





webapp2 :

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package client;

import java.util.ArrayList;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;


/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class AnotherWelcomePage implements EntryPoint {

  /**
   * This is the entry point method.
   */
  public void onModuleLoad() {
	  final Button button = new Button("Doosra Search");
	  
	  RootPanel.get("slot2").add(button);	  
	  
	  ArrayList list = Sharer.getListForOthers();
	  if(list != null)
	  {
		  button.setText("Returning OK with " + list.size());
	  }
	  else
	  {
		  button.setText("Problem !!!!!!");
	  }
       }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




webapp1 :

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package client;

import java.util.ArrayList;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

//import com.google.gwt.user.client.ui.;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class EntryPointClass implements EntryPoint {

  /**
   * This is the entry point method.
   */
  public void onModuleLoad() {
	  	
	  ArrayList list = new ArrayList();
	  ClientSideEvent event = new ClientSideEvent();
	  
	  final Button b = new Button("Initial Display");
	  b.addClickListener(new ClickListener()
	  {

		public void onClick(Widget sender) 
		{
		
			ArrayList nowlist = Sharer.getListForOthers();
			if(nowlist == null)
			{
				b.setText("Null returned");
			}	
			else
			{
				b.setText("Size is " + Integer.toString(nowlist.size()));
			}
			
		}	
	  });
	  
	  RootPanel.get("slot1").add(b);	  
	  event.setTimestamp(" time is money "); // It's ok, needs a string
	  event.setId(222);
	  event.setType("type");
	  event.setDescription("description");
	  list.add(event);
	  Sharer.setListForOthers(list);
	  
	 	
	  //button.setText(Integer.toString(list.size()));
  }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////



Now, webapp1 sets the list size to 1. Now when Sharer.getListForOthers()
from webapp1, "Size is 1", while when Sharer.getListForOthers() from
webapp2, it shows "Problem !!!!!!".

Any light ?????????????????/



Ajay Garg

Mikolaj Rydzewski-2 wrote:
> 
> java_is_everything wrote:
>>     public int getA()
>>    {
>>        return a; 
>>    }
>>   
> [...]
>> value 123. But I don't .. :-(  Instead I get a null as returned value.
>>   
> It's impossible to return null from such method.
> 
> Show us complete code (both shared class and webapps).
> 
> -- 
> Mikolaj Rydzewski <miki@ceti.pl>
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Doubt-on-lifecycle-of-a-class-in-%22shared%22-folder-tp18502300p18505777.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message