use of com.github.bordertech.wcomponents.Input in project wcomponents by BorderTech.
the class AbstractWFieldIndicatorRenderer method doRender.
/**
* Paints the given AbstractWFieldIndicator.
*
* @param component the WFieldErrorIndicator to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
AbstractWFieldIndicator fieldIndicator = (AbstractWFieldIndicator) component;
XmlStringBuilder xml = renderContext.getWriter();
WComponent validationTarget = fieldIndicator.getTargetComponent();
// Diagnosables takes care of thieir own messaging.
if (validationTarget == null || (validationTarget instanceof Diagnosable && !(validationTarget instanceof Input))) {
return;
}
if (validationTarget instanceof Input && !((Input) validationTarget).isReadOnly()) {
return;
}
List<Diagnostic> diags = fieldIndicator.getDiagnostics();
if (diags != null && !diags.isEmpty()) {
xml.appendTagOpen("ui:fieldindicator");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
switch(fieldIndicator.getFieldIndicatorType()) {
case INFO:
xml.appendAttribute("type", "info");
break;
case WARN:
xml.appendAttribute("type", "warn");
break;
case ERROR:
xml.appendAttribute("type", "error");
break;
default:
throw new SystemException("Cannot paint field indicator due to an invalid field indicator type: " + fieldIndicator.getFieldIndicatorType());
}
xml.appendAttribute("for", fieldIndicator.getRelatedFieldId());
xml.appendClose();
for (Diagnostic diag : diags) {
xml.appendTag("ui:message");
xml.appendEscaped(diag.getDescription());
xml.appendEndTag("ui:message");
}
xml.appendEndTag("ui:fieldindicator");
}
}
use of com.github.bordertech.wcomponents.Input in project wcomponents by BorderTech.
the class AbstractSetMandatory_Test method testExecute.
@Test
public void testExecute() {
// ---------------------
// Valid Target (WInput) and TRUE Boolean Value
SubordinateTarget target1 = new MyTarget();
AbstractSetMandatory mandatory = new MyMandatory(target1, Boolean.TRUE);
// Should be mandatory
mandatory.execute();
Assert.assertTrue("Target (Mandatable) should be mandatory", ((Mandatable) target1).isMandatory());
// FALSE Boolean Value
mandatory = new MyMandatory(target1, Boolean.FALSE);
// Should not be mandatory
mandatory.execute();
Assert.assertFalse("Target (Mandatable) should not be mandatory", ((Mandatable) target1).isMandatory());
// ---------------------
// Valid Target (WField) and TRUE Boolean Value
Input textArea = new WTextArea();
WField target2 = new WFieldLayout().addField("test", textArea);
mandatory = new MyMandatory(target2, Boolean.TRUE);
// Should be mandatory
mandatory.execute();
Assert.assertTrue("Target (WField) should be mandatory", textArea.isMandatory());
// FALSE Boolean Value
mandatory = new MyMandatory(target2, Boolean.FALSE);
// Should not be mandatory
mandatory.execute();
Assert.assertFalse("Target (WField) should not be mandatory", textArea.isMandatory());
// ---------------------
// Valid Target (WFieldSet) and TRUE Boolean Value
WFieldSet target3 = new WFieldSet("Test");
mandatory = new MyMandatory(target3, Boolean.TRUE);
// Should be mandatory
mandatory.execute();
Assert.assertTrue("Target (WFieldSet) should be mandatory", target3.isMandatory());
// FALSE Boolean Value
mandatory = new MyMandatory(target3, Boolean.FALSE);
// Should not be mandatory
mandatory.execute();
Assert.assertFalse("Target (WFieldSet) should not be mandatory", target3.isMandatory());
// ---------------------
// Invalid Target (Cannot be set Mandatory) and Boolean Value
MyInvalidTarget target4 = new MyInvalidTarget();
mandatory = new MyMandatory(target4, Boolean.TRUE);
// Should do nothing
mandatory.execute();
}
use of com.github.bordertech.wcomponents.Input in project wcomponents by BorderTech.
the class AbstractCompare method getTriggerValue.
/**
* Get the value for the trigger.
* <p>
* If no request is passed in, the current value of the trigger is used.
* </p>
* <p>
* It will return the same "value" the client would have used in its subordinate logic.
* </p>
* <p>
* The trigger value will either be (i) a date formatted String for WDateFields, (ii) a BigDecimal for WNumberFields
* or (iii) a List of String values for MultiSelect components or (iv) a String value.
* </p>
*
* @param request the request being processed, can be null
* @return the value to be used for the trigger
*/
protected Object getTriggerValue(final Request request) {
// Date Compare (Use Date Formatted String - YYYY-MM-DD)
if (trigger instanceof WDateField) {
final WDateField input = (WDateField) trigger;
Date date;
if (request == null) {
date = input.getValue();
} else {
date = input.getRequestValue(request);
}
return date == null ? null : new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(date);
} else if (trigger instanceof WNumberField) {
// Number Compare (Use Number Object)
final WNumberField input = (WNumberField) trigger;
if (request == null) {
return input.getValue();
} else {
return input.getRequestValue(request);
}
} else if (trigger instanceof AbstractWSingleSelectList) {
// String Compare for Single Select Lists (Use the Option's Code)
final AbstractWSingleSelectList list = (AbstractWSingleSelectList) trigger;
final Object selected;
if (request == null) {
selected = list.getValue();
} else {
selected = list.getRequestValue(request);
}
// Convert selected option to its "code" (Should always have a value)
String code = list.optionToCode(selected);
return code;
} else if (trigger instanceof AbstractWMultiSelectList) {
// String Compare for Multi Select Lists (Use the Option's Code)
final AbstractWMultiSelectList list = (AbstractWMultiSelectList) trigger;
final List<?> selected;
if (request == null) {
selected = list.getValue();
} else {
selected = list.getRequestValue(request);
}
// Empty is treated the same as null
if (selected == null || selected.isEmpty()) {
return null;
}
// Convert selected options to their "code" (Should always have a value)
List<String> codes = new ArrayList<>(selected.size());
for (Object select : selected) {
String code = list.optionToCode(select);
codes.add(code);
}
return codes;
} else if (trigger instanceof Input) {
// String Compare - Use the String Value of the Input
final Input input = (Input) trigger;
final Object inputValue;
if (request == null) {
inputValue = input.getValue();
} else {
inputValue = input.getRequestValue(request);
}
// Treat empty the same as null
return (inputValue == null || Util.empty(inputValue.toString())) ? null : inputValue.toString();
} else {
throw new SystemException("Trigger is not a valid type.");
}
}
use of com.github.bordertech.wcomponents.Input in project wcomponents by BorderTech.
the class WLabelRenderer method doRender.
/**
* Paints the given {@link WLabel}.
*
* @param component the WLabel to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WLabel label = (WLabel) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:label");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("for", label.getLabelFor());
WComponent what = label.getForComponent();
String whatFor = null;
if (what instanceof MultiInputComponent) {
whatFor = "group";
} else if (what instanceof Labelable) {
whatFor = "input";
}
boolean isReadOnly = ((what instanceof Input) && ((Input) what).isReadOnly()) || (what instanceof WRadioButton && ((WRadioButton) what).isReadOnly());
boolean isMandatory = (what instanceof Input) && ((Input) what).isMandatory();
xml.appendOptionalAttribute("what", whatFor);
xml.appendOptionalAttribute("readonly", isReadOnly, "true");
xml.appendOptionalAttribute("required", isMandatory, "true");
xml.appendOptionalAttribute("hiddencomponent", (what != null && what.isHidden()), "true");
xml.appendOptionalAttribute("hint", label.getHint());
xml.appendOptionalAttribute("accessKey", Util.upperCase(label.getAccessKeyAsString()));
xml.appendOptionalAttribute("hidden", label.isHidden(), "true");
xml.appendOptionalAttribute("toolTip", label.getToolTip());
xml.appendOptionalAttribute("accessibleText", label.getAccessibleText());
xml.appendClose();
xml.append(label.getText(), label.isEncodeText());
paintChildren(label, renderContext);
xml.appendEndTag("ui:label");
}
use of com.github.bordertech.wcomponents.Input in project wcomponents by BorderTech.
the class DiagnosticImpl method getDescription.
/**
* {@inheritDoc}
*/
@Override
public String getDescription() {
// We need to change references to input fields to their label or accessible text.
Object[] modifiedArgs = new Object[args.length];
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof Input) {
Input input = (Input) args[i];
String text = null;
UIContextHolder.pushContext(uic);
try {
if (input.getLabel() != null) {
text = input.getLabel().getText();
// Some apps use colons at the end of labels. We trim these off automatically
if (!Util.empty(text) && text.charAt(text.length() - 1) == ':') {
text = text.substring(0, text.length() - 1);
}
}
if (text == null) {
text = input.getAccessibleText();
}
if (text == null) {
text = input.getToolTip();
}
} finally {
UIContextHolder.popContext();
}
modifiedArgs[i] = text == null ? "" : text;
} else {
modifiedArgs[i] = args[i];
}
}
return I18nUtilities.format(null, message, modifiedArgs);
}
Aggregations