List of usage examples for org.apache.wicket Component getMarkupId
public String getMarkupId(boolean createIfDoesNotExist)
From source file:com.doculibre.constellio.wicket.behaviors.SetFocusBehavior.java
License:Open Source License
/** * Forces the focusComponent to print its markup id and adds a Javascript * function call to the <head> tag that will set the focus on it. * /* w ww. j a v a 2 s.co m*/ * @param focusComponent * @param response */ private void setFocus(Component focusComponent, IHeaderResponse response) { // Forces to print the id attribute. focusComponent.setOutputMarkupId(true); // Sets the id attribute if it does not already exist. String focusFormComponentId = focusComponent.getMarkupId(true); // Function call added to the <head> tag. response.renderOnLoadJavascript("document.getElementById('" + focusFormComponentId + "').focus()"); }
From source file:com.lyndir.lhunath.opal.wayward.behavior.FocusOnReady.java
License:Open Source License
@Override public void bind(final Component component) { component.setOutputMarkupId(true);//from w ww.j a v a2 s . c o m headerContributor = new IHeaderContributor() { @Override public void renderHead(final IHeaderResponse response) { if (component.isVisibleInHierarchy()) { String id = component.getMarkupId(true); response.renderOnDomReadyJavascript( String.format("document.getElementById(%s).focus()", JSUtils.toString(id))); } } }; }
From source file:com.premiumminds.webapp.wicket.repeaters.AjaxListSetView.java
License:Open Source License
/** * @param id component id/*from w ww . j ava 2 s. co m*/ * @param model model containing the listOrderedSet of * @param bodyTag tag name for the container that will be created * @see org.apache.wicket.Component#Component(String, IModel) */ public AjaxListSetView(String id, IModel<? extends ListOrderedSet<? extends T>> model, final String bodyTag) { super(id, model); if (model == null) { throw new IllegalArgumentException("Null models are not allowed"); } add(new Behavior() { private static final long serialVersionUID = -2448715969183335401L; @Override public void beforeRender(Component component) { getResponse().write("<" + bodyTag + " id='" + component.getMarkupId(true) + "'>"); } @Override public void afterRender(Component component) { getResponse().write("</" + bodyTag + ">"); } }); }
From source file:com.servoy.j2db.server.headlessclient.dataui.WebComponentSpecialIdMaker.java
License:Open Source License
/** * Determines the markup ID of a given component. Uses the servoy id of that component and adds indexes in case of table/list view in order to make id's * unique./* w ww . j ava2 s. co m*/ * * @deprecated as of version 6.0 components should just fallback to default wicket markup id * @param component the component who's markup id is computed and returned. * @return the markup id for the given component. */ @Deprecated public static String getSpecialIdIfAppropriate(Component component) { return component.getMarkupId(true); }
From source file:com.servoy.j2db.server.headlessclient.dataui.WebComponentSpecialIdMaker.java
License:Open Source License
/** * @deprecated as of version 6.0 components should just fallback to default wicket markup id *//*from w w w . j a va 2 s . c o m*/ @Deprecated public static String getSpecialId(int selectedIndex, Component component) { return component.getMarkupId(true); }
From source file:org.artifactory.common.wicket.application.SetPathMarkupIdOnBeforeRenderListener.java
License:Open Source License
@Override public void onBeforeRender(Component component) { String markupId = component.getMarkupId(false); if (markupId == null) { String id = getPath(component); if (id != null) { component.setMarkupId(id);//from www.j a v a 2s . c o m component.setOutputMarkupId(true); } } }
From source file:org.dcm4chee.web.war.tc.TCSearchPanel.java
License:LGPL
@SuppressWarnings({ "serial" }) public TCSearchPanel(final String id) { super(id, new Model<TCQueryFilter>(new TCQueryFilter())); setOutputMarkupId(true);/* w w w .j a v a2s.com*/ final DateSpanSearchItem dateSpanItem = new DateSpanSearchItem(); final DateSpanDialog dateSpanDialog = new DateSpanDialog(dateSpanItem); final List<IDateSearchItem> dateItems = new ArrayList<IDateSearchItem>(); dateItems.addAll(Arrays.asList(NotOlderThanSearchItem.values())); dateItems.add(dateSpanItem); Form<?> dateSpanDialogOuterForm = new Form<Void>("date-input-dialog-outer-form"); dateSpanDialogOuterForm.setOutputMarkupId(true); dateSpanDialogOuterForm.setMarkupId("tc-search-date-input-form-helper"); dateSpanDialogOuterForm.add(dateSpanDialog); final TCInput keywordInput = TCUtilities.createInput("keywordInput", TCQueryFilterKey.Keyword, getFilterValue(TCQueryFilterKey.Keyword), true); final TCInput anatomyInput = TCUtilities.createInput("anatomyInput", TCQueryFilterKey.Anatomy, getFilterValue(TCQueryFilterKey.Anatomy), true); final TCInput pathologyInput = TCUtilities.createInput("pathologyInput", TCQueryFilterKey.Pathology, getFilterValue(TCQueryFilterKey.Pathology), true); final TCInput findingInput = TCUtilities.createInput("findingInput", TCQueryFilterKey.Finding, getFilterValue(TCQueryFilterKey.Finding), true); final TCInput diagnosisInput = TCUtilities.createInput("diagnosisInput", TCQueryFilterKey.Diagnosis, getFilterValue(TCQueryFilterKey.Diagnosis), true); final TCInput diffDiagnosisInput = TCUtilities.createInput("diffDiagnosisInput", TCQueryFilterKey.DifferentialDiagnosis, getFilterValue(TCQueryFilterKey.DifferentialDiagnosis), true); final TextField<String> textText = new TextField<String>("textText", new Model<String>("")); textText.add(new AutoSelectInputTextBehaviour()); final DropDownChoice<TCQueryFilterValue.AcquisitionModality> modalityChoice = TCUtilities .createDropDownChoice("modalityChoice", new Model<TCQueryFilterValue.AcquisitionModality>(), Arrays.asList(TCQueryFilterValue.AcquisitionModality.values()), NullDropDownItem.All); final DropDownChoice<TCQueryFilterValue.PatientSex> patientSexChoice = TCUtilities.createEnumDropDownChoice( "patientSexChoice", new Model<TCQueryFilterValue.PatientSex>(), Arrays.asList(TCQueryFilterValue.PatientSex.values()), true, "tc.patientsex", NullDropDownItem.All); final DropDownChoice<TCQueryFilterValue.Category> categoryChoice = TCUtilities.createEnumDropDownChoice( "categoryChoice", new Model<TCQueryFilterValue.Category>(), Arrays.asList(TCQueryFilterValue.Category.values()), true, "tc.category", NullDropDownItem.All); final DropDownChoice<TCQueryFilterValue.Level> levelChoice = TCUtilities.createEnumDropDownChoice( "levelChoice", new Model<TCQueryFilterValue.Level>(), Arrays.asList(TCQueryFilterValue.Level.values()), true, "tc.level", NullDropDownItem.All); final DropDownChoice<TCQueryFilterValue.YesNo> diagnosisConfirmedChoice = TCUtilities .createEnumDropDownChoice("diagnosisConfirmedChoice", new Model<TCQueryFilterValue.YesNo>(), Arrays.asList(TCQueryFilterValue.YesNo.values()), true, "tc.yesno", NullDropDownItem.All); final TCAjaxComboBox<IDateSearchItem> dateBox = new TCAjaxComboBox<IDateSearchItem>("dateChoice", dateItems, new IChoiceRenderer<IDateSearchItem>() { public String getIdValue(IDateSearchItem item, int index) { return item.getId(); } public String getDisplayValue(IDateSearchItem item) { return item.getLabel(getSession().getLocale()); } }) { @Override protected IDateSearchItem convertValue(String svalue) { if (TCUtilities.equals(dateSpanItem.getLabel(getSession().getLocale()), svalue)) { return dateSpanItem; } else { return NotOlderThanSearchItem.valueForLabel(svalue, getSession().getLocale()); } } @Override protected boolean shallCommitValue(IDateSearchItem oldValue, IDateSearchItem newValue, AjaxRequestTarget target) { if (dateSpanItem == newValue) { final Component c = this; dateSpanDialog.setWindowClosedCallback(new WindowClosedCallback() { @Override public void onClose(AjaxRequestTarget target) { target.appendJavascript( getDateBoxInitUIJavascript(c.getMarkupId(true), dateSpanItem, false)); } }); dateSpanDialog.show(target); return true; } return super.shallCommitValue(oldValue, newValue, target); } }; TCUtilities.addOnDomReadyJavascript(dateBox, getDateBoxInitUIJavascript(dateBox.getMarkupId(), dateSpanItem, true)); final RadioGroup<Option> optionGroup = new RadioGroup<Option>("optionGroup", new Model<Option>()); optionGroup.add(new Radio<Option>("historyOption", new Model<Option>(Option.History))); optionGroup.add(new Radio<Option>("authorNameOption", new Model<Option>(Option.AuthorName))); optionGroup.add(new Radio<Option>("authorContactOption", new Model<Option>(Option.AuthorContact))); optionGroup.add(new Radio<Option>("authorOrganisationOption", new Model<Option>(Option.AuthorAffiliation))); optionGroup.add(new Radio<Option>("discussionOption", new Model<Option>(Option.Discussion))); optionGroup.add(new Radio<Option>("titleOption", new Model<Option>(Option.Title))); optionGroup.add(new Radio<Option>("abstractOption", new Model<Option>(Option.Abstract))); optionGroup.add(new Radio<Option>("patientSpeciesOption", new Model<Option>(Option.PatientSpecies))); final AjaxButton searchBtn = new AjaxButton("doSearchBtn") { private static final long serialVersionUID = 1L; private IAjaxCallDecorator decorator; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { try { try { findParent(TCPanel.class).getPopupManager().hidePopups(target); } catch (Exception e) { log.error("Error while closing popups!", e); } TCQueryFilter filter = (TCQueryFilter) TCSearchPanel.this.getDefaultModelObject(); filter.clear(); filter.setKeywords(keywordInput.getValues()); if (showAdvancedOptions) { filter.setAnatomy(anatomyInput.getValue()); filter.setPathology(pathologyInput.getValue()); filter.setFinding(findingInput.getValue()); filter.setDiagnosis(diagnosisInput.getValue()); filter.setDiffDiagnosis(diffDiagnosisInput.getValue()); filter.setAcquisitionModality(modalityChoice.getModelObject()); filter.setPatientSex(patientSexChoice.getModelObject()); filter.setCategory(categoryChoice.getModelObject()); filter.setLevel(levelChoice.getModelObject()); YesNo yesNo = diagnosisConfirmedChoice.getModelObject(); if (YesNo.Yes.equals(yesNo)) { filter.setDiagnosisConfirmed(yesNo); } IDateSearchItem dateItem = dateBox.getModelObject(); if (dateItem == null) { filter.setCreationDate(null, null); } else { filter.setCreationDate(dateItem.getFromDate(), dateItem.getUntilDate()); } Option selectedOption = optionGroup.getModelObject(); if (selectedOption != null) { if (Option.History.equals(selectedOption)) { filter.setHistory(textText.getDefaultModelObjectAsString()); } else if (Option.AuthorName.equals(selectedOption)) { filter.setAuthorName(textText.getDefaultModelObjectAsString()); } else if (Option.AuthorContact.equals(selectedOption)) { filter.setAuthorContact(textText.getDefaultModelObjectAsString()); } else if (Option.AuthorAffiliation.equals(selectedOption)) { filter.setAuthorAffiliation(textText.getDefaultModelObjectAsString()); } else if (Option.Title.equals(selectedOption)) { filter.setTitle(textText.getDefaultModelObjectAsString()); } else if (Option.Abstract.equals(selectedOption)) { filter.setAbstract(textText.getDefaultModelObjectAsString()); } else if (Option.PatientSpecies.equals(selectedOption)) { filter.setPatientSpecies(textText.getDefaultModelObjectAsString()); } else if (Option.Discussion.equals(selectedOption)) { filter.setDiscussion(textText.getDefaultModelObjectAsString()); } } } Component[] toUpdate = doSearch(filter); if (toUpdate != null && target != null) { for (Component c : toUpdate) { target.addComponent(c); } } } catch (Throwable t) { log.error("Searching for teaching-files failed!", t); } } @Override public void onError(AjaxRequestTarget target, Form<?> form) { BaseForm.addInvalidComponentsToAjaxRequestTarget(target, form); } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { if (decorator == null) { decorator = new TCMaskingAjaxDecorator(false, true); } return decorator; } }; searchBtn.setOutputMarkupId(true); searchBtn.add(new Image("doSearchImg", ImageManager.IMAGE_COMMON_SEARCH) .add(new ImageSizeBehaviour("vertical-align: middle;"))); searchBtn.add(new Label("doSearchText", new ResourceModel("tc.search.dosearch.text")) .add(new AttributeModifier("style", true, new Model<String>("vertical-align: middle;"))) .setOutputMarkupId(true)); AjaxButton resetBtn = new AjaxButton("resetSearchBtn") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { TCQueryFilter filter = (TCQueryFilter) TCSearchPanel.this.getDefaultModelObject(); filter.clear(); keywordInput.setValues(); anatomyInput.setValues(); pathologyInput.setValues(); findingInput.setValues(); diagnosisInput.setValues(); diffDiagnosisInput.setValues(); modalityChoice.setModelObject(null); levelChoice.setModelObject(null); patientSexChoice.setModelObject(null); categoryChoice.setModelObject(null); diagnosisConfirmedChoice.setModelObject(null); dateBox.setModelObject(null); textText.setModelObject(null); optionGroup.setModelObject(null); target.addComponent(form); target.appendJavascript("initUI($('#" + TCSearchPanel.this.getMarkupId(true) + "'));"); } @Override public void onError(AjaxRequestTarget target, Form<?> form) { BaseForm.addInvalidComponentsToAjaxRequestTarget(target, form); } }; resetBtn.add(new Image("resetSearchImg", ImageManager.IMAGE_COMMON_RESET) .add(new ImageSizeBehaviour("vertical-align: middle;"))); resetBtn.add(new Label("resetSearchText", new ResourceModel("tc.search.reset.text")) .add(new AttributeModifier("style", true, new Model<String>("vertical-align: middle;")))); final WebMarkupContainer wmc = new WebMarkupContainer("advancedOptions"); wmc.setOutputMarkupPlaceholderTag(true); wmc.setOutputMarkupId(true); wmc.setVisible(false); wmc.add(anatomyInput.getComponent()); wmc.add(pathologyInput.getComponent()); wmc.add(findingInput.getComponent()); wmc.add(diagnosisInput.getComponent()); wmc.add(diffDiagnosisInput.getComponent()); wmc.add(modalityChoice); wmc.add(patientSexChoice); wmc.add(categoryChoice); wmc.add(levelChoice); wmc.add(diagnosisConfirmedChoice); wmc.add(dateBox); wmc.add(optionGroup); wmc.add(textText); wmc.add(resetBtn); final MarkupContainer advancedOptionsToggleLink = new AjaxFallbackLink<String>("advancedOptionsToggle") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { showAdvancedOptions = !showAdvancedOptions; wmc.setVisible(showAdvancedOptions); target.addComponent(wmc); target.addComponent(this); if (showAdvancedOptions) { target.appendJavascript("initUI($('#" + wmc.getMarkupId(true) + "'));"); } } }.add(new Label("advancedOptionsToggleText", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = -7928173606391768738L; @Override public String getObject() { return showAdvancedOptions ? getString("tc.search.advancedOptions.hide.Text") : getString("tc.search.advancedOptions.show.Text"); } })).add((new Image("advancedOptionsToggleImg", new AbstractReadOnlyModel<ResourceReference>() { private static final long serialVersionUID = 1L; @Override public ResourceReference getObject() { return showAdvancedOptions ? ImageManager.IMAGE_COMMON_COLLAPSE : ImageManager.IMAGE_COMMON_EXPAND; } })).add(new ImageSizeBehaviour())); advancedOptionsToggleLink.setOutputMarkupId(true); final Form<?> form = new Form<Object>("searchForm"); form.add(keywordInput.getComponent()); form.add(wmc); form.add(searchBtn); form.setDefaultButton(searchBtn); form.setOutputMarkupPlaceholderTag(true); form.add(advancedOptionsToggleLink); add(dateSpanDialogOuterForm); add(form); add(new AjaxFallbackLink<Object>("searchToggle") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { showSearch = !showSearch; form.setVisible(showSearch); target.addComponent(TCSearchPanel.this); if (showSearch) { target.appendJavascript("initUI($('#" + TCSearchPanel.this.getMarkupId(true) + "'));"); } } }.add((new Image("searchToggleImg", new AbstractReadOnlyModel<ResourceReference>() { private static final long serialVersionUID = 1L; @Override public ResourceReference getObject() { return showSearch ? ImageManager.IMAGE_COMMON_COLLAPSE : ImageManager.IMAGE_COMMON_EXPAND; } })).add(new ImageSizeBehaviour()))); }
From source file:org.efaps.ui.wicket.behaviors.dojo.DnDBehavior.java
License:Apache License
/** * Add the javascriupt to the head of the webpage. * * @see org.efaps.ui.wicket.behaviors.dojo.AbstractDojoBehavior#renderHead( * org.apache.wicket.markup.html.IHeaderResponse) * * @param _component component the header will be rendered for * @param _response rseponse/* w w w. j av a 2 s .c o m*/ */ @Override public void renderHead(final Component _component, final IHeaderResponse _response) { super.renderHead(_component, _response); _response.render(JavaScriptHeaderItem.forScript("require([\"dojo/dnd/Source\",\"dojo/parser\"]);", DnDBehavior.class.toString())); if (this.type == DnDBehavior.BehaviorType.SOURCE) { final StringBuilder js = new StringBuilder() .append("require([\"dojo/aspect\",\"dojo/dom\",\"dojo/dnd/Source\"], ") .append("function(aspect,dom){\n").append("var nSrc = new dojo.dnd.Source(dom.byId('") .append(_component.getMarkupId(true)).append("'),") .append("{ accept: ['" + this.dndType + "']});") .append(" aspect.after(nSrc,\"onDrop\", function(){\n").append(this.appendJavaScript) .append("\n});").append("});"); _response.render(OnDojoReadyHeaderItem.forScript(js.toString())); } }
From source file:org.efaps.ui.wicket.behaviors.dojo.MenuBarBehavior.java
License:Apache License
/** * Render the links for the head./*from w w w. jav a2 s . c om*/ * * @param _component component the header will be rendered for * @param _response resonse to add */ @Override public void renderHead(final Component _component, final IHeaderResponse _response) { super.renderHead(_component, _response); _response.render(JavaScriptHeaderItem.forScript("require([\"dijit/MenuBar\", \"dojo/parser\"]);", MenuBarBehavior.class.getName())); _response.render(OnDojoReadyHeaderItem.forScript("require([\"dojo/dom-style\"], function(domStyle){\n" + " domStyle.set(\"" + _component.getMarkupId(true) + "\",\"visibility\",\"visible\");\n" + " domStyle.set(\"" + _component.getMarkupId(true) + "\",\"position\",\"\");\n" + " domStyle.set(\"" + _component.getMarkupId(true) + "\",\"left\",\"\");\n" + "});")); }
From source file:org.efaps.ui.wicket.behaviors.dojo.MessageListenerBehavior.java
License:Apache License
/** * @param _component _component the script will be rendered for * @return the Javascript/*from w ww. ja va 2 s . c o m*/ */ private static CharSequence getScript(final Component _component) { final StringBuilder js = new StringBuilder() .append("require([\"dojo/dom\",\"dojo/dom-style\", \"dojo/on\"],") .append("function(dom,domStyle,on){\n").append("on(window, \"message\", function(event) {\n") .append("var node = dom.byId('").append(_component.getMarkupId(true)).append("');\n") .append("if (event.data==\"\") {\n").append("domStyle.set(node, \"display\", \"none\");\n") .append("} else {\n").append("domStyle.set(node, \"display\", \"block\");\n") .append("node.innerHTML = event.data;\n").append("}\n").append("});").append("});"); return js; }