/** * gets the redirect URL as workaround for opening a new window or refreshing a window (Noscript * version) */ private String getWindowOpener() { String result = ""; IServiceStateInfo stateInfo = ContextProvider.getStateInfo(); WebForm activeForm = FormManager.getActive(); WebForm[] allForms = FormManager.getAll(); boolean finished = false; for (int i = 0; !finished && i < allForms.length; i++) { WebForm form = allForms[i]; IFormAdapter formAdapter = WebFormUtil.getFormAdapter(form); if (stateInfo.isExpired()) { if (!formAdapter.getWindowOpenerBuffer().equals("")) { result = formAdapter.getWindowOpenerBuffer(); finished = true; } } else { if (WebComponentControl.openInNewWindow(form) || WebComponentControl.refreshWindow(form)) { result = "<meta http-equiv=\"refresh\" content=\"0; url=" + RenderUtil.createEncodedFormGetURL(form) + "\">"; formAdapter.addWindowOpenerBuffer(result); NoscriptFormStack.getInstance().push(activeForm); finished = true; } else { formAdapter.addWindowOpenerBuffer(""); } } } return result; }
public void testDataEventCheckBox() throws Exception { WebForm form = W4TFixture.getEmptyWebFormInstance(); W4TFixture.fakeBrowser(new Default(true)); final WebDataEvent[] dataEvent = new WebDataEvent[1]; WebDataListener dataListener = new WebDataListener() { public void webValueChanged(final WebDataEvent evt) { dataEvent[0] = evt; } }; WebCheckBox checkBox = new WebCheckBox(); form.add(checkBox, WebBorderLayout.NORTH); assertEquals(UNCHECKED, checkBox.getValue()); checkBox.addWebDataListener(dataListener); checkBox.setValue(CHECKED); assertNull(dataEvent[0]); checkBox.removeWebDataListener(dataListener); checkBox.setValue(UNCHECKED); dataEvent[0] = null; checkBox.addWebDataListener(dataListener); String id = checkBox.getUniqueID(); W4TFixture.fakeRequestParam(id, CHECKED); W4TFixture.fakeRequestParam(WebCheckBoxRenderer.PREFIX + id, UNCHECKED); getLifeCycleAdapter(form).readData(); IServiceStateInfo stateInfo = ContextProvider.getStateInfo(); String key = EventQueueFilter.ATTRIBUTE_KEY; EventQueueFilter eqv = (EventQueueFilter) stateInfo.getAttribute(key); eqv.filter(); EventQueue.getEventQueue().fireEvents(); assertNotNull(dataEvent[0]); assertSame(checkBox, dataEvent[0].getSource()); assertSame(UNCHECKED, dataEvent[0].getOldValue()); assertSame(CHECKED, dataEvent[0].getNewValue()); assertEquals(CHECKED, checkBox.getValue()); dataEvent[0] = null; W4TFixture.fakeRequestParam(checkBox.getUniqueID(), null); W4TFixture.fakeRequestParam(WebCheckBoxRenderer.PREFIX + id, CHECKED); getLifeCycleAdapter(form).readData(); eqv.filter(); EventQueue.getEventQueue().fireEvents(); assertNotNull(dataEvent[0]); assertSame(checkBox, dataEvent[0].getSource()); assertSame(CHECKED, dataEvent[0].getOldValue()); assertSame(UNCHECKED, dataEvent[0].getNewValue()); assertEquals(UNCHECKED, checkBox.getValue()); W4TFixture.fakeRequestParam(WebCheckBoxRenderer.PREFIX + id, UNCHECKED); dataEvent[0] = null; getLifeCycleAdapter(form).readData(); eqv.filter(); EventQueue.getEventQueue().fireEvents(); assertNull(dataEvent[0]); assertEquals(UNCHECKED, checkBox.getValue()); }
public void testDataEventTriggering() throws Exception { WebForm form = W4TFixture.getEmptyWebFormInstance(); W4TFixture.fakeBrowser(new Default(true)); final WebDataEvent[] dataEvent = new WebDataEvent[1]; WebDataListener dataListener = new WebDataListener() { public void webValueChanged(final WebDataEvent evt) { dataEvent[0] = evt; } }; WebText text = new WebText(); form.add(text, WebBorderLayout.NORTH); text.setValue(OLD_VALUE); assertEquals(OLD_VALUE, text.getValue()); text.addWebDataListener(dataListener); text.setValue(NEW_VALUE); assertNull(dataEvent[0]); text.removeWebDataListener(dataListener); text.setValue(OLD_VALUE); dataEvent[0] = null; text.addWebDataListener(dataListener); W4TFixture.fakeRequestParam(text.getUniqueID(), NEW_VALUE); getLifeCycleAdapter(form).readData(); IServiceStateInfo stateInfo = ContextProvider.getStateInfo(); String key = EventQueueFilter.ATTRIBUTE_KEY; EventQueueFilter eqv = (EventQueueFilter) stateInfo.getAttribute(key); eqv.filter(); EventQueue.getEventQueue().fireEvents(); assertNotNull(dataEvent[0]); assertSame(text, dataEvent[0].getSource()); assertSame(OLD_VALUE, dataEvent[0].getOldValue()); assertSame(NEW_VALUE, dataEvent[0].getNewValue()); assertEquals(NEW_VALUE, text.getValue()); }
public void readData(final WebComponent component) { // initialize the event queue filter used in noscript mode IServiceStateInfo stateInfo = ContextProvider.getStateInfo(); EventQueueFilter filter = new EventQueueFilter_Script(); stateInfo.setAttribute(EventQueueFilter.ATTRIBUTE_KEY, filter); }