Example usage for org.apache.wicket.ajax AjaxRequestTarget prependJavaScript

List of usage examples for org.apache.wicket.ajax AjaxRequestTarget prependJavaScript

Introduction

In this page you can find the example usage for org.apache.wicket.ajax AjaxRequestTarget prependJavaScript.

Prototype

void prependJavaScript(CharSequence javascript);

Source Link

Document

Adds javascript that will be evaluated on the client side before components are replaced.

Usage

From source file:org.opensingular.lib.wicket.util.modal.BSModalBorder.java

License:Apache License

public void hide(AjaxRequestTarget target) {
    // limpo os valores, pois erros de validacao impedem o formulario de se ser recarregado 
    clearInputs();//  ww  w  . j a v a  2s . c  o  m

    this.setVisible(false);

    if (target != null) {
        final String blockingFunction = "hide_hidden_wicket_modal";
        target.prependJavaScript(blockingFunction + "|" + getHideJavaScriptCallback(blockingFunction));
        target.add(this);
    }
}

From source file:org.projectforge.web.fibu.RechnungCostEditTablePanel.java

License:Open Source License

@SuppressWarnings("serial")
public RechnungCostEditTablePanel add(final AbstractRechnungsPositionDO origPosition) {
    if (origPosition instanceof RechnungsPositionDO) {
        position = new RechnungsPositionDO();
    } else {//from w  w w.ja v  a 2s.  co m
        position = new EingangsrechnungsPositionDO();
    }
    position.copyValuesFrom(origPosition, "kostZuweisungen");
    new KostZuweisungenCopyHelper().mycopy(origPosition.getKostZuweisungen(), null, position);
    List<KostZuweisungDO> kostzuweisungen = position.getKostZuweisungen();
    if (CollectionUtils.isEmpty(kostzuweisungen) == true) {
        addZuweisung(position);
        kostzuweisungen = position.getKostZuweisungen();
    }
    for (final KostZuweisungDO zuweisung : kostzuweisungen) {
        final WebMarkupContainer row = createRow(rows.newChildId(), position, zuweisung);
        rows.add(row);
    }
    final Label restLabel = new Label("restValue", new Model<String>() {
        /**
         * @see org.apache.wicket.model.Model#getObject()
         */
        @Override
        public String getObject() {
            return CurrencyFormatter.format(position.getKostZuweisungNetFehlbetrag());
        }
    });
    form.add(restLabel);
    ajaxComponents.register(restLabel);
    final AjaxButton addRowButton = new AjaxButton(ButtonPanel.BUTTON_ID, form) {
        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            final KostZuweisungDO zuweisung = addZuweisung(position);
            final WebMarkupContainer newRow = createRow(rows.newChildId(), position, zuweisung);
            newRow.setOutputMarkupId(true);
            final StringBuffer prependJavascriptBuf = new StringBuffer();
            prependJavascriptBuf
                    .append(WicketAjaxUtils.appendChild("costAssignmentBody", "tr", newRow.getMarkupId()));
            rows.add(newRow);
            target.add(newRow);
            ajaxComponents.addTargetComponents(target);
            target.prependJavaScript(prependJavascriptBuf.toString());
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            target.add(feedbackPanel);
        }
    };
    // addRowButton.setDefaultFormProcessing(false);
    final SingleButtonPanel addPositionButtonPanel = new SingleButtonPanel("addRowButton", addRowButton,
            getString("add"));
    form.add(addPositionButtonPanel);

    final AjaxButton recalculateButton = new AjaxButton(ButtonPanel.BUTTON_ID, form) {
        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            ajaxComponents.addTargetComponents(target);
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            target.add(feedbackPanel);
        }
    };
    // recalculateButton.setDefaultFormProcessing(false);
    final SingleButtonPanel recalculateButtonPanel = new SingleButtonPanel("recalculateButton",
            recalculateButton, getString("recalculate"));
    form.add(recalculateButtonPanel);

    return this;
}

From source file:org.projectforge.web.fibu.RechnungCostEditTablePanel.java

License:Open Source License

