org.apache.wicket.ajax.AbstractDefaultAjaxBehavior Java Examples

The following examples show how to use org.apache.wicket.ajax.AbstractDefaultAjaxBehavior. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainPage.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
private AbstractDefaultAjaxBehavior newAreaBehavior() {
	return new AbstractDefaultAjaxBehavior() {
		private static final long serialVersionUID = 1L;

		@Override
		protected void respond(AjaxRequestTarget target) {
			loaded = true;
			log.debug("MainPage::areaBehavior");
			if (uf == null) {
				uf = WebSession.get().getArea();
			}
			main.updateContents(uf == null ? OmUrlFragment.get() : uf, target);
			WebSession.get().setArea(null);
		}

		@Override
		public void renderHead(Component component, IHeaderResponse response) {
			if (!loaded) {
				log.debug("renderHead:: newAreaBehavior");
				super.renderHead(component, response);
				internalRenderHead(response);
				response.render(OnDomReadyHeaderItem.forScript(getCallbackScript()));
			}
		}
	};
}
 
Example #2
Source File: MenuConfig.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param id
 */
@SuppressWarnings("serial")
public MenuConfig(final String id, final Menu menu, final FavoritesMenu favoritesMenu)
{
  super(id);
  configureLink = new WebMarkupContainer("configureLink");
  add(configureLink);
  configureBehavior = new AbstractDefaultAjaxBehavior() {
    @Override
    protected void respond(final AjaxRequestTarget target)
    {
      final Request request = RequestCycle.get().getRequest();
      final StringValue configuration = request.getPostParameters().getParameterValue("configuration");
      final String xml = configuration.toString("");
      if (log.isDebugEnabled() == true) {
        log.debug(xml);
      }
      favoritesMenu.readFromXml(xml);
      favoritesMenu.storeAsUserPref();
    }
  };
  add(configureBehavior);
  add(new MenuConfigContent("content", menu));
}
 
Example #3
Source File: PFAutoCompleteBehavior.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#onBind()
 */
@Override
protected void onBind()
{
  // add empty AbstractDefaultAjaxBehavior to the component, to force
  // rendering wicket-ajax.js reference if no other ajax behavior is on
  // page
  getComponent().add(new AbstractDefaultAjaxBehavior() {
    private static final long serialVersionUID = 1L;

    @Override
    protected void respond(final AjaxRequestTarget target)
    {
    }
  });
}
 
Example #4
Source File: MainPage.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
private AbstractDefaultAjaxBehavior newDelayedLoad() {
	return new AbstractDefaultAjaxBehavior() {
		private static final long serialVersionUID = 1L;

		@Override
		protected void respond(AjaxRequestTarget target) {
			log.debug("MainPage::delayedLoad");
			main = new MainPanel(MAIN_PANEL_ID);
			target.add(mainContainer.replace(main).add(newAreaBehavior()));
		}

		@Override
		public void renderHead(Component component, IHeaderResponse response) {
			if (!inited) {
				log.debug("renderHead:: newDelayedLoad");
				inited = true;
				super.renderHead(component, response);
				response.render(OnDomReadyHeaderItem.forScript(getCallbackScript()));
			}
		}
	};
}
 
Example #5
Source File: CallbackFunctionHelper.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
private static StringBuilder getNamedFunctionStr(String name, AbstractDefaultAjaxBehavior b, CallbackParameter... extraParameters) {
	StringBuilder sb = new StringBuilder();
	sb.append("function ").append(name).append("(");
	boolean first = true;
	for (CallbackParameter curExtraParameter : extraParameters) {
		if (curExtraParameter.getFunctionParameterName() != null) {
			if (first) {
				first = false;
			} else {
				sb.append(',');
			}
			sb.append(curExtraParameter.getFunctionParameterName());
		}
	}
	sb.append(") {\n");
	sb.append(b.getCallbackFunctionBody(extraParameters));
	sb.append("}\n");
	return sb;
}
 
