Search in sources :

Example 1 with WicketRuntimeException

use of org.apache.wicket.WicketRuntimeException in project wiquery by WiQuery.

the class AutocompleteComponent method onBeforeRenderAutocomplete.

@Override
protected void onBeforeRenderAutocomplete(Autocomplete<?> autocomplete) {
    StringWriter sw = new StringWriter();
    try {
        JsonGenerator gen = new JsonFactory().createGenerator(sw);
        List<Object> json = new ArrayList<Object>();
        T defaultValue = AutocompleteComponent.this.getModelObject();
        AutocompleteJson value = null;
        Integer index = 0;
        for (T obj : AutocompleteComponent.this.list.getObject()) {
            index++;
            value = newAutocompleteJson(index, obj);
            json.add(value);
            if (obj.equals(defaultValue)) {
                autocomplete.setDefaultModelObject(value.getLabel());
                getAutocompleteHidden().setModelObject(value.getValueId());
            }
        }
        new ObjectMapper().writeValue(gen, json);
    } catch (IOException e) {
        throw new WicketRuntimeException(e);
    }
    autocomplete.getOptions().put("source", sw.toString());
}
Also used : StringWriter(java.io.StringWriter) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) JsonFactory(com.fasterxml.jackson.core.JsonFactory) ArrayList(java.util.ArrayList) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with WicketRuntimeException

use of org.apache.wicket.WicketRuntimeException in project gitblit by gitblit.

the class PluginClassResolver method getResources.

protected Iterator<URL> getResources(String name, PluginWrapper plugin) {
    HashSet<URL> loadedFiles = new HashSet<URL>();
    try {
        // Try the classloader for the wicket jar/bundle
        Enumeration<URL> resources = plugin.getPluginClassLoader().getResources(name);
        loadResources(resources, loadedFiles);
    } catch (IOException e) {
        throw new WicketRuntimeException(e);
    }
    return loadedFiles.iterator();
}
Also used : WicketRuntimeException(org.apache.wicket.WicketRuntimeException) IOException(java.io.IOException) URL(java.net.URL) HashSet(java.util.HashSet)

Example 3 with WicketRuntimeException

use of org.apache.wicket.WicketRuntimeException in project gitblit by gitblit.

the class FreemarkerPanel method getMarkupResourceStream.

/**
	 * @see org.apache.wicket.markup.IMarkupResourceStreamProvider#getMarkupResourceStream(org.apache
	 *      .wicket.MarkupContainer, java.lang.Class)
	 */
@Override
public final IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass) {
    Template template = getTemplate();
    if (template == null) {
        throw new WicketRuntimeException("could not find Freemarker template for panel: " + this);
    }
    // evaluate the template and return a new StringResourceStream
    StringBuffer sb = new StringBuffer();
    sb.append("<wicket:panel>");
    sb.append(evaluateFreemarkerTemplate(template));
    sb.append("</wicket:panel>");
    return new StringResourceStream(sb.toString());
}
Also used : WicketRuntimeException(org.apache.wicket.WicketRuntimeException) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) Template(freemarker.template.Template)

Example 4 with WicketRuntimeException

use of org.apache.wicket.WicketRuntimeException in project midpoint by Evolveum.

the class TabbedPanel method setCurrentTab.

private void setCurrentTab(int index) {
    if (this.currentTab == index) {
        // already current
        return;
    }
    this.currentTab = index;
    final Component component;
    if (currentTab == -1 || (tabs.getObject().size() == 0) || !getVisiblityCache().isVisible(currentTab)) {
        // no tabs or the current tab is not visible
        component = newPanel();
    } else {
        // show panel from selected tab
        T tab = tabs.getObject().get(currentTab);
        component = tab.getPanel(TAB_PANEL_ID);
        if (component == null) {
            throw new WicketRuntimeException("ITab.getPanel() returned null. TabbedPanel [" + getPath() + "] ITab index [" + currentTab + "]");
        }
    }
    if (!component.getId().equals(TAB_PANEL_ID)) {
        throw new WicketRuntimeException("ITab.getPanel() returned a panel with invalid id [" + component.getId() + "]. You must always return a panel with id equal to the provided panelId parameter. TabbedPanel [" + getPath() + "] ITab index [" + currentTab + "]");
    }
    addOrReplace(component);
}
Also used : WicketRuntimeException(org.apache.wicket.WicketRuntimeException) Component(org.apache.wicket.Component)

Aggregations

WicketRuntimeException (org.apache.wicket.WicketRuntimeException)4 IOException (java.io.IOException)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Template (freemarker.template.Template)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Component (org.apache.wicket.Component)1 StringResourceStream (org.apache.wicket.util.resource.StringResourceStream)1