@SuppressWarnings("serial")
private WebMarkupContainer createRow(final String id, final AbstractRechnungsPositionDO position,
        final KostZuweisungDO zuweisung) {
    final WebMarkupContainer row = new WebMarkupContainer(id);
    row.setOutputMarkupId(true);//  ww  w. jav  a 2 s.com
    final Kost1FormComponent kost1 = new Kost1FormComponent("kost1",
            new PropertyModel<Kost1DO>(zuweisung, "kost1"), true);
    kost1.setLabel(new Model<String>(getString("fibu.kost1")));
    row.add(kost1);
    ajaxComponents.register(kost1);
    final Kost2FormComponent kost2 = new Kost2FormComponent("kost2",
            new PropertyModel<Kost2DO>(zuweisung, "kost2"), true);
    kost2.setLabel(new Model<String>(getString("fibu.kost2")));
    row.add(kost2);
    ajaxComponents.register(kost2);

    final MinMaxNumberField<BigDecimal> netto = new MinMaxNumberField<BigDecimal>("netto",
            new PropertyModel<BigDecimal>(zuweisung, "netto"), BigDecimal.ZERO, position.getNetSum()) {
        @SuppressWarnings({ "rawtypes", "unchecked" })
        @Override
        public IConverter getConverter(final Class type) {
            return new CurrencyConverter(position.getNetSum());
        }
    };
    netto.setLabel(new Model<String>(getString("fibu.common.netto")));
    WicketUtils.addTooltip(netto, getString("currencyConverter.percentage.help"));
    row.add(netto);
    ajaxComponents.register(netto); // Should be updated if e. g. percentage value is given.
    final Label pLabel = new Label("percentage", new Model<String>() {
        /**
         * @see org.apache.wicket.model.Model#getObject()
         */
        @Override
        public String getObject() {
            final BigDecimal percentage;
            if (NumberHelper.isZeroOrNull(position.getNetSum()) == true
                    || NumberHelper.isZeroOrNull(zuweisung.getNetto()) == true) {
                percentage = BigDecimal.ZERO;
            } else {
                percentage = zuweisung.getNetto().divide(position.getNetSum(), RoundingMode.HALF_UP);
            }
            final boolean percentageVisible = NumberHelper.isNotZero(percentage);
            if (percentageVisible == true) {
                return NumberFormatter.formatPercent(percentage);
            } else {
                return " ";
            }
        }
    });
    ajaxComponents.register(pLabel);
    row.add(pLabel);

    if (position.isKostZuweisungDeletable(zuweisung) == true) {
        final AjaxButton deleteRowButton = new AjaxButton(ButtonPanel.BUTTON_ID, form) {
            @Override
            protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
                position.deleteKostZuweisung(zuweisung.getIndex());
                final StringBuffer prependJavascriptBuf = new StringBuffer();
                prependJavascriptBuf
                        .append(WicketAjaxUtils.removeChild("costAssignmentBody", row.getMarkupId()));
                ajaxComponents.remove(row);
                rows.remove(row);
                target.prependJavaScript(prependJavascriptBuf.toString());
            }

            @Override
            protected void onError(final AjaxRequestTarget target, final Form<?> form) {
                target.add(feedbackPanel.setVisible(true));
            }
        };
        deleteRowButton.setDefaultFormProcessing(false);
        row.add(new IconButtonPanel("deleteEntry", deleteRowButton, IconType.TRASH, null).setLight());
    } else {
        // Don't show a delete button.
        row.add(new Label("deleteEntry", "&nbsp;").setEscapeModelStrings(false).setRenderBodyOnly(true));
    }
    return row;
}

From source file:org.projectforge.web.tree.DefaultTreeTablePanel.java

License:Open Source License

