Strange component instanciationin in PAGE scope
swenvogel May 12, 2011 4:46 AMHi,
i encountered the problem that component are created several times
when used in PAGE scope.
For test cases i created three classes ActionOne, ActionTwo and QueryOne.
QueryOne is injected into ActionTwo and ActionOne, ActionTwo is
injected into ActionOne.
Her are the simple test classes:
ActionOne:
@AutoCreate @Name("actionOne") @Scope(ScopeType.PAGE) public class ActionOne { @In private ActionTwo actionTwo; @In private QueryOne queryOne; @Create public void create() { System.out.println("-> ActionOne.create(): " + this.toString()); System.out.println(" actionTwo = " + actionTwo.toString()); System.out.println(" queryOne = " + queryOne.toString()); System.out.flush(); } public void doAction() { System.out.println("-> ActionOne.doAction(): " + this.toString()); System.out.println(" actionTwo = " + actionTwo.toString()); System.out.println(" queryOne = " + queryOne.toString()); System.out.flush(); queryOne.doQuery(); actionTwo.doAction(); } }
ActionTwo:
@AutoCreate @Name("actionTwo") @Scope(ScopeType.PAGE) public class ActionTwo { @In private QueryOne queryOne; @Create public void create() { System.out.println("-> ActionTwo.create(): " + this.toString()); System.out.println(" queryOne = " + queryOne.toString()); System.out.flush(); } public void doAction() { System.out.println("-> ActionTwo.doAction(): " + this.toString()); System.out.println(" queryOne = " + queryOne.toString()); System.out.flush(); queryOne.doQuery(); } }
QueryOne:
@AutoCreate @Name("queryOne") @Scope(ScopeType.PAGE) public class QueryOne { @Create public void create() { System.out.println("-> QueryOne.create(): " + this.toString()); System.out.flush(); } public void doQuery() { System.out.println("-> QueryOne.doQuery(): " + this.toString()); System.out.flush(); } }
Here is the console output where you can see that the components are created
several times, for example 7x QueryOne!
10:01:10,923 INFO [STDOUT] -> QueryOne.create(): test.QueryOne@5f1b0c 10:01:10,923 INFO [STDOUT] -> ActionTwo.create(): test.ActionTwo@1e8e763 10:01:10,923 INFO [STDOUT] queryOne = test.QueryOne@5f1b0c 10:01:10,923 INFO [STDOUT] -> QueryOne.create(): test.QueryOne@1248cd1 10:01:10,924 INFO [STDOUT] -> ActionOne.create(): test.ActionOne@427e88 10:01:10,925 INFO [STDOUT] -> QueryOne.create(): test.QueryOne@5a5ea2 10:01:10,925 INFO [STDOUT] actionTwo = test.ActionTwo@1e8e763 10:01:10,925 INFO [STDOUT] queryOne = test.QueryOne@1248cd1 10:01:10,927 INFO [STDOUT] -> QueryOne.create(): test.QueryOne@d0791b 10:01:10,928 INFO [STDOUT] -> ActionTwo.create(): test.ActionTwo@bf0824 10:01:10,928 INFO [STDOUT] queryOne = test.QueryOne@d0791b 10:01:10,928 INFO [STDOUT] -> QueryOne.create(): test.QueryOne@1c96459 10:01:10,928 INFO [STDOUT] -> ActionOne.doAction(): test.ActionOne@427e88 10:01:10,929 INFO [STDOUT] -> QueryOne.create(): test.QueryOne@afb37b 10:01:10,929 INFO [STDOUT] actionTwo = test.ActionTwo@bf0824 10:01:10,929 INFO [STDOUT] queryOne = test.QueryOne@1c96459 10:01:10,929 INFO [STDOUT] -> QueryOne.doQuery(): test.QueryOne@1c96459 10:01:10,930 INFO [STDOUT] -> QueryOne.create(): test.QueryOne@9e7bc 10:01:10,930 INFO [STDOUT] -> ActionTwo.doAction(): test.ActionTwo@bf0824 10:01:10,930 INFO [STDOUT] queryOne = test.QueryOne@9e7bc 10:01:10,930 INFO [STDOUT] -> QueryOne.doQuery(): test.QueryOne@9e7bc
When i change the scope of the components to CONVERSATION everything works
fine and every component is created only once:
10:27:55,743 INFO [STDOUT] -> QueryOne.create(): de.moneyman.test.QueryOne@682598 10:27:55,743 INFO [STDOUT] -> ActionTwo.create(): de.moneyman.test.ActionTwo@17c4973 10:27:55,744 INFO [STDOUT] queryOne = de.moneyman.test.QueryOne@682598 10:27:55,745 INFO [STDOUT] -> ActionOne.create(): de.moneyman.test.ActionOne@d2dc0a 10:27:55,745 INFO [STDOUT] actionTwo = de.moneyman.test.ActionTwo@17c4973 10:27:55,745 INFO [STDOUT] queryOne = de.moneyman.test.QueryOne@682598 10:27:55,747 INFO [STDOUT] -> ActionOne.doAction(): de.moneyman.test.ActionOne@d2dc0a 10:27:55,748 INFO [STDOUT] actionTwo = de.moneyman.test.ActionTwo@17c4973 10:27:55,748 INFO [STDOUT] queryOne = de.moneyman.test.QueryOne@682598 10:27:55,748 INFO [STDOUT] -> QueryOne.doQuery(): de.moneyman.test.QueryOne@682598 10:27:55,749 INFO [STDOUT] -> ActionTwo.doAction(): de.moneyman.test.ActionTwo@17c4973 10:27:55,749 INFO [STDOUT] queryOne = de.moneyman.test.QueryOne@682598 10:27:55,749 INFO [STDOUT] -> QueryOne.doQuery(): de.moneyman.test.QueryOne@682598
But the page scope should be wider than the temporary conversation scope!
So why are the componentes created several times when used in page scope?