Example usage for org.apache.wicket.markup.html.form Form getMarkupId

List of usage examples for org.apache.wicket.markup.html.form Form getMarkupId

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form Form getMarkupId.

Prototype

public String getMarkupId() 

Source Link

Document

Retrieves id by which this component is represented within the markup.

Usage

From source file:au.org.theark.core.web.form.AbstractModalDetailForm.java

License:Open Source License

public void onEditSave(AjaxRequestTarget target, Form<?> form) {
    onSave(target);/*from  w  w w  . j  a va2s .  co  m*/
    target.add(arkCrudContainerVo.getDetailPanelContainer());
    String s = "jQuery('form#" + form.getMarkupId() + "').cleanDirty();";
    target.appendJavaScript(s);
    target.focusComponent(feedbackPanel);
}

From source file:com.visural.wicket.util.InvokeClientSideFormSubmitHandlerDecorator.java

License:Apache License

public InvokeClientSideFormSubmitHandlerDecorator(Form form) {
    form.setOutputMarkupId(true);
    formMarkupId = form.getMarkupId();
}

From source file:name.martingeisse.wicket.component.stateless.StatelessAjaxFormSubmitBehavior.java

License:Apache License

@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);

    final Form<?> form = getForm();
    attributes.setFormId(form.getMarkupId());

    final String formMethod = form.getMarkupAttributes().getString("method");
    if (formMethod == null || "POST".equalsIgnoreCase(formMethod)) {
        attributes.setMethod(Method.POST);
    }/*w  w  w . ja  va 2s  .co m*/

    if (form.getRootForm().isMultiPart()) {
        attributes.setMultipart(true);
        attributes.setMethod(Method.POST);
    }

    if (getComponent() instanceof IFormSubmittingComponent) {
        final String submittingComponentName = ((IFormSubmittingComponent) getComponent()).getInputName();
        attributes.setSubmittingComponentName(submittingComponentName);
    }
}

From source file:net.dontdrinkandroot.wicket.bootstrap.component.button.SubmitButtonLink.java

License:Apache License

/**
 * The JavaScript which triggers this link. Method is non-final so that subclasses can decorate
 * the provided script by wrapping their own JS around a call to super.getTriggerJavaScript().
 * //ww w  .  j  a v  a  2s . c  o  m
 * @return The JavaScript to be executed when the link is clicked.
 */
protected String getTriggerJavaScript() {

    if (this.getForm() != null) {
        // find the root form - the one we are really going to submit
        Form<?> root = this.getForm().getRootForm();
        StringBuilder sb = new StringBuilder(100);
        sb.append("var e=document.getElementById('");
        sb.append(root.getHiddenFieldId());
        sb.append("'); e.name=\'");
        sb.append(this.getInputName());
        sb.append("'; e.value='x';");
        sb.append("var f=document.getElementById('");
        sb.append(root.getMarkupId());
        sb.append("');");
        if (this.shouldInvokeJavaScriptFormOnsubmit()) {
            if (this.getForm() != root) {
                sb.append("var ff=document.getElementById('");
                sb.append(this.getForm().getMarkupId());
                sb.append("');");
            } else {
                sb.append("var ff=f;");
            }
            sb.append("if (ff.onsubmit != undefined) { if (ff.onsubmit()==false) return false; }");
        }
        sb.append("f.submit();e.value='';e.name='';return false;");
        return sb.toString();
    } else {
        return null;
    }
}

From source file:nl.knaw.dans.common.wicket.behavior.FormModificationDetectorBehavior.java

License:Apache License

public void bind(Component component) {
    if (!(component instanceof Form)) {
        throw new WicketRuntimeException(getClass() + " behavior can be bound only to a Form component");
    }// w w w .  j a  v a2  s .  c o m
    Form form = (Form) component;

    // This will make sure that the Form emits the
    // HTML 'ID' attribure when rendering. We require the 'ID' in our JS file

    form.setOutputMarkupId(true);

    // Since we require the Form "id" and the 'message' in our JavaScript
    // template, we will use Wicket's TextTemplateHeaderContributor that allows us to
    // perform variable substitutions at runtime. Keep the JS file in the same package location
    // as the behavior.

    // load dependencies
    form.getWebPage().add(JavascriptPackageResource.getHeaderContribution(WicketEventReference.INSTANCE));
    form.getWebPage().add(JavascriptPackageResource.getHeaderContribution(WicketAjaxReference.INSTANCE));

    form.getWebPage().add(TextTemplateHeaderContributor.forJavaScript(FormModificationDetectorBehavior.class,
            "j-script/FormModificationDetector.js", new FormModificationDetectorModel(form.getMarkupId())));
}