Example #6
Source File: BootstrapDatePickerBehaviourTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testJSInjectionOneSpecialDate() {
	getTester().getSession().setLocale(Locale.ENGLISH);

	DateTextField field = new DateTextField("field") {
		private static final long serialVersionUID = 1L;

		{
			add(new BootstrapDatePickerBehaviour() {
				private static final long serialVersionUID = 1L;

				@SuppressWarnings("deprecation")
				@Override
				public java.util.Collection<SpecialDate> getSpecialDates() {
					return Arrays.asList(new SpecialDate(new Date(110, 11, 25), "holiday", "Christmas"));
				};
			});
		}};
	startFormComponentTest(field, "text");

	String doc = getTester().getLastResponse().getDocument();

	TagTester head = TagTester.createTagByName(doc, "head");
	assertNotNull(head);

	List<TagTester> scripts = TagTester.createTagsByAttribute(head.getValue(), "type", "text/javascript", false);
	assertEquals(5, scripts.size());
	for (int i = 0; i < 5; i++) {
		assertEquals("script", scripts.get(i).getName());
	}

	assertThat(scripts.get(0).getAttribute("src"), matchesPattern("(.*)" + BootstrapDatePickerBehaviour.class.getName() + "/bootstrap-datepicker(.*)\\.js"));
	assertThat(scripts.get(1).getAttribute("src"), matchesPattern("(.*)" + BootstrapDatePickerBehaviour.class.getName() + "/bootstrap-datepicker-extension(.*)\\.js"));
	assertThat(scripts.get(2).getAttribute("src"), matchesPattern("(.*)" + JQueryResourceReference.class.getName() + "(.*)/jquery(.*)\\.js"));
	assertThat(scripts.get(3).getAttribute("src"), matchesPattern("(.*)" + AbstractDefaultAjaxBehavior.class.getName() + "(.*)/wicket-ajax-jquery(.*)\\.js"));
	assertThat(scripts.get(4).getValue(), matchesPattern("(?s)(.*)Wicket.Event.add\\(window, \\\"domready\\\", function\\(event\\) \\{(.*)\\$\\(\"#" +
			field.getMarkupId() + "\"\\).datepicker\\(null, \\[" +
			"\\{dt:new Date\\('2010-12-25'\\), css:'holiday', tooltip:'Christmas'\\}" +
			"\\]\\);(.*);\\}\\);(.*)"));
}
 
Example #7
Source File: AjaxLazyLoadImage.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * @param markupId
 *            The components markupid.
 * @return The component to show while the real component is being created.
 */
public Component getLoadingComponent(String markupId) {
	Label indicator = new Label(markupId, "<img src=\"" + RequestCycle.get().urlFor(AbstractDefaultAjaxBehavior.INDICATOR, null) + "\"/>");
	indicator.setEscapeModelStrings(false);
	indicator.add(new AttributeModifier("title", new Model("...")));
	return indicator;
}
 
Example #8
Source File: AjaxLazyLoadImage.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private void init() {
	setOutputMarkupId(true);	
	
	// render chart by ajax, uppon request
	chartRenderAjaxBehavior = new AbstractDefaultAjaxBehavior() {
		private static final long	serialVersionUID	= 1L;

		@Override
		protected void respond(AjaxRequestTarget target) {
			//log.debug("chartRenderAjaxBehavior.Responding for "+ getId());
			renderImage(target, true);
		}
		
		@Override
		public boolean isEnabled(Component component) {
			return state < 2;
		}
		
		@Override
		protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
		{
			super.updateAjaxAttributes(attributes);
			
			attributes.setChannel(new AjaxChannel(getId()));
		}
	};
	add(chartRenderAjaxBehavior);
	
	// fields for maximized chart size
	setDefaultModel(new CompoundPropertyModel(this));
	form = new Form("chartForm");
	form.add(new HiddenField("maxWidth"));
	form.add(new HiddenField("maxHeight"));
	add(form);

}
 
