/** * Updates the label text (if label exists). * * @param text the new label text */ public void setLabelText(final String text) { if (label != null) { label.setText(text); } }
@Override public void execute(final ActionEvent event) { if (ONLINE.equals(rbSelect.getSelected())) { mediumSelectionLabel.setText(ONLINE_LABEL); mediumSelection.setOptions(ONLINE_TYPES); mediumSelection.setMandatory(false); } else { mediumSelectionLabel.setText(MAIL_LABEL); mediumSelection.setOptions(MAIL_TYPES); mediumSelection.setMandatory(true); } mediumSelection.resetData(); }
/** * {@inheritDoc} */ @Override protected void preparePaintComponent(final Request request) { super.preparePaintComponent(request); if (!isInitialised()) { label.setText("Option " + (String) getBean()); setInitialised(true); } } }
@Test public void testSpecialCharacters() { WLabel lbl = new WLabel(); Assert.assertNull("Default text should be null by default", lbl.getText()); lbl.setLocked(true); setActiveContext(createUIContext()); lbl.setText(null); Assert.assertNull("Session text should be null after set to null", lbl.getText()); String myText = "a!@#$%^&()-=_+\\[]~{}|<>:;',.?/`~z"; lbl.setText(myText); Assert.assertEquals("getText returned incorrect session text", myText, lbl.getText()); resetContext(); lbl.setText(myText); Assert.assertEquals("getText returned incorrect default text", myText, lbl.getText()); }
/** * Attempts to set the text contained in the body component. This works only for simple components types: * <ul> * <li>{@link WButton}</li> * <li>{@link WLink}</li> * <li>{@link WLabel}</li> * <li>{@link WText}</li> * </ul> * * @param text the new body text, using {@link MessageFormat} syntax. * @param args optional arguments for the message format string. */ public void setText(final String text, final Serializable... args) { WComponent body = getBody(); if (body instanceof WText) { ((WText) body).setText(text, args); } else if (body instanceof WLabel) { ((WLabel) body).setText(text, args); } else if (body instanceof WButton) { ((WButton) body).setText(text, args); } else if (body instanceof WLink) { ((WLink) body).setText(text, args); } else if (body == null) { setBody(new WText(text, args)); } }
@Test public void testGetText() { String defaultText = "test"; WLabel lbl = new WLabel(defaultText); lbl.setLocked(true); setActiveContext(createUIContext()); Assert.assertTrue("Should be in default state by default", lbl.isDefaultState()); lbl.setText("blah"); Assert.assertFalse("Should not be in default state when has session text", lbl. isDefaultState()); Assert.assertEquals("getText returned incorrect session text", "blah", lbl.getText()); resetContext(); Assert.assertEquals("Default text should not have changed", defaultText, lbl.getText()); }
label.setText("def:"); Assert.assertEquals("Incorrect description text", "The field 'def' is required", diag. getDescription());
@Test public void testDoPaintAllOptions() throws IOException, SAXException, XpathException { WTextArea text = new WTextArea(); text.setText("text1"); WLabel label = new WLabel(); label.setForComponent(text); label.setHint("hint1"); label.setAccessKey('A'); label.setText("label1"); WContainer root = new WContainer(); root.add(label); root.add(text); // Validate Schema assertSchemaMatch(root); // Check Attributes assertXpathEvaluatesTo(label.getId(), "//ui:label/@id", label); assertXpathEvaluatesTo(text.getId(), "//ui:label/@for", label); assertXpathEvaluatesTo("hint1", "//ui:label/@hint", label); assertXpathEvaluatesTo("A", "//ui:label/@accessKey", label); assertXpathEvaluatesTo("input", "//ui:label/@what", label); // Check Label assertXpathEvaluatesTo("label1", "//ui:label", label); // Add Children to Label WTextArea text2 = new WTextArea(); text2.setText("text2"); label.add(text2); assertSchemaMatch(root); assertXpathEvaluatesTo("text2", "//ui:label/ui:textarea", label); }