From source file:nl.knaw.dans.dccd.common.web.behavior.FormModificationDetectorBehavior.java

License:Apache License

public void bind(Component component) {
    if (!(component instanceof Form)) {
        throw new WicketRuntimeException(getClass() + " behavior can be bound only to a Form component");
    }/*w  w  w  .j  ava  2s  . c  om*/
    Form form = (Form) component;

    // This will make sure that the Form emits the
    // HTML 'ID' attribure when rendering. We require the 'ID' in our JS file

    form.setOutputMarkupId(true);

    // Since we require the Form "id" and the 'message' in our JavaScript
    // template, we will use Wicket's TextTemplateHeaderContributor that allows us to
    // perform variable substitutions at runtime. Keep the JS file in the same package location
    // as the behavior.

    // TODO needed after continue deposit from dataset view page. (but why?)
    form.getWebPage().add(HeaderContributor.forJavaScript(AbstractDefaultAjaxBehavior.class, "wicket-ajax.js"));

    form.getWebPage().add(TextTemplateHeaderContributor.forJavaScript(FormModificationDetectorBehavior.class,
            "j-script/FormModificationDetector.js", new FormModificationDetectorModel(form.getMarkupId())));
}

From source file:org.antbear.jee.wicket.DemoPanel.java

License:Apache License

public DemoPanel(String id) {
    super(id);/*from w  w w .  j a v  a2s.c  o  m*/

    final Form<Void> form = new Form<Void>("form");
    form.setMarkupId("form_" + id);

    Label myid = new Label("myid", form.getMarkupId());
    final DemoStringListView listView = new DemoStringListView("listItem");

    SubmitLink addLink = new SubmitLink("addLink", form) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit() {
            System.out.println("onSubmit " + this.getParent().getMarkupId());
            listView.addItem("Another item, added @ " + new Date());

            // Now comes the interresting logic as of wicket 1.5
            // .. we want to anchor the page to our #ID. Send an event to our parent
            // with the ID to be anchored.
            AnchorPayload event = new AnchorPayload(form.getMarkupId());
            log.info("Sending event " + event);

            send(getPage(), Broadcast.BREADTH, event);
        }
    };

    add(form);
    form.add(myid);
    form.add(addLink);
    form.add(listView);
}

From source file:org.efaps.ui.wicket.components.search.SearchPanel.java

License:Apache License

/**
 * Instantiates a new search panel.//from  ww w  .  ja  v  a 2  s .c  om
 *
 * @param _wicketId the wicket id
 */
