Author: hlship
Date: Mon Apr 14 12:38:34 2008
New Revision: 647968
URL: http://svn.apache.org/viewvc?rev=647968&view=rev
Log:
TAPESTRY-2346: Update the tapestry-core adaptive API example to match the
current set of events triggered by the Form component
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java?rev=647968&r1=647967&r2=647968&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
Mon Apr 14 12:38:34 2008
@@ -227,13 +227,7 @@
InjectionProvider injectionProvider,
- Environment environment,
-
- ComponentClassResolver resolver,
-
- ComponentSource componentSource,
-
- BindingSource bindingsource)
+ ComponentClassResolver resolver)
{
// TODO: Proper scheduling of all of this. Since a given field or
method should
// only have a single annotation, the order doesn't matter so much, as
long as
@@ -252,7 +246,7 @@
configuration.add("Mixin", new MixinWorker(resolver));
configuration.add("OnEvent", new OnEventWorker());
configuration.add("SupportsInformalParameters", new
SupportsInformalParametersWorker());
- configuration.add("InjectPage", new InjectPageWorker(componentSource,
resolver));
+ configuration.add("InjectPage",
locator.autobuild(InjectPageWorker.class));
configuration.add("InjectContainer", new InjectContainerWorker());
configuration.add("InjectComponent", new InjectComponentWorker());
configuration.add("RenderCommand", new RenderCommandWorker());
@@ -260,7 +254,7 @@
// Default values for parameters are often some form of injection, so
make sure
// that Parameter fields are processed after injections.
- configuration.add("Parameter", new ParameterWorker(bindingsource),
"after:Inject*");
+ configuration.add("Parameter",
locator.autobuild(ParameterWorker.class), "after:Inject*");
// Workers for the component rendering state machine methods; this is
in typical
// execution order.
@@ -301,7 +295,7 @@
// These must come after Property, since they actually delete fields
that may still have the annotation
configuration.add("ApplicationState",
locator.autobuild(ApplicationStateWorker.class),
"after:Property");
- configuration.add("Environment", new EnvironmentalWorker(environment),
"after:Property");
+ configuration.add("Environment",
locator.autobuild(EnvironmentalWorker.class), "after:Property");
// This one is always last. Any additional private fields that aren't
annotated will
// be converted to clear out at the end of the request.
Modified: tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt?rev=647968&r1=647967&r2=647968&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt Mon Apr 14
12:38:34 2008
@@ -103,8 +103,10 @@
public class Login
{
@Persist
+ @Property
private String _userId;
+ @Property
private String _password;
@Component
@@ -113,36 +115,32 @@
@Inject
private LoginAuthenticator _authenticator;
- private Object onSubmit()
+ void onValidateForm()
{
- if (_authenticator.isValidLogin(_userId, _password))
- return Start.class;
-
- // Stay on this page:
-
- _form.recordError("Invalid user name or password.");
-
- return null;
+ if (! _authenticator.isValidLogin(_userId, _password))
+ {
+ _form.recordError("Invalid user name or password.");
+ }
}
-
- public String getUserId() { return _userId; }
-
- public String getPassword() { return _password; }
-
- public void setUserId(String userId) { _userId = userId; }
-
- public void setPassword(String password) { _password = password; }
+
+ Object onSuccess()
+ {
+ return PostLogin.class;
+ }
+
}
+----+
This short snippet demonstrates a bit about how Tapestry operates. Pages
and services
- within the application are injected with the @Inject annotation. The method
name, onSubmit(),
- informs Tapestry about when the method is to be invoked
- (when a form component contained by the page emits a "submit" event). The
method's
+ within the application are injected with the @Inject annotation. The method
names, onValidateForm()
+ and onSuccess(),
+ inform Tapestry about when the method is to be invoked. The two events
<validateForm> and <success> occur
+ when a form is submitted; "validateForm" is triggered to perform cross-field
validations, and "success" is
+ only triggered when there are no validation errors. The onSuccess() method's
return value directs Tapestry on what to do next: jump to another page
within the application
- (here identified as the class for the page, but other options exist), or
stay on the same page to display the
- error message.
-
+ (here identified as the class for the page, but many other options exist).
When there are exceptions,
+ the page will be redisplayed to the user.
+
This also represents a distinct change from Tapestry 4. In earlier versions
of Tapestry,
the Form component's listener parameter would be bound to the method to
invoke, by name. Further,
the listener method had to be public.
@@ -152,7 +150,10 @@
In many cases, additional information about the event is available, and can
be passed
into the method by adding parameters to the method. Again, Tapestry will
adapt
to your parameters, in whatever order you supply them.
-
+
+ Tapestry also saves you effort: the @Property annotation marks a field as
readable and writable;
+ Tapestry will provide the accessor methods automatically.
+
Finally, Tapestry 5 explicitly separates actions (requests that change
things) and rendering (requests that
render pages) into two separate requests. Performing an action, such as
clicking a link or submitting a form,
results in a <client side redirect> to the new page. This is often called
"redirect after post". This helps ensure