@SuppressWarnings("unchecked")
public void setEvent(final AjaxRequestTarget target, final TreeTableEvent event, final TreeTableNode node) {
    if (onSetEvent(target, event, node) == false) {
        return;/*  w ww.ja  v a2s. com*/
    }
    if (treeTableBody == null) {
        log.error("Oups, treeTableContainer is null. Ignoring Ajax event.");
        return;
    }
    if (log.isDebugEnabled() == true) {
        log.debug("setEvent: node=" + node.getHashId() + ", event=" + event + ", nodeStatus="
                + node.getNodeStatus());
    }
    final Component currentRow = getTreeRow(node.getHashId());
    final AbstractLink link = (AbstractLink) currentRow.get("c1:icons:folder");
    if (event == TreeTableEvent.OPEN || event == TreeTableEvent.EXPLORE) {
        final StringBuffer prependJavascriptBuf = new StringBuffer();
        {
            // Add all childs
            final Component row = getTreeRowAfter(node.getHashId());
            refresh(); // Force to rebuild tree list.
            for (final T child : getTreeTable().getDescendants(getTreeList(), (T) node)) {
                final WebMarkupContainer newRow = createTreeRow(child);
                if (row != null) {
                    prependJavascriptBuf.append(WicketAjaxUtils.insertBefore(treeTableBody.getMarkupId(),
                            row.getMarkupId(), "tr", newRow.getMarkupId()));
                } else {
                    prependJavascriptBuf.append(WicketAjaxUtils.appendChild(treeTableBody.getMarkupId(), "tr",
                            newRow.getMarkupId()));
                }
                target.add(newRow);
            }
        }
        {
            // Replace opened-folder-icon by closed-folder-icon.
            replaceFolderImage(target, link, node, prependJavascriptBuf);
        }
        final String javaScript = prependJavascriptBuf.toString();
        if (javaScript.length() > 0) {
            target.prependJavaScript(javaScript);
        }
        target.appendJavaScript("updateEvenOdd();");
    } else {
        // Remove all childs
        final StringBuffer prependJavascriptBuf = new StringBuffer();
        final Iterator<Component> it = rowRepeater.iterator();
        final List<Component> toRemove = new ArrayList<Component>();
        while (it.hasNext() == true) {
            final Component row = it.next();
            final TreeTableNode model = (TreeTableNode) row.getDefaultModelObject();
            if (node.isParentOf(model) == true) {
                prependJavascriptBuf
                        .append(WicketAjaxUtils.removeChild(treeTableBody.getMarkupId(), row.getMarkupId()));
                toRemove.add(row);
            }
        }
        for (final Component row : toRemove) {
            rowRepeater.remove(row);
        }
        {
            // Replace closed-folder-icon by opened-folder-icon.
            replaceFolderImage(target, link, node, prependJavascriptBuf);
        }
        final String javaScript = prependJavascriptBuf.toString();
        if (javaScript.length() > 0) {
            target.prependJavaScript(javaScript);
        }
        target.appendJavaScript("updateEvenOdd();");
    }
}

From source file:org.sakaiproject.profile2.tool.pages.panels.MessageView.java

License:Educational Community License

/**
 * Does the actual rendering of the page
 * @param currentUserUuid//ww w . ja  v a 2  s  .c om
 * @param threadId
 * @param threadSubject
 */
