/** * Flag to indicate the the AJAX trigger should be fired once only. * * @param loadOnce if <code>true</code> the target AJAX trigger only once for each load of a page */ public void setLoadOnce(final boolean loadOnce) { if (loadOnce != isLoadOnce()) { getOrCreateComponentModel().loadOnce = loadOnce; } }
@Test public void testLoadOnceFromDeprecatedLoadCount() { WAjaxControl control = new WAjaxControl(new WCheckBox()); Assert.assertFalse(control.isLoadOnce()); // default is false. control.setLoadCount(1); Assert.assertTrue(control.isLoadOnce()); control.setLoadCount(0); Assert.assertFalse(control.isLoadOnce()); control.setLoadCount(2); Assert.assertTrue(control.isLoadOnce()); }
@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()); }
xml.appendOptionalAttribute("loadOnce", ajaxControl.isLoadOnce(), "true"); xml.appendOptionalAttribute("delay", delay > 0, delay); xml.appendClose();