/** * Override handleRequest in order to perform processing for this component. This implementation updates the text * field's text if it has changed. * * @param request the request being responded to. * @return true if the text field has changed, otherwise false */ @Override protected boolean doHandleRequest(final Request request) { String value = getRequestValue(request); String current = getValue(); boolean changed = !Util.equals(value, current); if (changed) { setData(value); } return changed; }
@Override public void execute(final ActionEvent event) { tf4.setDisabled(!tf4.isDisabled()); } });
@Override public void execute(final ActionEvent event) { resultField.setText(text1.getValueAsString()); } });
@Test public void testDoPaint() throws IOException, SAXException, XpathException { WTextField textField = new WTextField(); WButton button = new WButton(); WSuggestions suggestions = new WSuggestions(); assertXpathEvaluatesTo(textField.getId(), "//ui:textfield/@id", textField); assertXpathNotExists("//ui:textfield/@disabled", textField); assertXpathNotExists("//ui:textfield/@hidden", textField); textField.setDisabled(true); assertSchemaMatch(textField); assertXpathEvaluatesTo("true", "//ui:textfield/@disabled", textField); textField.setMandatory(true); assertSchemaMatch(textField); assertXpathEvaluatesTo("true", "//ui:textfield/@required", textField); textField.setMinLength(45); assertSchemaMatch(textField); assertXpathEvaluatesTo("45", "//ui:textfield/@minLength", textField); textField.setMaxLength(50); assertSchemaMatch(textField); assertXpathEvaluatesTo("50", "//ui:textfield/@maxLength", textField); textField.setToolTip("tooltip"); assertSchemaMatch(textField); assertXpathEvaluatesTo(textField.getToolTip(), "//ui:textfield/@toolTip", textField);
@Test public void testSetAutocompleteNullAddressPart() { WTextField field = new WTextField(); field.setAutocomplete(Person.GIVEN); Assert.assertNotNull(field.getAutocomplete()); field.setAutocomplete((AddressPart) null); Assert.assertNull(field.getAutocomplete()); }
WTextField textField = (WTextField) component; XmlStringBuilder xml = renderContext.getWriter(); boolean readOnly = textField.isReadOnly(); xml.appendAttribute("readOnly", "true"); } else { int cols = textField.getColumns(); int minLength = textField.getMinLength(); int maxLength = textField.getMaxLength(); String pattern = textField.getPattern(); WSuggestions suggestions = textField.getSuggestions(); String suggestionsId = suggestions == null ? null : suggestions.getId(); WComponent submitControl = textField.getDefaultSubmitButton(); String submitControlId = submitControl == null ? null : submitControl.getId(); xml.appendOptionalAttribute("disabled", textField.isDisabled(), "true"); xml.appendOptionalAttribute("required", textField.isMandatory(), "true"); xml.appendOptionalAttribute("minLength", minLength > 0, minLength); xml.appendOptionalAttribute("maxLength", maxLength > 0, maxLength); xml.appendOptionalAttribute("toolTip", textField.getToolTip()); xml.appendOptionalAttribute("accessibleText", textField.getAccessibleText()); xml.appendOptionalAttribute("size", cols > 0, cols); xml.appendOptionalAttribute("buttonId", submitControlId); xml.appendOptionalAttribute("pattern", !Util.empty(pattern), pattern); xml.appendOptionalAttribute("list", suggestionsId); String placeholder = textField.getPlaceholder(); xml.appendOptionalAttribute("placeholder", !Util.empty(placeholder), placeholder);
field1 = new WTextField(); field1.setMandatory(true); field1.setMinLength(2); field1.setMaxLength(5); field2 = new WTextField(); field2.setMinLength(2); FieldValidator field2RegEx = new RegExFieldValidator("^[a-zA-Z]*$"); field2RegEx.setErrorMessage("{0} must only contain alphabetic characters."); field2.addValidator(field2RegEx); field3 = new WTextField();
@Test public void testClearAutocomplete() { WTextField field = new WTextField(); field.setAutocomplete(Person.FAMILY); field.addAutocompleteSection("foo"); Assert.assertNotNull(field.getAutocomplete()); field.clearAutocomplete(); Assert.assertNull(field.getAutocomplete()); }
/** * Retrieves the last name entered by the user. * * @return the last name. */ public String getLastName() { return lastName.getText(); }
@Test public void testMandatory() { List<Diagnostic> diags = new ArrayList<>(); WTextField textField = new WTextField(); Assert.assertFalse("Text field should not be mandatory by default", textField.isMandatory()); // No validation logic yet, but that should still be ok. textField.validate(diags); Assert.assertEquals("Diags should be empty when there are no validators", 0, diags.size()); // Add a mandatory validation textField.setMandatory(true); Assert.assertTrue("Text field should be mandatory", textField.isMandatory()); textField.validate(diags); Assert.assertEquals("Diags should contain mandatory validation error", 1, diags.size()); // Add some text to the text field textField.setText("Blah"); diags.clear(); textField.validate(diags); Assert.assertEquals("Diags should be empty when mandatory field is filled in", 0, diags. size()); }
@Test public void testWhenTrue() { SubordinateBuilder builder = new SubordinateBuilder(); WTextField comp1 = new WTextField(); WTextField comp2 = new WTextField(); builder.condition().equals(comp1, "x"); builder.whenTrue().disable(comp1); builder.whenFalse().enable(comp2); setActiveContext(createUIContext()); Assert.assertFalse("comp1 should not be disabled until rule executes", comp1.isDisabled()); Assert.assertFalse("comp2 should not be disabled", comp2.isDisabled()); comp1.setText("x"); builder.build().applyTheControls(); Assert.assertTrue("comp1 should be disabled", comp1.isDisabled()); Assert.assertFalse("comp2 should not be disabled", comp2.isDisabled()); }
@Override public void execute(final ActionEvent event) { Integer value = dateField.getDay(); text.setText(value == null ? null : value.toString()); } });
@Test public void testSetAutocompleteOffAfterSetting() { WTextField field = new WTextField(); field.setAutocomplete(Person.FAMILY); field.addAutocompleteSection("foo"); field.setAutocompleteOff(); Assert.assertTrue(field.isAutocompleteOff()); }
@Test public void testAddressAutocompleteNull() { WTextField field = new WTextField(); field.setAutocomplete(Person.GIVEN); Assert.assertNotNull(field.getAutocomplete()); field.setAddressAutocomplete(null, null); Assert.assertNull(field.getAutocomplete()); }
@Test public void testSetPhoneSegmentAutocompleteNull() { WTextField field = new WTextField(); field.setAutocomplete(Person.GIVEN); Assert.assertNotNull(field.getAutocomplete()); field.setPhoneSegmentAutocomplete(null, null); Assert.assertNull(field.getAutocomplete()); }
@Test public void testComponentModelSerialization() { WTextField name = new WTextField(); UIContext uic = createUIContext(); setActiveContext(uic); name.setText(TEST_STRING); Assert.assertEquals("Initial text incorrect", TEST_STRING, name.getText()); WebModel model = uic.getModel(name); model = (WebModel) pipe(model); uic.setModel(name, model); Assert.assertEquals("Text incorrect after serialization", TEST_STRING, name.getText()); }
linkContainer.reset(); WLink exampleLink = new WLink(); exampleLink.setText(tfLinkLabel.getText()); final String url = tfUrlField.getValue(); tfUrlField.setText(URL); exampleLink.setUrl(URL); } else { exampleLink.setText(tfLinkLabel.getText()); if (tfAccesskey.getText() != null && tfAccesskey.getText().length() > 0) { exampleLink.setAccessKey(tfAccesskey.getText().toCharArray()[0]);
/** * Test validate - where isDisableable and isDisabled. */ @Test public void testValidateIfIsDisableable() { // instanceOf Disableable and isDisabled implies abort validate() WTextField date = new WTextField(); date.addValidator(new MyValidator()); date.setLocked(true); setActiveContext(createUIContext()); date.setDisabled(true); List<Diagnostic> diags = new ArrayList<>(); date.validate(diags); // this calls validate(uic,diags) in WComponent parent class - the one being tested Assert.assertTrue("diags list should be empty", diags.isEmpty()); resetContext(); date.validate(diags); Assert.assertFalse("Diags list should not be empty", diags.isEmpty()); }
@Test public void testGetValue() { WTextField field = new WTextField(); field.setLocked(true); setActiveContext(createUIContext()); // Set data as a null value field.setData(null); Assert.assertNull("getValue should return null when data is null", field.getValue()); // Set data as a empty string field.setData(""); Assert.assertNull("getValue should return null when data is an empty string", field. getValue()); // Set data as a String value field.setData("A"); Assert.assertEquals("getValue returned the incorrect value for the data", "A", field. getValue()); // Set data as an Object Object object = new Date(); field.setData(object); Assert. assertEquals("getValue should return the string value of the data", object. toString(), field.getValue()); }