private void renderMyMessagesView(final String currentUserUuid, final String threadId,
        final String threadSubject) {

    //details container
    WebMarkupContainer messageDetailsContainer = new WebMarkupContainer("messageDetailsContainer");
    messageDetailsContainer.setOutputMarkupId(true);

    //thread subject
    Label threadSubjectLabel = new Label("threadSubject", new Model<String>(threadSubject));
    messageDetailsContainer.add(threadSubjectLabel);

    add(messageDetailsContainer);

    //list container
    messageListContainer = new WebMarkupContainer("messageListContainer");
    messageListContainer.setOutputMarkupId(true);

    //get our list of messages
    final MessagesDataProvider provider = new MessagesDataProvider(threadId);

    messageList = new DataView<Message>("messageList", provider) {
        private static final long serialVersionUID = 1L;

        protected void populateItem(final Item<Message> item) {

            final Message message = (Message) item.getDefaultModelObject();
            final String messageFromUuid = message.getFrom();

            //we need to know if this message has been read or not so we can style it accordingly
            //we only need this if we didn't send the message
            MessageParticipant participant = null;

            boolean messageOwner = false;
            if (StringUtils.equals(messageFromUuid, currentUserUuid)) {
                messageOwner = true;
            }
            if (!messageOwner) {
                participant = messagingLogic.getMessageParticipant(message.getId(), currentUserUuid);
            }

            //prefs and privacy
            ProfilePreferences prefs = preferencesLogic.getPreferencesRecordForUser(messageFromUuid);
            ProfilePrivacy privacy = privacyLogic.getPrivacyRecordForUser(messageFromUuid);

            //photo link
            AjaxLink<String> photoLink = new AjaxLink<String>("photoLink", new Model<String>(messageFromUuid)) {
                private static final long serialVersionUID = 1L;

                public void onClick(AjaxRequestTarget target) {
                    setResponsePage(new ViewProfile(getModelObject()));
                }

            };

            //photo
            /* disabled for now
            ProfileImage messagePhoto = new ProfileImage("messagePhoto", new Model<String>(messageFromUuid));
            messagePhoto.setSize(ProfileConstants.PROFILE_IMAGE_THUMBNAIL);
            photoLink.add(messagePhoto);
            */
            item.add(photoLink);

            //name link
            AjaxLink<String> messageFromLink = new AjaxLink<String>("messageFromLink",
                    new Model<String>(messageFromUuid)) {
                private static final long serialVersionUID = 1L;

                public void onClick(AjaxRequestTarget target) {
                    setResponsePage(new ViewProfile(getModelObject()));
                }

            };
            messageFromLink.add(new Label("messageFromName",
                    new Model<String>(sakaiProxy.getUserDisplayName(messageFromUuid))));
            item.add(messageFromLink);

            //date
            item.add(new Label("messageDate", ProfileUtils.convertDateToString(message.getDatePosted(),
                    ProfileConstants.MESSAGE_DISPLAY_DATE_FORMAT)));

            //message body
            item.add(new Label("messageBody", new Model<String>(message.getMessage())));

            //highlight if new, then mark it as read
            if (!messageOwner && !participant.isRead()) {
                item.add(new AttributeAppender("class", true, new Model<String>("unread-message"), " "));
                messagingLogic.toggleMessageRead(participant, true);

                //set param for first unread message in the thread
                if (!lastUnreadSet) {
                    lastUnreadSet = true;
                    item.add(new AttributeModifier("rel", true, new Model<String>("lastUnread")));
                }

            }

            item.setOutputMarkupId(true);

        }

    };
    messageList.setOutputMarkupId(true);
    messageListContainer.add(messageList);
    add(messageListContainer);

    //reply form
    StringModel stringModel = new StringModel();
    Form<StringModel> replyForm = new Form<StringModel>("replyForm", new Model<StringModel>(stringModel));

    //form feedback
    final Label formFeedback = new Label("formFeedback");
    formFeedback.setOutputMarkupPlaceholderTag(true);
    add(formFeedback);

    //reply field
    replyForm.add(new Label("replyLabel", new ResourceModel("message.reply")));
    final TextArea<StringModel> replyField = new TextArea<StringModel>("replyField",
            new PropertyModel<StringModel>(stringModel, "string"));
    replyField.setRequired(true);
    replyField.setOutputMarkupId(true);
    replyForm.add(replyField);

    //reply button
    IndicatingAjaxButton replyButton = new IndicatingAjaxButton("replyButton", replyForm) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {

            StringModel stringModel = (StringModel) form.getModelObject();
            String reply = stringModel.getString();

            //create a direct link to view this message thread
            //String messageLink = sakaiProxy.getDirectUrlToUserProfile(newMessage.getTo(), urlFor(MyMessageView.class, new PageParameters("thread=" + threadId)).toString());

            //send it, get Message back so we can add it to the list
            Message message = messagingLogic.replyToThread(threadId, reply, currentUserUuid);
            if (message != null) {
                //clear this field
                replyField.setModelObject(null);
                target.add(replyField);

                //create new item and add it to the list
                //do we need to register this with the listview?
                Component item = buildItem(message);
                target.prependJavaScript(String.format(
                        "var item=document.createElement('%s');item.id='%s';Wicket.$('%s').appendChild(item);",
                        "tr", item.getMarkupId(), messageListContainer.getMarkupId()));
                target.add(item);

                //repaint the list of messages in this thread
                //target.addComponent(messageListContainer);

                //resize
                target.appendJavaScript("setMainFrameHeight(window.name);");
            }

        }

        protected void onError(AjaxRequestTarget target, Form form) {

            //validate
            if (!replyField.isValid()) {
                formFeedback.setDefaultModel(new ResourceModel("error.message.required.body"));
            }
            formFeedback.add(new AttributeModifier("class", true, new Model<String>("alertMessage")));
            target.add(formFeedback);
        }
    };
    replyForm.add(replyButton);
    replyButton.setModel(new ResourceModel("button.message.send"));

    add(replyForm);

}

From source file:org.sakaiproject.profile2.tool.pages.panels.MyBusinessEdit.java

License:Educational Community License

