-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi All
I confuse about ZK Spring scope (ZK Spring 3 + ZK 5.0.7). I have main page scope_test.zul with ScopeTestController and popup page call scope_test_popup.zul with ScopeTestPopupController as bellow.
scope_test.zul
<?page title="new page title" contentType="text/html;charset=UTF-8"?> <?variable-resolver class="org.zkoss.spring.DelegatingVariableResolver"?> <zk> <window id="scopeTestWin" apply="${scopeTestCtrl}" title="Main Page" border="0" width="100%" height="auto"> <button id="openPopup" label="Open Popup" /> </window> </zk>
@Controller("scopeTestCtrl") @Scope("prototype") public class ScopeTestController extends GenericSpringComposer { @Autowired private ScopeTestModel scopeTestModel; @Autowired private Window scopeTestWin; @Autowired private Button openPopup; private boolean sameObj = false; @EventHandler("scopeTestWin.onCreate") public void doCreateWindow(Event event){ System.out.println("scopeTestCtrl"); if(sameObj){ System.out.println("old bean"); }else{ System.out.println("new bean"); sameObj = true; } if(scopeTestModel.getModelName() != null){ System.out.println("old model bean"); }else{ System.out.println("new model bean"); scopeTestModel.setModelName("Main Window"); } System.out.println("openPopup-->[" + openPopup.hashCode() + "] label=" + openPopup.getLabel()); } @EventHandler("openPopup.onClick") public void doClickOpenPopup(Event event) throws SuspendNotAllowedException, InterruptedException{ System.out.println("scopeTestCtrl openPopup"); Window popupWin = (Window) Executions.getCurrent().createComponents("/exam23/scope_test_popup.zul",scopeTestWin, null); popupWin.doModal(); } }
<?page title="new page title" contentType="text/html;charset=UTF-8"?> <?variable-resolver class="org.zkoss.spring.DelegatingVariableResolver"?> <zk> <window id="scopeTestPopupWin" apply="${scopeTestPopupCtrl}" title="This is popup" border="normal" width="200px" height="100px" closable="true"> <button id="openPopup" label="Open Popup 2" /> </window> </zk>
@Controller("scopeTestPopupCtrl") @Scope("prototype") public class ScopeTestPopupController extends GenericSpringComposer { @Autowired private ScopeTestModel scopeTestModel; @Autowired private Window scopeTestPopupWin; @Autowired private Button openPopup; private boolean sameObj = false; @EventHandler("scopeTestPopupWin.onCreate") public void doCreateWindow(Event event){ System.out.println("scopeTestPopupCtrl"); if(sameObj){ System.out.println("old bean"); }else{ System.out.println("new bean"); sameObj = true; } if(scopeTestModel.getModelName() != null){ System.out.println("old model bean"); }else{ System.out.println("new model bean"); scopeTestModel.setModelName("Main Window"); } System.out.println("openPopup-->[" + openPopup.hashCode() + "] label=" + openPopup.getLabel()); } @EventHandler("openPopup.onClick") public void doClickOpenPopup(Event event) throws SuspendNotAllowedException, InterruptedException{ System.out.println("scopeTestPopupCtrl openPopup"); } }
Asked: 2011-08-26 00:50:03 +0800
Seen: 516 times
Last updated: Jan 11 '12