Example #9
Source File: AjaxLazyLoadFragment.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * @param markupId The components markupid.
 * @return The component to show while the real component is being created.
 */
public Component getLoadingComponent(String markupId) {
	Label indicator = new Label(markupId, "<img src=\"" + RequestCycle.get().urlFor(AbstractDefaultAjaxBehavior.INDICATOR, null) + "\"/>");
	indicator.setEscapeModelStrings(false);
	indicator.add(new AttributeModifier("title", new Model("...")));
	return indicator;
}
 
Example #10
Source File: BootstrapDatePickerBehaviourTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testBehaviorEmptySpecialDates() {
	getTester().getSession().setLocale(Locale.ENGLISH);

	DateTextField field = new DateTextField("field") {
		private static final long serialVersionUID = 1L;

		{
			add(new BootstrapDatePickerBehaviour() {
				private static final long serialVersionUID = 1L;

				@Override
				public java.util.Collection<SpecialDate> getSpecialDates() {
					return new ArrayList<SpecialDate>();
				};
			});
		}};
	startFormComponentTest(field, "text");

	String doc = getTester().getLastResponse().getDocument();

	TagTester head = TagTester.createTagByName(doc, "head");
	assertNotNull(head);

	List<TagTester> scripts = TagTester.createTagsByAttribute(head.getValue(), "type", "text/javascript", false);
	assertEquals(5, scripts.size());
	for (int i = 0; i < 5; i++) {
		assertEquals("script", scripts.get(i).getName());
	}

	assertThat(scripts.get(0).getAttribute("src"), matchesPattern("(.*)" + BootstrapDatePickerBehaviour.class.getName() + "/bootstrap-datepicker(.*)\\.js"));
	assertThat(scripts.get(1).getAttribute("src"), matchesPattern("(.*)" + BootstrapDatePickerBehaviour.class.getName() + "/bootstrap-datepicker-extension(.*)\\.js"));
	assertThat(scripts.get(2).getAttribute("src"), matchesPattern("(.*)" + JQueryResourceReference.class.getName() + "(.*)/jquery(.*)\\.js"));
	assertThat(scripts.get(3).getAttribute("src"), matchesPattern("(.*)" + AbstractDefaultAjaxBehavior.class.getName() + "(.*)/wicket-ajax-jquery(.*)\\.js"));
	assertThat(scripts.get(4).getValue(), matchesPattern("(?s)(.*)Wicket.Event.add\\(window, \\\"domready\\\", function\\(event\\) \\{(.*)\\$\\(\"#" +
			field.getMarkupId() + "\"\\).datepicker\\(\\);(.*);\\}\\);(.*)"));

}
 
Example #11
Source File: BootstrapDatePickerBehaviourTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testJSInjectionNonEnglishLocale() {
	getTester().getSession().setLocale(Locale.FRENCH);

	DateTextField field = new DateTextField("field") {
		private static final long serialVersionUID = 1L;

		{
			add(new BootstrapDatePickerBehaviour());
		}};
	startFormComponentTest(field, "text");

	String doc = getTester().getLastResponse().getDocument();

	TagTester head = TagTester.createTagByName(doc, "head");
	assertNotNull(head);

	List<TagTester> scripts = TagTester.createTagsByAttribute(head.getValue(), "type", "text/javascript", false);
	assertEquals(6, scripts.size());
	for (int i = 0; i < 6; i++) {
		assertEquals("script", scripts.get(i).getName());
	}
	
	assertThat(scripts.get(0).getAttribute("src"), matchesPattern("(.*)" + BootstrapDatePickerBehaviour.class.getName() + "/bootstrap-datepicker(.*)\\.js"));
	assertThat(scripts.get(1).getAttribute("src"), matchesPattern("(.*)" + BootstrapDatePickerBehaviour.class.getName() + "/bootstrap-datepicker-extension(.*)\\.js"));
	assertThat(scripts.get(2).getAttribute("src"), matchesPattern("(.*)" + BootstrapDatePickerBehaviour.class.getName() + "/locales/bootstrap-datepicker.fr(.*)\\.js"));
	assertThat(scripts.get(3).getAttribute("src"), matchesPattern("(.*)" + JQueryResourceReference.class.getName() + "(.*)/jquery(.*)\\.js"));
	assertThat(scripts.get(4).getAttribute("src"), matchesPattern("(.*)" + AbstractDefaultAjaxBehavior.class.getName() + "(.*)/wicket-ajax-jquery(.*)\\.js"));
	assertThat(scripts.get(5).getValue(), matchesPattern("(?s)(.*)Wicket.Event.add\\(window, \\\"domready\\\", function\\(event\\) \\{(.*)\\$\\(\"#" +
			field.getMarkupId() + "\"\\).datepicker\\(\\);(.*);\\}\\);(.*)"));
}
 
