List of usage examples for org.apache.wicket.ajax.markup.html.form AjaxSubmitLink AjaxSubmitLink
public AjaxSubmitLink(String id, final Form<?> form)
From source file:com.axway.ats.testexplorer.pages.model.ColumnsDialog.java
License:Apache License
@SuppressWarnings({ "rawtypes" }) public ColumnsDialog(String id, final DataGrid grid, List<TableColumn> columnDefinitions) { super(id);//from w w w. jav a2 s. c o m setOutputMarkupId(true); this.dbColumnDefinitions = columnDefinitions; DataView<TableColumn> table = new DataView<TableColumn>("headers", new ListDataProvider<TableColumn>(dbColumnDefinitions), 100) { private static final long serialVersionUID = 1L; @Override protected void populateItem(final Item<TableColumn> item) { final TableColumn column = item.getModelObject(); item.add(new CheckBox("visible", new PropertyModel<Boolean>(column, "visible"))); item.add(new Label("columnName", new PropertyModel<String>(column, "columnName"))); item.add(new AjaxEventBehavior("click") { private static final long serialVersionUID = 1L; @Override protected void onEvent(AjaxRequestTarget target) { TableColumn tableColumn = (TableColumn) this.getComponent().getDefaultModelObject(); tableColumn.setVisible(!tableColumn.isVisible()); if (tableColumn.isVisible()) { item.add(AttributeModifier.replace("class", "selected")); } else { item.add(AttributeModifier.replace("class", "notSelected")); } grid.getColumnState().setColumnVisibility(tableColumn.getColumnId(), tableColumn.isVisible()); target.add(grid); target.add(this.getComponent()); open(target); } }); item.setOutputMarkupId(true); if (column.isVisible()) { item.add(AttributeModifier.replace("class", "selected")); } else { item.add(AttributeModifier.replace("class", "notSelected")); } } }; add(table); final Form<Void> columnDefinitionsForm = new Form<Void>("columnDefinitionsForm"); add(columnDefinitionsForm); AjaxSubmitLink saveButton = new AjaxSubmitLink("saveButton", columnDefinitionsForm) { private static final long serialVersionUID = 1L; @Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); AjaxCallListener ajaxCallListener = new AjaxCallListener(); ajaxCallListener.onPrecondition("getTableColumnDefinitions(); "); attributes.getAjaxCallListeners().add(ajaxCallListener); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { String columnDefinitionsString = form.getRequest().getPostParameters() .getParameterValue("columnDefinitions").toString(); List<TableColumn> jsColDefinitions = asList(columnDefinitionsString); orderTableColumns(dbColumnDefinitions, jsColDefinitions); try { saveColumnDefinitionsToDb(jsColDefinitions); modifyDBColumnDefinitionList(jsColDefinitions); } catch (DatabaseAccessException dae) { throw new RuntimeException("Unable to save table Column definitions in db: " + ((TestExplorerSession) Session.get()).getDbName(), dae); } catch (SQLException sqle) { throw new RuntimeException("Unable to save table Column definitions in db: " + ((TestExplorerSession) Session.get()).getDbName(), sqle); } close(target); } }; add(AttributeModifier.append("class", "runsTableColDialogDivWrapper")); columnDefinitionsForm.add(saveButton); add(new Behavior() { private static final long serialVersionUID = 1L; @Override public void renderHead(Component component, IHeaderResponse response) { if (autoAddToHeader()) { String script = "jQuery.fn.center=function(){" + "this.css(\"position\",\"absolute\");" + "this.css(\"top\",(jQuery(window).height()-this.height())/2+jQuery(window).scrollTop()+\"px\");" + "this.css(\"left\",(jQuery(window).width()-this.width())/2+jQuery(window).scrollLeft()+\"px\");" + "return this};"; String css = "#settingsoverlay,.settingsoverlay,#settingsoverlay_high," + ".settingsoverlay_high{filter:Alpha(Opacity=40);" + "-moz-opacity:.4;opacity:.4;background-color:#444;display:none;position:absolute;" + "left:0;top:0;width:100%;height:100%;text-align:center;z-index:5000;}" + "#settingsoverlay_high,.settingsoverlay_high{z-index:6000;}" + "#settingsoverlaycontent,#settingsoverlaycontent_high{display:none;z-index:5500;" + "text-align:center;}.settingsoverlaycontent," + ".settingsoverlaycontent_high{display:none;z-index:5500;text-align:left;}" + "#settingsoverlaycontent_high,.settingsoverlaycontent_high{z-index:6500;}" + "#settingsoverlaycontent .modalborder," + "#settingsoverlaycontent_high .modalborder{padding:15px;width:300px;" + "border:1px solid #444;background-color:white;" + "-webkit-box-shadow:0 0 10px rgba(0,0,0,0.8);-moz-box-shadow:0 0 10px rgba(0,0,0,0.8);" + "box-shadow:0 0 10px rgba(0,0,0,0.8);" + "filter:progid:DXImageTransform.Microsoft.dropshadow(OffX=5,OffY=5,Color='gray');" + "-ms-filter:\"progid:DXImageTransform.Microsoft.dropshadow(OffX=5,OffY=5,Color='gray')\";}"; response.render(JavaScriptHeaderItem.forScript(script, null)); response.render(CssHeaderItem.forCSS(css, null)); if (isSupportIE6()) { response.render(JavaScriptHeaderItem .forReference(new PackageResourceReference(getClass(), "jquery.bgiframe.js"))); } } response.render(OnDomReadyHeaderItem.forScript(getJS())); } private String getJS() { StringBuilder sb = new StringBuilder(); sb.append("if (jQuery('#").append(getDivId()) .append("').length == 0) { jQuery(document.body).append('") .append(getDiv().replace("'", "\\'")).append("'); }"); return sb.toString(); } private String getDivId() { return getMarkupId() + "_ovl"; } private String getDiv() { if (isClickBkgToClose()) { return ("<div id=\"" + getDivId() + "\" class=\"settingsoverlayCD\" onclick=\"" + getCloseString() + "\"></div>"); } else { return ("<div id=\"" + getDivId() + "\" class=\"settingsoverlayCD\"></div>"); } } }); }
From source file:com.cubeia.backoffice.web.user.UserReportPanel.java
License:Open Source License
public UserReportPanel(String id, final ModalWindow modal) { super(id);/*from w w w .j ava 2 s.co m*/ Form<?> form = new Form<Void>("form"); form.setOutputMarkupId(true); form.add(new AjaxSubmitLink("reportLink", form) { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { String url = getRequest().getContextPath() + "reportbuilder/reports/users/?format=" + format; target.appendJavaScript("document.location = '" + url + "'"); modal.close(target); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { // nothing to do here... } }); RadioGroup<String> formatGroup = new RadioGroup<String>("formatGroup", new PropertyModel<String>(this, "format")); formatGroup.add(new Radio<String>("csv", Model.of("csv"))); formatGroup.add(new Radio<String>("xls", Model.of("xls"))); formatGroup.add(new Radio<String>("pdf", Model.of("pdf"))); form.add(formatGroup); add(form); }
From source file:com.googlecode.wicketwebbeans.actions.BeanSubmitButton.java
License:Apache License
/** * Construct a BeanSubmitButton. The link has a class of "beanSubmitButton" if label is a * regular Label, otherwise the class is "beanSubmitImageButton". * * Note that updateFeedbackPanels(target) will not work if the action * makes you change context. In this case, you should avoid doing * something after BeanSubmitButton.this.onAction() * * @param id//from w ww . jav a 2s . c o m * @param label * @param form * @param bean * @param confirmMsg if non-null, a confirm message will be displayed before the action is taken. * If the answer is "Yes", the action is taken, otherwise it is canceled. * @param ajaxFlag if a string whose value is "true", the button's action is fired with an Ajax form submit. * Otherwise if null or not "true", the button is fired with a regular form submit. * @param isDefault if "true", the button is invoked when enter is pressed on the form. */ private BeanSubmitButton(String id, final Component label, Form form, final Object bean, final String confirmMsg, String ajaxFlag, String isDefault) { super(id); setRenderBodyOnly(true); WebMarkupContainer button; if (Boolean.valueOf(ajaxFlag)) { button = new AjaxSubmitLink("button", form) { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form form) { BeanSubmitButton.this.onAction(target, form, bean); updateFeedbackPanels(target); // see comments in function javadoc } @Override protected void onError(AjaxRequestTarget target, Form form) { BeanSubmitButton.this.onError(target, form, bean); updateFeedbackPanels(target); // see comments in function javadoc } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return decorator; } @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.put("class", (label instanceof Label ? "beanSubmitButton" : "beanSubmitImageButton")); tag.put("href", "javascript:void(0)"); // don't do href="#" } }; } else { button = new SubmitLink("button", form) { private static final long serialVersionUID = 1L; @Override public void onSubmit() { BeanSubmitButton.this.onAction(null, getForm(), bean); } @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.put("class", (label instanceof Label ? "beanSubmitButton" : "beanSubmitImageButton")); } }; } if (confirmMsg != null) { button.add(new AttributeModifier("onclick", true, null) { private static final long serialVersionUID = 1L; @Override protected String newValue(String currentValue, String replacementValue) { return "if (!confirm('" + confirmMsg + "')) return false; else { " + currentValue + " }"; } }); } if (Boolean.valueOf(isDefault)) { button.add(new SimpleAttributeModifier("id", "bfDefaultButton")); } button.setOutputMarkupId(true); add(button); button.add(label); }
From source file:com.premiumminds.wicket.crudifier.form.CrudifierForm.java
License:Open Source License
public CrudifierForm(String id, IModel<T> model, CrudifierEntitySettings entitySettings, CrudifierFormSettings formSettings, Map<Class<?>, IObjectRenderer<?>> renderers) { super(id, model); setOutputMarkupId(true);/* www.ja v a2 s .c o m*/ this.formSettings = formSettings; this.entitySettings = entitySettings; this.renderers = renderers; add(new Label("legend", new StringResourceModel("legend", this, getModel(), "Unknown")) { private static final long serialVersionUID = -7854751811138463187L; @Override protected void onConfigure() { super.onConfigure(); setVisible(!getDefaultModelObjectAsString().isEmpty()); } }); add(listControlGroups = new ListControlGroups<T>("controls", getModel(), entitySettings, renderers) { private static final long serialVersionUID = 8621555399423058702L; @Override protected EntityProvider<?> getEntityProvider(String name) { return CrudifierForm.this.getEntityProvider(name); } }); add(new AjaxSubmitLink("submit", this) { private static final long serialVersionUID = -4527592607129929399L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { target.add(CrudifierForm.this); CrudifierForm.this.onSubmit(target, form); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(CrudifierForm.this); CrudifierForm.this.onError(target, form); } }.add(new Label("submitLabel", new StringResourceModel("submit.label", this, getModel(), "Submit")))); add(new ListView<Component>("buttons", buttons) { private static final long serialVersionUID = -8614436913101248043L; @Override protected void populateItem(ListItem<Component> item) { if (getApplication().usesDevelopmentConfig()) { if (!"button".equals(item.getModelObject().getId())) { throw new WicketRuntimeException( "custom buttons must have the wicket:id=\"button\" and must have a label with wicket:id=\"label\""); } if (item.getModelObject().get("label") == null) { throw new WicketRuntimeException( "custom buttons must have a label inside them with wicket:id=\"label\""); } } item.add(item.getModelObject()); } }); }
From source file:com.socialsite.course.question.AddQuestionPanel.java
License:Open Source License
public AddQuestionPanel(final String id, final IModel<Course> model, final MarkupContainer dependent) { super(id, model); final Form<Course> form = new Form<Course>("form", model); add(form);//from w w w. ja v a 2 s . c om form.add(new RequiredTextField<String>("heading", new PropertyModel<String>(this, "heading"))); form.add(new RichEditor("richeditor", new PropertyModel<String>(this, "text"))); final AjaxSubmitLink addQuestionLink = new AjaxSubmitLink("addquestion", form) { /** */ private static final long serialVersionUID = 1L; @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { super.onError(target, form); // show feedback messages target.addComponent(feedback); } @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { // save the question final Course course = (Course) form.getModelObject(); // create another question model final Question question = new Question(heading, text); question.setCourse(course); question.setUser(getSessionUser()); questionDao.save(question); QuestionInfoMsg infoMsg = new QuestionInfoMsg(); infoMsg.setQuestion(question); infoMsg.setTime(new Date()); infoMsg.setUsers(new HashSet<User>(course.getStudents())); messageDao.save(infoMsg); // update the related contents target.addComponent(dependent); target.addComponent(feedback); // fire the update event so the editor can intialize firePostAjaxUpdateEvent(target); // slideup the reply panel final String id = AddQuestionPanel.this.getMarkupId(); target.appendJavascript(" $('#" + id + " .slideText').trigger('click'); "); } }; form.add(addQuestionLink); form.setDefaultButton(addQuestionLink); add(feedback = new FeedbackPanel("feedback")); feedback.setOutputMarkupId(true); setOutputMarkupId(true); }
From source file:com.userweave.pages.base.ContactAndFeedbackPage.java
License:Open Source License
@Override protected WebMarkupContainer getAcceptButton(String componentId, final ModalWindow window) { final AjaxSubmitLink link = new AjaxSubmitLink(componentId, getForm()) { private static final long serialVersionUID = 1L; @Override/*from w w w. j ava 2 s . c o m*/ protected void onSubmit(AjaxRequestTarget target, Form form) { User user = UserWeaveSession.get().getUser(); String subject = new StringResourceModel(feedbacktype.toString(), ContactAndFeedbackPage.this, null) .getString(); try { DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy"); DateTimeFormatter localeFmt = fmt.withLocale(user.getLocale()); DateTimeFormatter timeFmt = DateTimeFormat.forPattern("HH:mm"); DateTime dateTime = new DateTime(); String mailMessage = new StringResourceModel("mailMessage", ContactAndFeedbackPage.this, null, new Object[] { user.getForename(), user.getSurname(), dateTime.toString(localeFmt), dateTime.toString(timeFmt), subject, feedbackMessage }).getString(); String subjectForMail = new StringResourceModel("mailSubject", ContactAndFeedbackPage.this, null).getString(); mailservice.sendMail(user.getEmail(), subjectForMail, mailMessage, "info@userweave.net", true); window.close(target); } catch (MessagingException e) { error(new StringResourceModel("mailMessageError", ContactAndFeedbackPage.this, null) .getString()); target.add(feedback); } } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { } }; return link; }
From source file:com.userweave.pages.configuration.project.invitation.InviteUserToProjectPage.java
License:Open Source License
@Override protected WebMarkupContainer getAcceptButton(String componentId, final ModalWindow window) { final AjaxSubmitLink link = new AjaxSubmitLink(componentId, getForm()) { private static final long serialVersionUID = 1L; @Override// w ww . j a va 2s. co m protected void onError(AjaxRequestTarget target, Form form) { // add the feedback panel of the invitation form panel. target.addComponent(((InvitationFormPanel) displayComponent).getFeedbackPanel()); } @Override protected void onSubmit(AjaxRequestTarget target, Form form) { InvitationFormPanel panel = (InvitationFormPanel) displayComponent; String addressee = panel.getInvitaitonAddressee().toLowerCase(); User recipant = userDao.findByEmail(addressee); if (recipant == null) // user is not a registered user { if (verifyEmailAddress(addressee)) { if (project == null) { triggerError("projectDoesNotExists", panel, target); } else if (userHasBeenInvited(addressee, project)) { triggerError("userAlreadyInvited", panel, target); } else // send new invitation { projectInvitationDao.sendInvitation(addressee, user, project, roleDao.findByName(panel.getRole().getRoleName()), panel.getSelectedLocale(), InviteUserToProjectPage.this); window.close(target); //replaceDisplayComponentAndHideLink(target); } } else // email address incorect { triggerError("emailAddressIncorrectPattern", panel, target); } } else { if (project == null) { triggerError("projectDoesNotExists", panel, target); } else { if (isUserAlreadyInProject(recipant, project)) { triggerError("userAlreadyInProject", panel, target); } else if (userHasBeenInvited(recipant, project)) { triggerError("userAlreadyInvited", panel, target); } else { projectInvitationDao.sendInvitation(user, recipant, project, roleDao.findByName(panel.getRole().getRoleName())); window.close(target); //replaceDisplayComponentAndHideLink(target); } } } } }; link.setOutputMarkupId(true); return link; }
From source file:com.userweave.pages.configuration.project.userpanel.WriteMessagePage.java
License:Open Source License
@Override protected WebMarkupContainer getAcceptButton(String componentId, final ModalWindow window) { final AjaxSubmitLink link = new AjaxSubmitLink(componentId, getForm()) { private static final long serialVersionUID = 1L; @Override/*from w ww .ja v a 2 s . co m*/ protected void onSubmit(AjaxRequestTarget target, Form form) { User user = UserWeaveSession.get().getUser(); List<ProjectUserRoleJoin> joins = purjDao.getJoinsByProject(project); List<String> recipients = new ArrayList<String>(); for (ProjectUserRoleJoin join : joins) { if (join.getUser().getId().equals(user.getId())) { continue; } recipients.add(join.getUser().getEmail()); } String mailSubject = new StringResourceModel("mailSubject", WriteMessagePage.this, null, new Object[] { project.getName() }).getString(); String mailMessage = new StringResourceModel("mailMessage", WriteMessagePage.this, null, new Object[] { user.getForename(), user.getSurname(), project.getName(), subject, message }) .getString(); try { mailService.sendMails(recipients, mailSubject, mailMessage, user.getEmail()); window.close(target); } catch (MessagingException e) { error(new StringResourceModel("could_not_send_mail_to", WriteMessagePage.this, null)); } } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { } }; return link; }
From source file:com.userweave.pages.configuration.study.localization.AddLocalePage.java
License:Open Source License
@Override protected WebMarkupContainer getAcceptButton(String componentId, final ModalWindow window) { return new AjaxSubmitLink(componentId, getForm()) { private static final long serialVersionUID = 1L; @Override/* w ww. j av a 2 s.c o m*/ protected void onSubmit(AjaxRequestTarget target, Form form) { onAddLocale(target, locales); window.close(target); } @Override protected void onError(AjaxRequestTarget target, Form form) { target.addComponent(feedback); } }; }
From source file:eu.uqasar.web.dashboard.DashboardEditPage.java
License:Apache License
/** * /* w w w . ja va2 s. c o m*/ * @return */ private AjaxSubmitLink newSubmitLink() { return new AjaxSubmitLink("submit", dashboardForm) { /** * */ private static final long serialVersionUID = 8233961185708082469L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { save(target); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { showErrors(target); } }; }