@Override public void bind(final Component component) { super.bind(component); component.setOutputMarkupId(true); component.add(AttributeModifier.replace("rel", createRelAttribute())); component.add(AttributeModifier.replace("title", label)); }
/** * Test that a null model does not append an empty attribute * https://issues.apache.org/jira/browse/WICKET-3884 */ @Test public void nullModelDoesNotAppendEmptyAttribute() { AttributeModifier appender = AttributeModifier.append("class", null); XmlTag xmlTag = new XmlTag(); ComponentTag tag = new ComponentTag(xmlTag); appender.replaceAttributeValue(null, tag); Map<String, Object> attributes = tag.getAttributes(); assertTrue(attributes.isEmpty()); }
/** https://issues.apache.org/jira/browse/WICKET-6279 */ @Test public void deserializeRemove() { AttributeModifier appender = AttributeModifier.append("class", AttributeModifier.VALUELESS_ATTRIBUTE_REMOVE); final AttributeModifier copy = WicketObjects.cloneObject(appender); final IModel<?> replaceModel = copy.getReplaceModel(); assertThat( replaceModel.getObject(), is(sameInstance(AttributeModifier.VALUELESS_ATTRIBUTE_REMOVE))); }
/** * Tests {@link AttributeModifier#remove(String)} * * <p>https://issues.apache.org/jira/browse/WICKET-3934 */ @Test public void removeAttribute() { AttributeModifier appender = AttributeModifier.remove("class"); XmlTag xmlTag = new XmlTag(); ComponentTag tag = new ComponentTag(xmlTag); Map<String, Object> attributes = tag.getAttributes(); attributes.put("class", "someValue"); appender.replaceAttributeValue(null, tag); assertTrue(attributes.isEmpty()); }
protected void rptList_PopulateItem(Item<Map<String, Object>> item) { Map<String, Object> dataRow = item.getModelObject(); // ID FWLabel index = new FWLabel("index"); index.setRenderBodyOnly(true); index.setValue(ConvUtils.convToString(rptList.getFirstItemOffset() + item.getIndex() + 1)); item.add(index); // 用户名称 FWModalPopupLink userName = new FWModalPopupLink("userName"); userName.setLabel(ConvUtils.convToString(dataRow.get("USER_NAME"))); userName.add( AttributeModifier.replace( "onclick", "layer_show('360','','" + ConvUtils.convToString(dataRow.get("USER_NAME")) + "','" + fwContext.getContextRoot() + TransitionUrlConst.USER_DETAIL_PAGE + "?USER_ID=" + ConvUtils.convToString(dataRow.get("OID_USER_ID")) + "')")); item.add(userName); // 手机 FWLabel mobile = new FWLabel("mobile"); mobile.setRenderBodyOnly(true); mobile.setValue(ConvUtils.convToString(dataRow.get("MOBILE"))); item.add(mobile); // 邮箱 FWLabel email = new FWLabel("email"); email.setRenderBodyOnly(true); if (!StringUtils.isEmpty(ConvUtils.convToString(dataRow.get("EMAIL")))) { email.setValue( ConvUtils.convToString(dataRow.get("EMAIL")) + " " + (ConvUtils.convToBool(dataRow.get("EMAIL_VERIFY_FLG")) ? "已验证" : "未验证")); } else { email.setValue("未填写"); } item.add(email); FWContainer selectBtn = new FWContainer("selectBtn"); selectBtn.add( AttributeModifier.replace( "onclick", "selectUserAccount('" + ConvUtils.convToString(dataRow.get("USER_NAME")) + "', '" + ConvUtils.convToString(dataRow.get("OID_USER_ID")) + "', '" + ConvUtils.convToString(dataRow.get("BORROWER_NAME")) + "', '" + ConvUtils.convToString(dataRow.get("BORROWER_ID_CARD")) + "')")); item.add(selectBtn); }
/** Test that a null model does not throw null pointers. */ @Test public void nullModelDoesNotThrowNullPointerExceptions() { AttributeModifier modifier = new AttributeModifier("test", null); XmlTag xmlTag = new XmlTag(); ComponentTag tag = new ComponentTag(xmlTag); tag.setId("foo"); tag.setName("test"); modifier.replaceAttributeValue(null, tag); Map<String, Object> attributes = tag.getAttributes(); assertTrue(attributes.isEmpty()); }
/** * Add an attribute with name equal (Object#equals()) to the special {@link * AttributeModifier#VALUELESS_ATTRIBUTE_REMOVE} but not identity equal * * <p>https://issues.apache.org/jira/browse/WICKET-3934 */ @Test public void appendSpecialAttribute() { String attrName = "attrName"; AttributeModifier appender = AttributeModifier.append(attrName, "VA_REMOVE"); XmlTag xmlTag = new XmlTag(); ComponentTag tag = new ComponentTag(xmlTag); Map<String, Object> attributes = tag.getAttributes(); attributes.put(attrName, "VA_REMOVE"); appender.replaceAttributeValue(null, tag); assertFalse(attributes.isEmpty()); assertEquals("VA_REMOVE VA_REMOVE", attributes.get(attrName)); }
/** Test simple model replacement. */ @Test public void testModelReplacement() { AttributeModifier modifier = new AttributeModifier("test", Model.of("Ellioth Smith Rocks")); XmlTag xmlTag = new XmlTag(); ComponentTag tag = new ComponentTag(xmlTag); tag.setId("test"); tag.setName("id"); modifier.replaceAttributeValue(null, tag); Map<String, Object> attributes = tag.getAttributes(); assertTrue(!attributes.isEmpty()); String replacement = (String) attributes.get("test"); assertNotNull(replacement); assertEquals("Ellioth Smith Rocks", replacement); }
public class IsisAjaxPagingNavigation extends AjaxPagingNavigation { private static final long serialVersionUID = 1L; /** Attribute for active state */ private final AttributeModifier activeAttribute = AttributeModifier.append("class", "active"); public IsisAjaxPagingNavigation( String id, IPageable pageable, IPagingLabelProvider labelProvider) { super(id, pageable, labelProvider); } public IsisAjaxPagingNavigation(String id, IPageable pageable) { super(id, pageable); } @Override protected Link<?> newPagingNavigationLink(String id, IPageable pageable, long pageIndex) { return new IsisAjaxPagingNavigationLink(id, pageable, pageIndex); } @Override protected void populateItem(final LoopItem loopItem) { super.populateItem(loopItem); if ((getStartIndex() + loopItem.getIndex()) == pageable.getCurrentPage()) { loopItem.add(activeAttribute); } } }
/** * 填充明细控件。 * * @param 明细结构体 * @return 没有 */ protected void rptList_PopulateItem(Item<Map<String, Object>> item) { Map<String, Object> dataRow = item.getModelObject(); // ID FWLabel index = new FWLabel("index"); index.setRenderBodyOnly(true); index.setValue(ConvUtils.convToString(rptList.getFirstItemOffset() + item.getIndex() + 1)); item.add(index); // 投资人 FWLabel tender = new FWLabel("tender"); tender.setRenderBodyOnly(true); item.add(tender); String mobile = ConvUtils.convToString(dataRow.get("MOBILE")); String email = ConvUtils.convToString(dataRow.get("EMAIL")); String connectChar = "/"; if (StringUtils.isEmpty(mobile) || StringUtils.isEmpty(email)) { connectChar = ""; } tender.setValue(mobile + connectChar + email); // 产品标题 FWModalPopupLink titleLink = new FWModalPopupLink("title"); titleLink.setLabel(ConvUtils.convToString(dataRow.get("FINANCE_PROD_TITLE"))); titleLink.add( AttributeModifier.replace( "onclick", "layer_show('450','','宝宝产品明细','" + fwContext.getContextRoot() + TransitionUrlConst.PROD_FINANCE_OPERATION_PAGE + "?" + PageParamConstant.VIEW_DETAIL + "=0&" + PageParamConstant.OBJECT_ID + "=" + dataRow.get("OID_FINANCE_PROD_ID") + "')")); item.add(titleLink); // 理财金额 FWLabel financeProdAmount = new FWLabel("financeProdAmount"); financeProdAmount.setRenderBodyOnly(true); financeProdAmount.setValue(ConvUtils.convToMoney(dataRow.get("FINANCE_PROD_AMOUNT"))); item.add(financeProdAmount); // 理财天数 FWLabel financeProdaDays = new FWLabel("financeProdaDays"); financeProdaDays.setRenderBodyOnly(true); financeProdaDays.setValue(ConvUtils.convToString(dataRow.get("FINANCE_PROD_DAYS"))); item.add(financeProdaDays); // 收益总额 FWLabel operationAmount = new FWLabel("operationAmount"); operationAmount.setRenderBodyOnly(true); operationAmount.setValue(ConvUtils.convToMoney(dataRow.get("OPERATION_AMOUNT"))); item.add(operationAmount); }
/** Test */ @Test public void testNewValue1Append() { AttributeModifier appender = AttributeModifier.append("attr", null); assertEquals("oldvalue newvalue", appender.newValue("oldvalue", "newvalue")); assertEquals("newvalue", appender.newValue("", "newvalue")); assertEquals("newvalue", appender.newValue(null, "newvalue")); assertEquals("oldvalue", appender.newValue("oldvalue", "")); assertEquals("oldvalue", appender.newValue("oldvalue", null)); assertNull(appender.newValue(null, null)); }
/** Test */ @Test public void testNewValue1Prepend() { AttributeModifier prepender = AttributeModifier.prepend("attr", null); assertEquals("newvalue oldvalue", prepender.newValue("oldvalue", "newvalue")); assertEquals("newvalue", prepender.newValue("", "newvalue")); assertEquals("newvalue", prepender.newValue(null, "newvalue")); assertEquals("oldvalue", prepender.newValue("oldvalue", "")); assertEquals("oldvalue", prepender.newValue("oldvalue", null)); assertNull(prepender.newValue(null, null)); }
/** Test */ @Test public void testNewValue2Prepend() { AttributeModifier appender = AttributeModifier.prepend("attr", null).setSeparator(";"); assertEquals("newvalue;oldvalue", appender.newValue("oldvalue", "newvalue")); assertEquals("newvalue", appender.newValue("", "newvalue")); assertEquals("newvalue", appender.newValue(null, "newvalue")); assertEquals("oldvalue", appender.newValue("oldvalue", "")); assertEquals("oldvalue", appender.newValue("oldvalue", null)); assertNull(appender.newValue(null, null)); }
/** * Sets attribute size (only for TextFields) and style="length: width"; The width value is size + * 0.5 em and for drop down choices size + 2em; * * @param component * @param size * @param important If true then "!important" is appended to the width style (true is default). * @return This for chaining. */ public static FormComponent<?> setSize( final FormComponent<?> component, final int size, final boolean important) { if (component instanceof TextField) { component.add(AttributeModifier.replace("size", String.valueOf(size))); } final StringBuffer buf = new StringBuffer(20); buf.append("width: "); if (component instanceof DropDownChoice) { buf.append(size + 2).append("em"); } else { buf.append(size).append(".5em"); } if (important == true) { buf.append(" !important;"); } buf.append(";"); component.add(AttributeModifier.append("style", buf.toString())); return component; }
/** Test that that the attribute modifier does nothing with not enabled. */ @Test public void testNoNewValueWhenNotEnabled() { AttributeModifier modifier = new AttributeModifier("test", Model.of("Ellioth Smith Rocks")) { @Override public boolean isEnabled(Component component) { return false; } }; XmlTag xmlTag = new XmlTag(); ComponentTag tag = new ComponentTag(xmlTag); tag.setId("test"); tag.setName("id"); Map<String, Object> attributes = tag.getAttributes(); attributes.put("test", "My mother rocks"); modifier.replaceAttributeValue(null, tag); String replacement = (String) attributes.get("test"); assertNotNull(replacement); assertEquals("My mother rocks", replacement); }
@Override public void bind(Component component) { super.bind(component); if (this.component != null) { throw new WicketRuntimeException("Behavior is already bound to another component."); } this.component = component; this.component.add(AttributeModifier.append("class", INVOKER_CSS_CLASS)); this.component.add(this.onContextMenuEventBehavior = this.newOnContextMenuBehavior()); }
@Override public void bind(Component component) { super.bind(component); component.add(AttributeModifier.replace("data-tooltip", true)); this.selector = JQueryWidget.getSelector(component); this.setOption("items", Options.asString("[data-tooltip]")); this.setOption( "content", String.format("function() { return \"%s\"; }", this.render(this.newContent(CONTENT_ID)))); }
/** * Adds a SimpleAttributeModifier("title", ...) to the given component. Does not modify the given * tool tip text! * * @param component * @param title * @param text If the string contains "\n" characters then html=true and <br/> are used. * @param rightAlignment If false (default is true) the tooltip will be aligned at the bottom. */ public static Component addTooltip( final Component component, final IModel<String> title, final IModel<String> text, final boolean rightAlignment) { @SuppressWarnings("serial") final IModel<String> myModel = new Model<String>() { /** @see org.apache.wicket.model.Model#getObject() */ @Override public String getObject() { if (text != null && text.getObject() != null && text.getObject().indexOf("\n") > 0) { final String newText = HtmlHelper.escapeHtml(text.getObject(), true); return newText; } return text.getObject(); } }; component.add(AttributeModifier.replace("data-html", true)); if (title != null && title.getObject() != null) { component.add(AttributeModifier.replace("rel", rightAlignment ? "mypopup-right" : "mypopup")); component.add(AttributeModifier.replace("data-original-title", title)); component.add(AttributeModifier.replace("data-content", myModel)); } else { component.add( AttributeModifier.replace("rel", rightAlignment ? "mytooltip-right" : "mytooltip")); component.add(AttributeModifier.replace("title", myModel)); } return component; }
/** Test overriding newValue (and using a null model). */ @Test public void testNewValue() { AttributeModifier modifier = new AttributeModifier("test", null) { private static final long serialVersionUID = 1L; @Override protected String newValue(String currentValue, String replacementValue) { return "the replacement"; } }; XmlTag xmlTag = new XmlTag(); ComponentTag tag = new ComponentTag(xmlTag); tag.setId("test"); tag.setName("id"); modifier.replaceAttributeValue(null, tag); Map<String, Object> attributes = tag.getAttributes(); assertTrue(!attributes.isEmpty()); String replacement = (String) attributes.get("test"); assertNotNull(replacement); assertEquals("the replacement", replacement); }
/** * Add JavaScript function showDeleteEntryQuestionDialog(). Depending on BaseDao.isHistorizable() * a delete or mark-as-deleted question will be displayed. Usage in markup: <script * wicket:id="showDeleteEntryQuestionDialog">[...]</script> * * @param parent * @param dao */ public static void addShowDeleteRowQuestionDialog( final MarkupContainer parent, final BaseDao<?> dao) { final StringBuffer buf = new StringBuffer(); buf.append("function showDeleteEntryQuestionDialog() {\n").append(" return window.confirm('"); if (dao.isHistorizable() == true) { buf.append(parent.getString("question.markAsDeletedQuestion")); } else { buf.append(parent.getString("question.deleteQuestion")); } buf.append("');\n}\n"); parent.add( new Label("showDeleteEntryQuestionDialog", buf.toString()) .setEscapeModelStrings(false) .add(AttributeModifier.replace("type", "text/javascript"))); }
/** * Constructor that is invoked when page is invoked without a session. * * @param parameters Page parameters */ @SuppressWarnings("serial") public AbstractMobilePage(final PageParameters parameters) { super(parameters); add(pageContainer = new WebMarkupContainer("page")); pageContainer.add(headerContainer = new WebMarkupContainer("header")); add( new Label( "windowTitle", new Model<String>() { @Override public String getObject() { return getWindowTitle(); } })); final Model<String> loggedInLabelModel = new Model<String>() { @Override public String getObject() { return "<strong>" + escapeHtml(AppVersion.APP_TITLE) + "</strong>"; } }; pageContainer.add( new Label("loggedInLabel", loggedInLabelModel) .setEscapeModelStrings(false) .setRenderBodyOnly(false) .setVisible(getUser() != null)); if (getWicketApplication().isDevelopmentSystem() == true) { // navigationContainer.add(AttributeModifier.replace("style", // WebConstants.CSS_BACKGROUND_COLOR_RED)); } else { } pageContainer.add( AttributeModifier.append( "data-title", new Model<String>() { @Override public String getObject() { return getTitle(); } })); }
@Override public void populateItem( final Item<ICellPopulator<List<String>>> aCellItem, final String componentId, final IModel<List<String>> rowModel) { int rowNumber = aCellItem.getIndex(); aCellItem.setOutputMarkupId(true); final String value = rowModel.getObject().get(columnNumber).trim(); // the project if (rowNumber == rowModel.getObject().size() - 1) { aCellItem.add( new EmbeddableImage( componentId, new ContextRelativeResource("/images_small/page_edit.png"))); aCellItem.add(AttributeModifier.append("class", "centering")); aCellItem.add( new AjaxEventBehavior("onclick") { private static final long serialVersionUID = -4213621740511947285L; @Override protected void onEvent(AjaxRequestTarget aTarget) { selectedCrowdJob = repository.getCrowdJob(value, selectedProject); SelectionModel selectionModel = new SelectionModel(); selectionModel.name = selectedCrowdJob.getName(); selectionModel.apiKey = selectedCrowdJob.getApiKey(); selectionModel.link = selectedCrowdJob.getLink(); selectionModel.status = selectedCrowdJob.getStatus(); crowdJobDetailForm.setModelObject(selectionModel); crowdJobDetailForm.setVisible(true); createCrowdJob = false; aTarget.add(crowdJobDetailForm.setOutputMarkupId(true)); aTarget.appendJavaScript("window.location.reload()"); aTarget.add(crowdJobForm); } }); } else { aCellItem.add(new Label(componentId, value)); } }
@SuppressWarnings("serial") public void redraw() { clearContent(); { gridBuilder.newSecurityAdviceBox(Model.of(getString("calendar.icsExport.securityAdvice"))); addFormFields(); final FieldsetPanel fs = gridBuilder.newFieldset(getString("calendar.abonnement.url")).setLabelSide(false); urlTextArea = new TextArea<String>( fs.getTextAreaId(), new Model<String>() { @Override public String getObject() { return WicketUtils.getAbsoluteContextPath() + getUrl(); }; }); urlTextArea.setOutputMarkupId(true); fs.add(urlTextArea); urlTextArea.add(AttributeModifier.replace("onClick", "$(this).select();")); } }
/** * Sets the html attribute placeholder. * * @param component * @param value */ public static void setPlaceHolderAttribute(Component component, final String value) { if (component instanceof ComponentWrapperPanel) { component = ((ComponentWrapperPanel) component).getFormComponent(); } component.add(AttributeModifier.replace("placeholder", value)); }
protected void rptList_PopulateItem(Item<Map<String, Object>> item) { Map<String, Object> dataRow = item.getModelObject(); // ID FWLabel index = new FWLabel("index"); index.setRenderBodyOnly(true); index.setValue(ConvUtils.convToString(rptList.getFirstItemOffset() + item.getIndex() + 1)); item.add(index); // 产品标题 FWLabel productTitle = new FWLabel("productTitle"); productTitle.setRenderBodyOnly(true); productTitle.setDefaultModelObject(ConvUtils.convToString(dataRow.get("PRODUCTS_TITLE"))); item.add(productTitle); // 应回款日期 FWLabel date = new FWLabel("date"); date.setRenderBodyOnly(true); date.setDefaultModelObject(ConvUtils.convToString(dataRow.get("RECOVER_DATE"))); item.add(date); // 应回款本金 FWLabel amountCapital = new FWLabel("amountCapital"); amountCapital.setRenderBodyOnly(true); amountCapital.setDefaultModelObject( ConvUtils.convToDecimal(dataRow.get("RECOVER_AMOUNT_CAPITAL"))); item.add(amountCapital); // 应回款利息 FWLabel amountInterest = new FWLabel("amountInterest"); amountInterest.setRenderBodyOnly(true); amountInterest.setDefaultModelObject( ConvUtils.convToDecimal(dataRow.get("RECOVER_AMOUNT_INTEREST"))); item.add(amountInterest); // 应回款总额 FWLabel amountTotal = new FWLabel("amountTotal"); amountTotal.setRenderBodyOnly(true); amountTotal.setDefaultModelObject(ConvUtils.convToDecimal(dataRow.get("RECOVER_AMOUNT_TOTAL"))); item.add(amountTotal); // 实际回款日期 FWLabel dateYes = new FWLabel("dateYes"); dateYes.setRenderBodyOnly(true); dateYes.setDefaultModelObject(ConvUtils.convToString(dataRow.get("RECOVER_DATE_YES"))); item.add(dateYes); // 实际回款本金 FWLabel amountCapitalYes = new FWLabel("amountCapitalYes"); amountCapitalYes.setRenderBodyOnly(true); amountCapitalYes.setDefaultModelObject( ConvUtils.convToDecimal(dataRow.get("RECOVER_AMOUNT_CAPITAL_YES"))); item.add(amountCapitalYes); // 实际回款利息 FWLabel amountInterestYes = new FWLabel("amountInterestYes"); amountInterestYes.setRenderBodyOnly(true); amountInterestYes.setDefaultModelObject( ConvUtils.convToDecimal(dataRow.get("RECOVER_AMOUNT_INTEREST_YES"))); item.add(amountInterestYes); // 实际回款总额 FWLabel amountTotalYes = new FWLabel("amountTotalYes"); amountTotalYes.setRenderBodyOnly(true); amountTotalYes.setDefaultModelObject( ConvUtils.convToDecimal(dataRow.get("RECOVER_AMOUNT_TOTAL_YES"))); item.add(amountTotalYes); // 回款状态 FWLabel status = new FWLabel("status"); status.setDefaultModelObject( RecoverFlgEnum.getEnumDisp(ConvUtils.convToString(dataRow.get("RECOVER_FLG"))).getValue()); item.add(status); // 回款状态样式控制 if (RecoverFlgEnum.RECOVER_STATUS_NO .getValue() .equals(ConvUtils.convToString(dataRow.get("RECOVER_FLG")))) { status.add(AttributeModifier.replace("class", "label label-default")); } else if (RecoverFlgEnum.RECOVER_STATUS_YES .getValue() .equals(ConvUtils.convToString(dataRow.get("RECOVER_FLG")))) { status.add(AttributeModifier.replace("class", "label label-success")); } }
public static void append(final Component component, final RowCssClass... rowCssClasses) { for (final RowCssClass rowCssClass : rowCssClasses) { component.add(AttributeModifier.append("class", rowCssClass.getCssClass())); } }
protected void setNoBackButton() { headerContainer.add(AttributeModifier.replace("data-nobackbtn", "true")); }
public static Component setWarningTooltip(final Component component) { component.add(AttributeModifier.append("class", "warning")); return component; }
protected Component addToolTipToComponent(Component component, String resourceText) { component.add(AttributeModifier.append("rel", "tooltip")); component.add(AttributeModifier.append("data-placement", "top")); component.add(AttributeModifier.append("data-original-title", new ResourceModel(resourceText))); return component; }
/** * Sets readonly="readonly" and "readOnly" as class. * * @param component * @return This for chaining. */ public static FormComponent<?> setReadonly(final FormComponent<?> component) { component.add(AttributeModifier.append("class", "readonly")); component.add(AttributeModifier.replace("readonly", "readonly")); return component; }