Example #12
Source File: BootstrapDatePickerBehaviourTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testJSInjection() {
	getTester().getSession().setLocale(Locale.ENGLISH);

	DateTextField field = new DateTextField("field") {
		private static final long serialVersionUID = 1L;

		{
			add(new BootstrapDatePickerBehaviour());
		}};

	startFormComponentTest(field, "text");

	String doc = getTester().getLastResponse().getDocument();

	TagTester head = TagTester.createTagByName(doc, "head");
	assertNotNull(head);

	List<TagTester> scripts = TagTester.createTagsByAttribute(head.getValue(), "type", "text/javascript", false);
	assertEquals(5, scripts.size());
	for (int i = 0; i < 5; i++) {
		assertEquals("script", scripts.get(i).getName());
	}
	
	assertThat(scripts.get(0).getAttribute("src"), matchesPattern("(.*)" + BootstrapDatePickerBehaviour.class.getName() + "/bootstrap-datepicker(.*)\\.js"));
	assertThat(scripts.get(1).getAttribute("src"), matchesPattern("(.*)" + BootstrapDatePickerBehaviour.class.getName() + "/bootstrap-datepicker-extension(.*)\\.js"));
	assertThat(scripts.get(2).getAttribute("src"), matchesPattern("(.*)" + JQueryResourceReference.class.getName() + "(.*)/jquery(.*)\\.js"));
	assertThat(scripts.get(3).getAttribute("src"), matchesPattern("(.*)" + AbstractDefaultAjaxBehavior.class.getName() + "(.*)/wicket-ajax-jquery(.*)\\.js"));
	assertThat(scripts.get(4).getValue(), matchesPattern("(?s)(.*)Wicket.Event.add\\(window, \\\"domready\\\", function\\(event\\) \\{(.*)\\$\\(\"#" +
			field.getMarkupId() + "\"\\).datepicker\\(\\);(.*);\\}\\);(.*)"));
}
 
Example #13
Source File: AjaxLazyLoadImage.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * @param markupId
 *            The components markupid.
 * @return The component to show while the real component is being created.
 */
public Component getLoadingComponent(String markupId) {
	Label indicator = new Label(markupId, "<img src=\"" + RequestCycle.get().urlFor(AbstractDefaultAjaxBehavior.INDICATOR, null) + "\"/>");
	indicator.setEscapeModelStrings(false);
	indicator.add(new AttributeModifier("title", new Model("...")));
	return indicator;
}
 