private AjaxFallbackButton createAddCompanyProfileButton(final String id, final UserProfile userProfile,
        Form form, final Label formFeedback) {
    AjaxFallbackButton addCompanyProfileButton = new AjaxFallbackButton("addCompanyProfileButton",
            new ResourceModel("button.business.add.profile"), form) {

        private static final long serialVersionUID = 1L;

        @Override//from w  ww  . j av  a 2s.c o  m
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            CompanyProfile companyProfileToAdd = new CompanyProfile(userProfile.getUserUuid(), "", "", "");
            companyProfilesToAdd.add(companyProfileToAdd);
            userProfile.addCompanyProfile(companyProfileToAdd);

            Component newPanel = new MyBusinessEdit(id, userProfile, companyProfilesToAdd,
                    companyProfilesToRemove, TabDisplay.END);
            newPanel.setOutputMarkupId(true);
            MyBusinessEdit.this.replaceWith(newPanel);

            if (target != null) {
                target.add(newPanel);
                // resize iframe
                target.prependJavaScript("setMainFrameHeight(window.name);");
            }
        }
    };
    return addCompanyProfileButton;
}

From source file:org.sakaiproject.profile2.tool.pages.panels.MyStatusPanel.java

License:Educational Community License

public MyStatusPanel(String id, UserProfile userProfile) {
    super(id);//from w  ww  . ja  va 2  s . c  o  m

    log.debug("MyStatusPanel()");

    //get info
    final String displayName = userProfile.getDisplayName();
    final String userId = userProfile.getUserUuid();

    //if superUser and proxied, can't update
    boolean editable = true;
    if (sakaiProxy.isSuperUserAndProxiedToUser(userId)) {
        editable = false;
    }

    //name
    Label profileName = new Label("profileName", displayName);
    add(profileName);

    //status component
    status = new ProfileStatusRenderer("status", userId, null, "tiny") {
        @Override
        public boolean isVisible() {
            return this.hasStatusSet() && sakaiProxy.isProfileStatusEnabled();
        }
    };
    status.setOutputMarkupId(true);
    add(status);

    //clear link
    final AjaxFallbackLink clearLink = new AjaxFallbackLink("clearLink") {
        private static final long serialVersionUID = 1L;

        public void onClick(AjaxRequestTarget target) {
            //clear status, hide and repaint
            if (statusLogic.clearUserStatus(userId)) {
                status.setVisible(false); //hide status
                this.setVisible(false); //hide clear link
                target.add(status);
                target.add(this);
            }
        }

        @Override
        public boolean isVisible() {
            return status.isVisible(); //if there is text to show
        }
    };
    clearLink.setOutputMarkupPlaceholderTag(true);
    clearLink.add(new Label("clearLabel", new ResourceModel("link.status.clear")));

    add(clearLink);

    WebMarkupContainer statusFormContainer = new WebMarkupContainer("statusFormContainer") {
        @Override
        public boolean isVisible() {
            return sakaiProxy.isProfileStatusEnabled();
        }
    };

    //setup SimpleText object to back the single form field 
    StringModel stringModel = new StringModel();

    //status form
    Form form = new Form("form", new Model(stringModel));
    form.setOutputMarkupId(true);

    //status field
    final TextField statusField = new TextField("message", new PropertyModel(stringModel, "string"));
    statusField.setMarkupId("messageinput");
    statusField.setOutputMarkupId(true);
    statusField.setOutputMarkupPlaceholderTag(true);
    statusField.add(new StatusFieldCounterBehaviour());
    form.add(statusField);

    //link the status textfield field with the focus/blur function via this dynamic js 
    //also link with counter
    //add(new StatusFieldCounterBehaviour());

    //submit button
    IndicatingAjaxButton submitButton = new IndicatingAjaxButton("submit", form) {

        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {

            //get the backing model
            StringModel stringModel = (StringModel) form.getModelObject();

            //get userId from sakaiProxy
            String userId = sakaiProxy.getCurrentUserId();

            //get the status. if its the default text, do not update, although we should clear the model
            String statusMessage = StringUtils.trim(stringModel.getString());
            if (StringUtils.isBlank(statusMessage) || StringUtils.equals(statusMessage, defaultStatus)) {
                log.warn("Status for userId: " + userId
                        + " was not updated because they didn't enter anything.");
                return;
            }

            //save status from userProfile
            if (statusLogic.setUserStatus(userId, statusMessage)) {
                log.info("Saved status for: " + userId);

                //post update event
                sakaiProxy.postEvent(ProfileConstants.EVENT_STATUS_UPDATE, "/profile/" + userId, true);

                //update twitter
                externalIntegrationLogic.sendMessageToTwitter(userId, statusMessage);

                // post to walls if wall enabled
                if (true == sakaiProxy.isWallEnabledGlobally()) {
                    wallLogic.addNewStatusToWall(statusMessage, sakaiProxy.getCurrentUserId());
                }

                //repaint status component
                ProfileStatusRenderer newStatus = new ProfileStatusRenderer("status", userId, null, "tiny");
                newStatus.setOutputMarkupId(true);
                status.replaceWith(newStatus);
                newStatus.setVisible(true);

                //also show the clear link
                clearLink.setVisible(true);

                if (target != null) {
                    target.add(newStatus);
                    target.add(clearLink);
                    status = newStatus; //update reference

                    //reset the field
                    target.appendJavaScript(
                            "autoFill('#" + statusField.getMarkupId() + "', '" + defaultStatus + "');");

                    //reset the counter
                    target.appendJavaScript("countChars('#" + statusField.getMarkupId() + "');");

                }

            } else {
                log.error("Couldn't save status for: " + userId);
                String js = "alert('Failed to save status. If the problem persists, contact your system administrator.');";
                target.prependJavaScript(js);
            }

        }
    };
    submitButton.setModel(new ResourceModel("button.sayit"));
    form.add(submitButton);

    //add form to container
    statusFormContainer.add(form);

    //if not editable, hide the entire form
    if (!editable) {
        statusFormContainer.setVisible(false);
    }

    add(statusFormContainer);

}

