use of org.apache.tapestry5.annotations.Component in project tapestry-5 by apache.
the class UploadTest method process_submission_calls_validator.
@SuppressWarnings("unchecked")
@Test
public void process_submission_calls_validator() throws Exception {
MultipartDecoder decoder = mockMultipartDecoder();
UploadedFile uploadedFile = mockUploadedFile();
FieldValidator<Object> validate = mockFieldValidator();
ComponentResources resources = mockComponentResources();
FieldValidationSupport support = mockFieldValidationSupport();
Upload component = new Upload(null, validate, decoder, null, resources, support);
expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
expect(uploadedFile.getFileName()).andReturn("test").atLeastOnce();
support.validate(uploadedFile, resources, validate);
replay();
component.processSubmission("test");
verify();
}
use of org.apache.tapestry5.annotations.Component in project tapestry-5 by apache.
the class Form method preallocateNames.
private void preallocateNames(IdAllocator idAllocator) {
for (String name : formControlNameManager.getReservedNames()) {
idAllocator.allocateId(name);
// See https://issues.apache.org/jira/browse/TAP5-1632
javascriptSupport.allocateClientId(name);
}
Component activePage = componentSource.getActivePage();
if (activePage == null)
return;
ComponentResources activePageResources = activePage.getComponentResources();
try {
activePageResources.triggerEvent(EventConstants.PREALLOCATE_FORM_CONTROL_NAMES, new Object[] { idAllocator }, null);
} catch (RuntimeException ex) {
logger.error(String.format("Unable to obtain form control names to preallocate: %s", ExceptionUtils.toMessage(ex)), ex);
}
}
use of org.apache.tapestry5.annotations.Component in project tapestry-5 by apache.
the class Form method executeStoredActions.
/**
* Pulls the stored actions out of the request, converts them from MIME
* stream back to object stream and then
* objects, and executes them.
*/
private void executeStoredActions(boolean forFormCancel) {
String[] values = request.getParameters(FORM_DATA);
if (!request.getMethod().equals("POST") || values == null)
throw new RuntimeException(messages.format("core-invalid-form-request", FORM_DATA));
for (String clientEncodedActions : values) {
if (InternalUtils.isBlank(clientEncodedActions))
continue;
logger.debug("Processing actions: {}", clientEncodedActions);
ObjectInputStream ois = null;
Component component = null;
try {
ois = clientDataEncoder.decodeClientData(clientEncodedActions);
while (!eventCallback.isAborted()) {
String componentId = ois.readUTF();
boolean cancelAction = ois.readBoolean();
ComponentAction action = (ComponentAction) ois.readObject();
// based on whether the form was submitted or cancelled.
if (forFormCancel != cancelAction) {
continue;
}
component = source.getComponent(componentId);
logger.debug("Processing: {} {}", componentId, action);
action.execute(component);
component = null;
}
} catch (EOFException ex) {
// Expected
} catch (Exception ex) {
Location location = component == null ? null : component.getComponentResources().getLocation();
throw new TapestryException(ex.getMessage(), location, ex);
} finally {
InternalUtils.close(ois);
}
}
}
use of org.apache.tapestry5.annotations.Component in project tapestry-5 by apache.
the class ProgressiveDisplay method beginRender.
Block beginRender(MarkupWriter writer) {
String clientId = jsSupport.allocateClientId(resources);
String elementName = resources.getElementName("div");
writer.element(elementName, "id", clientId, "data-container-type", "zone");
resources.renderInformalParameters(writer);
Link link = resources.createEventLink(EventConstants.ACTION, context);
jsSupport.require("t5/core/zone").invoke("deferredZoneUpdate").with(clientId, link.toURI());
// of the component.
return initial;
}
use of org.apache.tapestry5.annotations.Component in project tapestry-5 by apache.
the class DateField method beginRender.
void beginRender(MarkupWriter writer) {
String value = validationTracker.getInput(this);
if (value == null) {
value = formatCurrentValue();
}
String clientId = getClientId();
writer.element("div", "data-component-type", "core/DateField", "data-parse-url", resources.createEventLink("parse").toString(), "data-format-url", resources.createEventLink("format").toString());
if (!hideTextField) {
writer.attributes("class", "input-group");
}
Element field = writer.element("input", "type", type, "class", cssClass, "name", getControlName(), "id", clientId, "value", value);
if (hideTextField) {
field.attribute("class", "hide");
}
writeDisabled(writer);
putPropertyNameIntoBeanValidationContext("value");
validate.render(writer);
removePropertyNameFromBeanValidationContext();
resources.renderInformalParameters(writer);
decorateInsideField();
// input
writer.end();
if (!hideTextField) {
writer.element("span", "class", "input-group-btn");
}
writer.element("button", "type", "button", "class", "btn btn-default", "alt", "[Show]");
writer.element("span", "class", "glyphicon glyphicon-calendar");
// span
writer.end();
// button
writer.end();
if (!hideTextField) {
// span.input-group-btn
writer.end();
}
// outer div
writer.end();
}
Aggregations