Example #14
Source File: AjaxLazyLoadImage.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private void init() {
	setOutputMarkupId(true);	
	
	// render chart by ajax, uppon request
	chartRenderAjaxBehavior = new AbstractDefaultAjaxBehavior() {
		private static final long	serialVersionUID	= 1L;

		@Override
		protected void respond(AjaxRequestTarget target) {
			//log.debug("chartRenderAjaxBehavior.Responding for "+ getId());
			renderImage(target, true);
		}
		
		@Override
		public boolean isEnabled(Component component) {
			return state < 2;
		}
		
		@Override
		protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
		{
			super.updateAjaxAttributes(attributes);
			
			attributes.setChannel(new AjaxChannel(getId()));
		}
	};
	add(chartRenderAjaxBehavior);
	
	// fields for maximized chart size
	setDefaultModel(new CompoundPropertyModel(this));
	form = new Form("chartForm");
	form.add(new HiddenField("maxWidth"));
	form.add(new HiddenField("maxHeight"));
	add(form);

}
 
Example #15
Source File: AjaxLazyLoadFragment.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * @param markupId The components markupid.
 * @return The component to show while the real component is being created.
 */
public Component getLoadingComponent(String markupId) {
	Label indicator = new Label(markupId, "<img src=\"" + RequestCycle.get().urlFor(AbstractDefaultAjaxBehavior.INDICATOR, null) + "\"/>");
	indicator.setEscapeModelStrings(false);
	indicator.add(new AttributeModifier("title", new Model("...")));
	return indicator;
}
 
Example #16
Source File: OmWebSocketPanel.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	add(newWsBehavior(), new AbstractDefaultAjaxBehavior() {
		private static final long serialVersionUID = 1L;

		@Override
		public void renderHead(Component component, IHeaderResponse response) {
			if (!pingable) {
				log.debug("pingTimer is attached");
				pingable = true;
				super.renderHead(component, response);
				response.render(OnDomReadyHeaderItem.forScript(getJs()));
			}
		}

		private CharSequence getJs() {
			return "OmUtil.ping(function(){" + getCallbackScript() + "});";
		}

		@Override
		protected void respond(AjaxRequestTarget target) {
			log.debug("Sending WebSocket PING");
			target.appendJavaScript(getJs());
			WebSocketHelper.sendClient(getWsClient(), new byte[]{getUserId() == null ? 0 : getUserId().byteValue()});
		}
	});
}
 
Example #17
Source File: AjaxListSetView.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void updateAjaxAttributes(AbstractDefaultAjaxBehavior behavior, AjaxRequestAttributes attributes) {
}
 
Example #18
Source File: AjaxLazyLoadImage.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void setAutoDetermineChartSizeByAjax(final String jquerySelectorForContainer) {
	autoDetermineChartSizeByAjax = true;
	AbstractDefaultAjaxBehavior determineChartSizeBehavior = new AbstractDefaultAjaxBehavior() {
		private static final long	serialVersionUID	= 1L;

		@Override
		protected void respond(AjaxRequestTarget target) {
			// parse desired image size
			Request req = RequestCycle.get().getRequest();

			selectedWidth = req.getQueryParameters().getParameterValue("width").toInt(400);					

			selectedHeight = req.getQueryParameters().getParameterValue("height").toInt(200);
			if(selectedHeight < 200)
			{
				selectedHeight = 200;
			}
			// render chart image
			renderImage(target, true);
		}

		@Override
		public void renderHead(Component component, IHeaderResponse response) {
			
			super.renderHead(component, response);
			response.render(OnDomReadyHeaderItem.forScript(getCallbackScript(component)));
		}
		
		@Override
		protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
		{
			super.updateAjaxAttributes(attributes);
			
			attributes.setChannel(new AjaxChannel(getId()));
			
			String dynamicExtraParams = "return { 'height': jQuery('" + jquerySelectorForContainer
					+ "').height(), 'width': jQuery('" + jquerySelectorForContainer + "').width() }";
			attributes.getDynamicExtraParameters().add(dynamicExtraParams);
		}
	};	
	
	add(determineChartSizeBehavior);
}
 
Example #19
Source File: CallbackFunctionHelper.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
public static JavaScriptHeaderItem getNamedFunction(String name, AbstractDefaultAjaxBehavior b, CallbackParameter... extraParameters) {
	String uid = randomUUID().toString();
	return JavaScriptHeaderItem.forScript(getNamedFunctionStr(name, b, extraParameters), String.format("%s-%s", name, uid));
}
 