From source file:org.sakaiproject.sitestats.tool.wicket.components.useractivity.EventRefDetailsButtonPanel.java

License:Educational Community License

@Override
protected void onInitialize() {
    super.onInitialize();

    Form<Void> form = new Form<>("moreDetailsForm");
    SakaiAjaxButton button = new SakaiAjaxButton("moreDetailsButton", form) {
        @Override/* ww w  .  ja  v a 2s.  c  o  m*/
        public void onSubmit(AjaxRequestTarget target, Form form) {
            if (target != null) {
                DetailedEvent de = EventRefDetailsButtonPanel.this.getModelObject();
                EventRefDetailsPanel panel = new EventRefDetailsPanel("details", de.getEventId(),
                        de.getEventRef(), siteID);
                panel.setOutputMarkupId(true);
                form.getParent().replace(panel);
                target.add(panel);
                setVisible(false);
                target.add(this);
                target.prependJavaScript(
                        String.format("$('#%s').closest('td').removeAttr('data-label');", getMarkupId()));
            }
        }
    };
    form.add(button);
    add(form);

    add(new WebMarkupContainer("details").setOutputMarkupPlaceholderTag(true));
}

From source file:org.wicketstuff.datatable_autocomplete.panel.AutoCompletingTextField.java

License:Apache License

/**
 * /*from ww  w  .  j  a v a2 s.co m*/
 * @param id
 * @param searchFieldModel
 *            model that contains the prefix used in filtering the results.
 * @param rowsPerPage
 *            number of rows to show per page.
 * @param columns
 *            the columns to show in the @see {@link AutoCompletingPanel}
 * @param provider
 *            provides the data for the autocompleting panel.
 * @param rowSelectionHandler
 *            This is what handles the assignment of the selected row somewhere.
 * @param usePagination
 *            allows turning on or off the pagination controls.
 * @param throttlingDelay
 *            Controls the number of miliseconds to wait after a keystroke before issuing the
 *            get request to the server.
 * @param renderingHints2
 */
