/** * <p> * Set a delay period, in milliseconds, between the WAjaxControl being rendered in the view and it being * <em>automatically</em> triggered. A WAjaxControl with a delay > 0 will result in a request being made without * a change to any {@link AjaxTrigger} component. * </p> * <p> * The use of a delay may be useful for setting up a trigger which polls for changes in a part of a UI. See * {@link com.github.bordertech.wcomponents.WAjaxPollingRegion}. * </p> * <p> * If the trigger is part of a polling region (therefore it is itself updated and potentially re-triggers itself * possibly many times) then the delay <strong>must not</strong> be less than 334.</p> * * @param delay the delay after page load before AJAX control triggered */ public void setDelay(final int delay) { if (delay != getDelay()) { getOrCreateComponentModel().delay = delay; } }
WAjaxControl ajax = (WAjaxControl) trigger; if (ajax.getDelay() > 0) { return true;
@Test public void testTriggerConstructor() { AjaxTrigger trigger = new WButton(); WAjaxControl control = new WAjaxControl(trigger); Assert.assertSame("Incorrect trigger", trigger, control.getTrigger()); Assert.assertFalse("Should not be load once", control.isLoadOnce()); Assert.assertTrue("Targets should be empty", control.getTargets().isEmpty()); Assert.assertEquals("Delay should not be set", 0, control.getDelay()); }
@Test public void testTriggerTargetConstructor() { AjaxTrigger trigger = new WDropdown(); AjaxTarget target = new WPanel(); WAjaxControl control = new WAjaxControl(trigger, target); Assert.assertSame("Incorrect trigger", trigger, control.getTrigger()); Assert.assertFalse("Should not be load once", control.isLoadOnce()); Assert.assertEquals("Delay should not be set", 0, control.getDelay()); Assert.assertEquals("Incorrect target", Arrays.asList(target), control.getTargets()); }
@Test public void testTriggerTargetArrayConstructor() { AjaxTrigger trigger = new WCheckBox(); AjaxTarget[] targets = new AjaxTarget[]{new WPanel(), new WTextField()}; WAjaxControl control = new WAjaxControl(trigger, targets); Assert.assertSame("Incorrect trigger", trigger, control.getTrigger()); Assert.assertFalse("Should not be load once", control.isLoadOnce()); Assert.assertEquals("Delay should not be set", 0, control.getDelay()); Assert.assertEquals("Incorrect targets list", Arrays.asList(targets), control.getTargets()); Assert.assertTrue("Incorrect targets array", Arrays.equals(targets, control. getTargetsArray())); }
@Test public void testTriggerTargetListConstructor() { AjaxTrigger trigger = new WCheckBox(); List<AjaxTarget> targets = Arrays.asList(new AjaxTarget[]{new WPanel(), new WTextField()}); WAjaxControl control = new WAjaxControl(trigger, targets); Assert.assertSame("Incorrect trigger", trigger, control.getTrigger()); Assert.assertFalse("Should not be load once", control.isLoadOnce()); Assert.assertEquals("Delay should not be set", 0, control.getDelay()); Assert.assertEquals("Incorrect targets", targets, control.getTargets()); }
WComponent trigger = ajaxControl.getTrigger() == null ? ajaxControl : ajaxControl. getTrigger(); int delay = ajaxControl.getDelay();