Example #20
Source File: BootstrapDatePickerBehaviourTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void testBehaviorManySpecialDates() {
	getTester().getSession().setLocale(Locale.ENGLISH);

	DateTextField field = new DateTextField("field") {
		private static final long serialVersionUID = 1L;

		{
			add(new BootstrapDatePickerBehaviour() {
				private static final long serialVersionUID = 1L;

				@SuppressWarnings("deprecation")
				@Override
				public java.util.Collection<SpecialDate> getSpecialDates() {
					return Arrays.asList(
							new SpecialDate(new Date(110, 11, 25), "holiday", "Christmas"),
							new SpecialDate(new Date(110, 0, 1), "holiday", "New Year"));
				};
			});
		}};
	startFormComponentTest(field, "text");

	String doc = getTester().getLastResponse().getDocument();

	TagTester head = TagTester.createTagByName(doc, "head");
	assertNotNull(head);

	List<TagTester> scripts = TagTester.createTagsByAttribute(head.getValue(), "type", "text/javascript", false);
	assertEquals(5, scripts.size());
	for (int i = 0; i < 5; i++) {
		assertEquals("script", scripts.get(i).getName());
	}
	assertThat(scripts.get(0).getAttribute("src"), matchesPattern("(.*)" + BootstrapDatePickerBehaviour.class.getName() + "/bootstrap-datepicker(.*)\\.js"));
	assertThat(scripts.get(1).getAttribute("src"), matchesPattern("(.*)" + BootstrapDatePickerBehaviour.class.getName() + "/bootstrap-datepicker-extension(.*)\\.js"));
	assertThat(scripts.get(2).getAttribute("src"), matchesPattern("(.*)" + JQueryResourceReference.class.getName() + "(.*)/jquery(.*)\\.js"));
	assertThat(scripts.get(3).getAttribute("src"), matchesPattern("(.*)" + AbstractDefaultAjaxBehavior.class.getName() + "(.*)/wicket-ajax-jquery(.*)\\.js"));

	assertThat(scripts.get(4).getValue(), matchesPattern("(?s)(.*)Wicket.Event.add\\(window, \\\"domready\\\", function\\(event\\) \\{(.*)\\$\\(\"#" +
			field.getMarkupId() + "\"\\).datepicker\\(null, \\[" +
			"\\{dt:new Date\\('2010-12-25'\\), css:'holiday', tooltip:'Christmas'\\}," +
			"\\{dt:new Date\\('2010-01-01'\\), css:'holiday', tooltip:'New Year'\\}" +
			"\\]\\);(.*);\\}\\);(.*)"));
}
 
Example #21
Source File: AjaxIndicator.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void onComponentTag(ComponentTag tag) {
	super.onComponentTag(tag);
	tag.put("src", RequestCycle.get().urlFor(AbstractDefaultAjaxBehavior.INDICATOR, null));
}
 
Example #22
Source File: AjaxIndicator.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void onComponentTag(ComponentTag tag) {
	super.onComponentTag(tag);
	tag.put("src", RequestCycle.get().urlFor(AbstractDefaultAjaxBehavior.INDICATOR, null));
}
 