public AutoCompletingTextField(String id, IModel<String> searchFieldModel, IColumn<?>[] columns,
        SortableDataProvider<R> provider, ITableRowSelectionHandler<R> rowSelectionHandler,
        IAutocompleteControlPanelProvider controlPanelProvider, int throttlingDelay,
        IAutocompleteRenderingHints renderingHints) {

    // dummy model.
    // we are a formcomponentpanel so that we are traversed during form
    // submissions.
    super(id);
    this.searchFieldModel = searchFieldModel;
    this.renderingHints = renderingHints;

    searchField = new TextField<String>("searchField", searchFieldModel);

    searchField.add(AttributeModifier.replace("autocomplete", "off"));

    autoCompletingPanel = new AutoCompletingPanel<R>("autoCompletingPanel", searchField.getModel(), columns,
            provider, rowSelectionHandler, controlPanelProvider, renderingHints);

    add(searchField);

    add(autoCompletingPanel);

    searchField.add(autoCompletingBehaviour = new AutoCompletingBehavior(searchField, autoCompletingPanel,
            throttlingDelay));

    add(new AjaxLink<Void>("showLink") {

        /**
         *
         */
        private static final long serialVersionUID = -5603196048089462726L;

        /*
         * (non-Javadoc)
         * 
         * @see org.apache.wicket.ajax.markup.html.AjaxLink#onClick(org.apache.wicket.ajax.
         * AjaxRequestTarget)
         */
        @Override
        public void onClick(AjaxRequestTarget target) {

            String callbackScript = autoCompletingBehaviour.getCallbackScript().toString();

            target.prependJavaScript(callbackScript);

        }

    });

}

From source file:org.wicketstuff.datatable_autocomplete.table.button.ButtonListView.java

License:Apache License

@Override
protected void populateItem(ListItem<ISelectableTableViewPanelButtonProvider> item) {

    final ISelectableTableViewPanelButtonProvider buttonProvider = item.getModelObject();

    IFormOnSubmitAction buttonAction = buttonProvider.getButtonAction();

    if (buttonAction == null) {
        Label label;//w ww  .ja va2  s  .  co m
        // not visible
        item.add(label = new Label(BUTTON_ID));

        label.setVisible(false);

        item.add(label);

        return;
    }

    // if the tow is required then
    buttonAction = new AbstractFormOnSubmitAction() {

        /**
            * 
            */
        private static final long serialVersionUID = 5910571859628875165L;

        public void onSubmit(AjaxRequestTarget target, Form<?> form) {

            if (buttonProvider.isSelectedRowRequired()) {

                if (selectedContextField.getModelObject() == null) {
                    if (target != null) {
                        target.prependJavaScript("alert ('A selected row is required.');");
                    } else
                        error("A selected row is required.");

                    return;
                }

                // fall through
            }

            // run the user logic
            buttonProvider.getButtonAction().onSubmit(target, form);

            // else the action is defined.
            if (buttonProvider.isClearSelectedRowOnAction()) {
                // clear the value in the form.
                selectedContextField.clearInput();
            }

        }

    };

    DTAAjaxFallbackButton button;

    // if (buttonProvider.isSelectedRowRequired()) {
    //
    // IModel<String> requireASelectedRow;
    //
    // final List<Radio>radioList = new LinkedList<Radio>();
    //
    // if (selectedContextField instanceof RadioGroup) {
    // RadioGroup rg = (RadioGroup) selectedContextField;
    //
    // rg.visitChildren(new IVisitor() {
    //
    // /* (non-Javadoc)
    // * @see org.apache.wicket.Component.IVisitor#component(org.apache.wicket.Component)
    // */
    // public Object component(Component component) {
    //
    // if (component instanceof Radio) {
    //
    // radioList.add((Radio) component);
    // }
    //
    // return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
    // }
    //
    // });
    //
    //
    // requireASelectedRow = createRadioRequireSelectedRowModel (radioList);
    //
    // }
    // else {
    // // String hidden field
    //
    //
    // requireASelectedRow = new MarkupIDInStringModel(
    // "if (Wicket.$('" + MarkupIDInStringModel.MARKUP_ID_TAG
    // + "').value == '') {"
    // + "\nalert ('A selected row is required.');"
    // + "\nreturn false;" + "}", selectedContextField);
    // }
    //
    // button = new DTAAjaxFallbackButton(BUTTON_ID, buttonProvider
    // .getButtonLabelText(displayEntityName), this.form,
    // requireASelectedRow);
    //
    // button.setSubmitAction(buttonAction);
    // }
    // else {

    button = new DTAAjaxFallbackButton(BUTTON_ID, buttonProvider.getButtonLabelText(displayEntityName), form,
            buttonAction);
    // }

    String cssClass = buttonProvider.getCSSClassName();

    if (cssClass != null) {
        button.add(AttributeModifier.replace("class", cssClass));
    }

    item.add(button);

}