public SearchPanel(final String _wicketId) {
    super(_wicketId);
    boolean access = false;
    try {
        final Command cmd = Command
                .get(UUID.fromString(Configuration.getAttribute(ConfigAttribute.INDEXACCESSCMD)));
        access = cmd.hasAccess(TargetMode.VIEW, null);
    } catch (final EFapsException e) {
        LOG.error("Catched error during access control to index.", e);
    }
    this.setVisible(access);
    final Model<IndexSearch> searchModel = Model.of(new IndexSearch());
    final ResultPanel resultPanel = new ResultPanel("result", searchModel);
    resultPanel.setOutputMarkupPlaceholderTag(true).setVisible(false);
    add(resultPanel);
    final Form<IndexSearch> form = new Form<>("form", searchModel);
    add(form);
    final TextField<String> input = new TextField<>("input", Model.of(""));
    input.setOutputMarkupId(true);
    input.add(new AttributeModifier("placeholder",
            DBProperties.getProperty(SearchPanel.class.getName() + ".Placeholder")));
    form.add(input);
    final AjaxButton button = new AjaxButton("button") {

        /** The Constant serialVersionUID. */
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(final AjaxRequestTarget _target, final Form<?> _form) {
            super.onSubmit(_target, _form);
            final String query = (String) input.getDefaultModelObject();
            if (StringUtils.isNotEmpty(query)) {
                final IndexSearch indexSearch = (IndexSearch) _form.getDefaultModelObject();
                indexSearch.setCurrentQuery(query);
                indexSearch.search();

                SearchPanel.this.visitChildren(ResultPanel.class, new IVisitor<Component, Void>() {
                    @Override
                    public void component(final Component _component, final IVisit<Void> _visit) {
                        ((ResultPanel) _component).update(_target, indexSearch);
                    }
                });
                resultPanel.setVisible(true);
                _target.add(resultPanel);

                final StringBuilder js = new StringBuilder();
                js.append("require(['dijit/TooltipDialog', 'dijit/popup', 'dojo/dom', 'dijit/registry',")
                        .append("'dojo/_base/window', 'dojo/window', 'dojo/query',")
                        .append("'dojo/dom-construct', 'dojo/NodeList-dom'],")
                        .append("function(TooltipDialog, popup, dom, registry, baseWindow, win, ")
                        .append(" query, domConstruct){\n").append("var rN = dom.byId('")
                        .append(resultPanel.getMarkupId()).append("');\n")
                        .append("var dialog = registry.byId(rN.id);")
                        .append("if (typeof(dialog) !== \"undefined\") {\n").append("popup.close(dialog);")
                        .append("registry.remove(dialog.id);").append("}\n").append("var vs = win.getBox();\n")
                        .append("var wi = (vs.w - 100) + 'px';\n").append("var wh = (vs.h - 150) + 'px';\n")
                        .append("query(\".searchOverlay\").forEach(domConstruct.destroy);\n")
                        .append("var ov = domConstruct.create(\"div\", {'class' : 'searchOverlay'}, ")
                        .append("baseWindow.body());\n")
                        .append("query('.searchOverlay').on('click', function (e) {\n")
                        .append("popup.close(registry.byId(rN.id));\n").append("});\n")
                        .append("query(\".resultPlaceholder\", rN).style(\"width\", wi);\n")
                        .append("query('.resultContainer', rN).style('height', wh);")
                        .append("query('.resultClose', rN).on(\"click\", function(e){\n")
                        .append("popup.close(registry.byId(rN.id));\n").append("});\n")
                        .append("dialog = new TooltipDialog({}, rN);\n").append("popup.open({\n")
                        .append("popup: dialog,")
                        .append("orient: [ \"below-centered\", \"below-alt\", \"below\"],")
                        .append("onClose: function(){\n")
                        .append("query(\".searchOverlay\").forEach(domConstruct.destroy);\n").append("")
                        .append("},\n").append("around: dom.byId('").append(form.getMarkupId()).append("')")
                        .append("});").append("});");
                _target.appendJavaScript(js);
            }
        }

        @Override
        public void onComponentTagBody(final MarkupStream _markupStream, final ComponentTag _openTag) {
            replaceComponentTagBody(_markupStream, _openTag,
                    DBProperties.getProperty(SearchPanel.class.getName() + ".Button"));
        }
    };
    form.add(button);
    form.setDefaultButton(button);
}

From source file:org.wicketstuff.stateless.behaviors.StatelessAjaxFormSubmitBehavior.java

License:Apache License

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);

    Form<?> form = findForm();
    attributes.setFormId(form.getMarkupId());

    String formMethod = form.getMarkupAttributes().getString("method");
    if (formMethod == null || "POST".equalsIgnoreCase(formMethod)) {
        attributes.setMethod(Method.POST);
    }//from w  ww .j  a v  a2  s  . c  o m

    if (form.getRootForm().isMultiPart()) {
        attributes.setMultipart(true);
        attributes.setMethod(Method.POST);
    }

    attributes.setPreventDefault(true);
}

From source file:org.wicketstuff.validation.client.AbstractClientAndServerValidatingBehavior.java

License:Apache License

protected Map<String, Object> variablesMap(Form<?> form, FormComponent<T> component) {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("form", form.getMarkupId());
    vars.put("label", component.getMarkupId());
    vars.put("input", "{VAL}");
    return vars;//  w  w  w.  j  ava 2  s .com
}