Example #23
Source File: AjaxLazyLoadImage.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void setAutoDetermineChartSizeByAjax(final String jquerySelectorForContainer) {
	autoDetermineChartSizeByAjax = true;
	AbstractDefaultAjaxBehavior determineChartSizeBehavior = new AbstractDefaultAjaxBehavior() {
		private static final long	serialVersionUID	= 1L;

		@Override
		protected void respond(AjaxRequestTarget target) {
			// parse desired image size
			Request req = RequestCycle.get().getRequest();

			selectedWidth = req.getQueryParameters().getParameterValue("width").toInt(400);					

			selectedHeight = req.getQueryParameters().getParameterValue("height").toInt(200);
			if(selectedHeight < 200)
			{
				selectedHeight = 200;
			}
			// render chart image
			renderImage(target, true);
		}

		@Override
		public void renderHead(Component component, IHeaderResponse response) {
			
			super.renderHead(component, response);
			response.render(OnDomReadyHeaderItem.forScript(getCallbackScript(component)));
		}
		
		@Override
		protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
		{
			super.updateAjaxAttributes(attributes);
			
			attributes.setChannel(new AjaxChannel(getId()));
			
			String dynamicExtraParams = "return { 'height': jQuery('" + jquerySelectorForContainer
					+ "').height(), 'width': jQuery('" + jquerySelectorForContainer + "').width() }";
			attributes.getDynamicExtraParameters().add(dynamicExtraParams);
		}
	};	
	
	add(determineChartSizeBehavior);
}
 
Example #24
Source File: PFAutoCompleteTextField.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @see org.apache.wicket.Component#onInitialize()
 */
@Override
protected void onInitialize()
{
  super.onInitialize();
  behavior = new PFAutoCompleteBehavior<T>(renderer, settings) {
    private static final long serialVersionUID = 1L;

    @Override
    protected List<T> getChoices(final String input)
    {
      return PFAutoCompleteTextField.this.getChoices(input);
    }

    @Override
    protected List<T> getFavorites()
    {
      return PFAutoCompleteTextField.this.getFavorites();
    }

    @Override
    protected List<String> getRecentUserInputs()
    {
      return PFAutoCompleteTextField.this.getRecentUserInputs();
    }

    @Override
    protected String formatValue(final T value)
    {
      return PFAutoCompleteTextField.this.formatValue(value);
    }

    @Override
    protected String formatLabel(final T value)
    {
      return PFAutoCompleteTextField.this.formatLabel(value);
    }
  };
  add(behavior);
  deleteBehavior = new AbstractDefaultAjaxBehavior() {
    private static final long serialVersionUID = 3014042180471042845L;

    @Override
    protected void respond(final AjaxRequestTarget target)
    {
      // Gather query params ?...&content=kssel
      final StringValue contentValue = RequestCycle.get().getRequest().getQueryParameters().getParameterValue(CONTENT);
      if (contentValue != null) {
        final String contentString = contentValue.toString();
        if (getForm() instanceof AutoCompleteIgnoreForm) {
          ((AutoCompleteIgnoreForm) getForm()).ignore(PFAutoCompleteTextField.this, contentString);
        } // else { just ignore }
      }
    }
  };
  add(deleteBehavior);
}
 
Example #25
Source File: BratSuggestionVisualizer.java    From webanno with Apache License 2.0 4 votes vote down vote up
public BratSuggestionVisualizer(String id,
        IModel<UserAnnotationSegment> aModel, int aPosition)
{
    super(id, aModel);
    String username;
    if (getModelObject().getAnnotatorState().getMode().equals(Mode.AUTOMATION)
            || getModelObject().getAnnotatorState().getMode().equals(Mode.CORRECTION)) {
        username = "Suggestion";
    }
    else {
        Project project = getModelObject().getAnnotatorState().getProject();
        if (project.isAnonymousCuration()
                && !projectService.isManager(project, userService.getCurrentUser())) {
            username = "Anonymized annotator " + (aPosition + 1);
        }
        else {
            username = getModelObject().getUsername();
        }
    }
    
    add(new Label("username", username));

    controller = new AbstractDefaultAjaxBehavior()
    {
        private static final long serialVersionUID = 1133593826878553307L;

        @Override
        protected void respond(AjaxRequestTarget aTarget)
        {
            try {
                onClientEvent(aTarget);
            }
            catch (Exception e) {
                aTarget.addChildren(getPage(), IFeedback.class);
                error("Error: " + e.getMessage());
            }
        }

    };
    add(controller);
}