use of org.apache.tapestry5.commons.Location 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.commons.Location in project tapestry-5 by apache.
the class BindingFactoryTest method translate_binding.
@Test
public void translate_binding() {
FieldTranslator translator = mockFieldTranslator();
FieldTranslatorSource source = newMock(FieldTranslatorSource.class);
ComponentResources resources = mockComponentResources();
Location l = mockLocation();
String description = "foo bar";
String expression = "mock";
expect(source.createTranslator(resources, expression)).andReturn(translator);
replay();
BindingFactory factory = new TranslateBindingFactory(source, new StringInternerImpl());
Binding binding = factory.newBinding(description, resources, resources, expression, l);
assertSame(binding.get(), translator);
assertSame(InternalUtils.locationOf(binding), l);
verify();
}
use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.
the class BindingFactoryTest method literal_binding.
@Test
public void literal_binding() {
ComponentResources res = mockInternalComponentResources();
Location l = mockLocation();
replay();
BindingFactory factory = new LiteralBindingFactory();
Binding b = factory.newBinding("test binding", res, null, "Tapestry5", l);
assertSame(InternalUtils.locationOf(b), l);
assertEquals(b.get(), "Tapestry5");
assertTrue(b.isInvariant());
assertSame(b.getBindingType(), String.class);
try {
b.set(null);
unreachable();
} catch (TapestryException ex) {
assertSame(ex.getLocation(), l);
}
verify();
}
use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.
the class PropBindingFactoryTest method property_path_with_explicit_method_in_preamble.
/**
* The "preamble" are the non-terminal property or method names.
*/
@Test
public void property_path_with_explicit_method_in_preamble() {
TargetBean bean = new TargetBean();
ComponentResources resources = newComponentResources(bean);
Location l = mockLocation();
replay();
Binding binding = factory.newBinding("test binding", resources, null, "stringHolderMethod().value", l);
assertSame(binding.getBindingType(), String.class);
bean.getStringHolder().setValue("first");
assertEquals(binding.get(), "first");
assertEquals(binding.toString(), "PropBinding[test binding foo.Bar:baz(stringHolderMethod().value)]");
verify();
}
use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.
the class PropBindingFactoryTest method special_prop_binding_values.
@Test(dataProvider = "values")
public void special_prop_binding_values(String expression, Object expected) {
Location l = mockLocation();
String description = "my description";
ComponentResources resources = mockComponentResources();
Component component = mockComponent();
train_getComponent(resources, component);
train_getCompleteId(resources, "Does.not.matter");
replay();
Binding binding = factory.newBinding(description, resources, null, expression, l);
assertEquals(binding.get(), expected);
// All of these are invariatns, even though they are generated from the PropertyConduit.
assertTrue(binding.isInvariant());
verify();
}
Aggregations