cancel
Showing results for 
Search instead for 
Did you mean: 

Scope of ComponentContext

Former Member
0 Kudos

Sorry to bother again... As soon as I have one thing figured out, the next issue arises. Now my problem is, that I am not very sure if the objects stored in the


IPortalComponentRequest request =
	(IPortalComponentRequest) this.getRequest();
IPortalComponentContext myContext = request.getComponentContext();

are accessible only for the current logged on user. For me it looks like it is shared for any user logged on to the portal.

To trace this problem I created a very simple Java iView which has two buttons. The first sets a new values in my bean, the second is just for refreshing. The thing I do in the doInitialization() is to put my bean in the ComponentContext. After that I work with the bean object and set and get things in it. This works very fine for one user. But as soon as another user (on a different computer) accesses my iView the two bean objects get mixed up. Results from one user appear on the other users output fields, eg: user A clicks on Click1 and sets the bean Results to "onClick1". If user B starts the same iView from a differnt computer the first thing he gets is the initial value "Start". But when user A clicks on Refresh he now gets the "Start" value. I can continue with this. If user A now clicks on Click1 and B refreshes he sees "onClick1", ...

Can somebody tell me what I am doing wrong?

Here is the code:


public class TestBean extends PageProcessorComponent {

	public DynPage getPage() {
		return new TestBeanPage();
	}


	public class TestBeanPage extends JSPDynPage {
		Bean myBean;
		
		public void doInitialization() {
			IPortalComponentRequest request =
				(IPortalComponentRequest) this.getRequest();
			IPortalComponentContext myContext = request.getComponentContext();			

			Bean myBean = new Bean();
			myBean.setResults("Start");
			myContext.putValue("myBeanName", myBean);

		}

		public void doProcessAfterInput() throws PageException {
			 IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();
			 IPortalComponentContext myContext = request.getComponentContext();
			 myBean = (Bean) myContext.getValue("myBeanName");
		}
		
		public void onClick1(Event event) throws PageException {
			myBean.setResults("onClick1");			
		}

		public void onClick3(Event event) throws PageException {
			// Just refresh
		}

		public void doProcessBeforeOutput() throws PageException {
			setJspName("myTestJsp.jsp");
		}
	}
}

Thanks for any help on this!

Best regards,

Holger.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Holger,

without having read your source, I would recommend NOT to use the component context for storing bean information. Test have proven that the lifetime of the component context varies from 5 to 30 minutes and isn't predictable. Use your user session instead and you shouldn't have problems with synchronization as well.

Regards, Karsten

Former Member
0 Kudos

Hi Karsten,

thanks for your help. I switched to


IPortalComponentSession mySession = request.getComponentSession();

and now it works!!

Regards,

Holger.

PS. I wanted to reward you with 10 points, but for some reason I am not able to (I think because I didn't declasre this initial post as a question, which I thought I had -- I wanted to change that, but couldn't either.)