/** * Retrieves the text field's text. * * @return the text field's text. */ public String getText() { return getValue(); }
/** * 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; }
/** * {@inheritDoc} */ @Override public String getRequestValue(final Request request) { if (isPresent(request)) { String value = request.getParameter(getId()); // An empty string is treated as null return (Util.empty(value)) ? null : value; } else { return getValue(); } }
@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()); }
WLink exampleLink = new WLink(); exampleLink.setText(tfLinkLabel.getText()); final String url = tfUrlField.getValue();