You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Chris Lewis <ch...@bellsouth.net> on 2007/09/28 15:59:41 UTC
T5: when/where to contribute a PageRenderCommand
I'm creating something like DocumentScriptBuilder for inserting
stylesheets, much like DocumentScriptBuilderImpl does for javascripts. I
have this method in my app module, inspired by the method in TapestryModule:
public void
contributePageRenderInitializer(OrderedConfiguration<PageRenderCommand>
configuration) {
configuration.add("DocumentStyleBuilder", new PageRenderCommand() {
public void cleanup(Environment environment) {
DocumentStyleBuilder builder =
environment.pop(DocumentStyleBuilder.class);
Document doc = environment.peek(Document.class);
builder.updateDocument(doc);
}
public void setup(Environment environment) {
environment.push(DocumentStyleBuilder.class, new
DocumentStyleBuilderImpl());
}
}, "before:PageRenderSupport");
}
When I try to inject this via @Environmental, a RuntimeException is
thrown with this message:
"No object of type xxx.services.DocumentStyleBuilder is available from
the Environment. Available types are ."
With logging I've verified that this is thrown _before_ my contribution
is called, suggesting that the page using the @Environmental (my Start
page) is initialized before my contribution is called. I tried using
"before:PageRenderSupport" as a constraint to no avail. How can I get my
object into the environment, since mimicking what's in TapestryModule
doesn't seem to work?
thanks!
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: when/where to contribute a PageRenderCommand
Posted by Chris Lewis <ch...@bellsouth.net>.
Thanks - setupRender() did it. I wasn't aware of the order of calling,
but it makes sense now that you mention it (I understand the rendering
is totally from page activation). Thanks for the clarification :)
Howard Lewis Ship wrote:
> onActivate() (i.e., the "activate" event) is not part of rendering, it comes
> very early in the request handling process.
>
> I think you want to do something more like beginRender() or even
> setupRender().
>
> On 9/30/07, Chris Lewis <ch...@bellsouth.net> wrote:
>
>> FYI I just upgraded to 5.0.6-SNAPSHOT with the same results.
>>
>> Howard Lewis Ship wrote:
>>
>>> Could we see your Start page?
>>>
>>>
>>> On 9/28/07, Chris Lewis <ch...@bellsouth.net> wrote:
>>>
>>>
>>>> I'm creating something like DocumentScriptBuilder for inserting
>>>> stylesheets, much like DocumentScriptBuilderImpl does for javascripts.
>>>>
>> I
>>
>>>> have this method in my app module, inspired by the method in
>>>> TapestryModule:
>>>>
>>>> public void
>>>> contributePageRenderInitializer(OrderedConfiguration<PageRenderCommand>
>>>> configuration) {
>>>>
>>>> configuration.add("DocumentStyleBuilder", new
>>>>
>> PageRenderCommand()
>>
>>>> {
>>>>
>>>> public void cleanup(Environment environment) {
>>>> DocumentStyleBuilder builder =
>>>> environment.pop(DocumentStyleBuilder.class);
>>>> Document doc = environment.peek(Document.class);
>>>> builder.updateDocument(doc);
>>>> }
>>>>
>>>> public void setup(Environment environment) {
>>>> environment.push(DocumentStyleBuilder.class, new
>>>> DocumentStyleBuilderImpl());
>>>> }
>>>>
>>>> }, "before:PageRenderSupport");
>>>> }
>>>>
>>>> When I try to inject this via @Environmental, a RuntimeException is
>>>> thrown with this message:
>>>> "No object of type xxx.services.DocumentStyleBuilder is available from
>>>> the Environment. Available types are ."
>>>>
>>>> With logging I've verified that this is thrown _before_ my contribution
>>>> is called, suggesting that the page using the @Environmental (my Start
>>>> page) is initialized before my contribution is called. I tried using
>>>> "before:PageRenderSupport" as a constraint to no avail. How can I get
>>>>
>> my
>>
>>>> object into the environment, since mimicking what's in TapestryModule
>>>> doesn't seem to work?
>>>>
>>>> thanks!
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>
>
>
Re: T5: when/where to contribute a PageRenderCommand
Posted by Howard Lewis Ship <hl...@gmail.com>.
onActivate() (i.e., the "activate" event) is not part of rendering, it comes
very early in the request handling process.
I think you want to do something more like beginRender() or even
setupRender().
On 9/30/07, Chris Lewis <ch...@bellsouth.net> wrote:
>
> FYI I just upgraded to 5.0.6-SNAPSHOT with the same results.
>
> Howard Lewis Ship wrote:
> > Could we see your Start page?
> >
> >
> > On 9/28/07, Chris Lewis <ch...@bellsouth.net> wrote:
> >
> >> I'm creating something like DocumentScriptBuilder for inserting
> >> stylesheets, much like DocumentScriptBuilderImpl does for javascripts.
> I
> >> have this method in my app module, inspired by the method in
> >> TapestryModule:
> >>
> >> public void
> >> contributePageRenderInitializer(OrderedConfiguration<PageRenderCommand>
> >> configuration) {
> >>
> >> configuration.add("DocumentStyleBuilder", new
> PageRenderCommand()
> >> {
> >>
> >> public void cleanup(Environment environment) {
> >> DocumentStyleBuilder builder =
> >> environment.pop(DocumentStyleBuilder.class);
> >> Document doc = environment.peek(Document.class);
> >> builder.updateDocument(doc);
> >> }
> >>
> >> public void setup(Environment environment) {
> >> environment.push(DocumentStyleBuilder.class, new
> >> DocumentStyleBuilderImpl());
> >> }
> >>
> >> }, "before:PageRenderSupport");
> >> }
> >>
> >> When I try to inject this via @Environmental, a RuntimeException is
> >> thrown with this message:
> >> "No object of type xxx.services.DocumentStyleBuilder is available from
> >> the Environment. Available types are ."
> >>
> >> With logging I've verified that this is thrown _before_ my contribution
> >> is called, suggesting that the page using the @Environmental (my Start
> >> page) is initialized before my contribution is called. I tried using
> >> "before:PageRenderSupport" as a constraint to no avail. How can I get
> my
> >> object into the environment, since mimicking what's in TapestryModule
> >> doesn't seem to work?
> >>
> >> thanks!
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >>
> >
> >
> >
>
>
--
Howard M. Lewis Ship
Partner and Senior Architect at Feature50
Creator Apache Tapestry and Apache HiveMind
Re: T5: when/where to contribute a PageRenderCommand
Posted by Chris Lewis <ch...@bellsouth.net>.
FYI I just upgraded to 5.0.6-SNAPSHOT with the same results.
Howard Lewis Ship wrote:
> Could we see your Start page?
>
>
> On 9/28/07, Chris Lewis <ch...@bellsouth.net> wrote:
>
>> I'm creating something like DocumentScriptBuilder for inserting
>> stylesheets, much like DocumentScriptBuilderImpl does for javascripts. I
>> have this method in my app module, inspired by the method in
>> TapestryModule:
>>
>> public void
>> contributePageRenderInitializer(OrderedConfiguration<PageRenderCommand>
>> configuration) {
>>
>> configuration.add("DocumentStyleBuilder", new PageRenderCommand()
>> {
>>
>> public void cleanup(Environment environment) {
>> DocumentStyleBuilder builder =
>> environment.pop(DocumentStyleBuilder.class);
>> Document doc = environment.peek(Document.class);
>> builder.updateDocument(doc);
>> }
>>
>> public void setup(Environment environment) {
>> environment.push(DocumentStyleBuilder.class, new
>> DocumentStyleBuilderImpl());
>> }
>>
>> }, "before:PageRenderSupport");
>> }
>>
>> When I try to inject this via @Environmental, a RuntimeException is
>> thrown with this message:
>> "No object of type xxx.services.DocumentStyleBuilder is available from
>> the Environment. Available types are ."
>>
>> With logging I've verified that this is thrown _before_ my contribution
>> is called, suggesting that the page using the @Environmental (my Start
>> page) is initialized before my contribution is called. I tried using
>> "before:PageRenderSupport" as a constraint to no avail. How can I get my
>> object into the environment, since mimicking what's in TapestryModule
>> doesn't seem to work?
>>
>> thanks!
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
>
>
>
Re: T5 form field validation, component injection
Posted by "Marc A. Donis" <ma...@runbox.com>.
Thanks for that fantastic reply. Yes, in fact, the Component annotation is
exactly what I was missing. Don't know why I didn't see it before...
And that Input Validate page you refered me to is quite a help. Reading
avidly.
Thanks!
Marc
----- Original Message -----
From: "lasitha" <la...@gmail.com>
To: "Tapestry users" <us...@tapestry.apache.org>
Sent: Saturday, September 29, 2007 19:40
Subject: Re: T5 form field validation, component injection
> Hello Marc,
>
> I think you want the @Component annotation instead of
> @InjectComponent. The latter is "Used exclusively inside a mixin to
> connect the mixin to the component to which it is attached."[1]
>
> I haven't tested whether this will solve your problem, but it seems
> likely.
>
> A good starting point for basic form validation is probably the 'Input
> Validation' page of the online documentation[2]. It comes with a
> simple example and a lot of useful info.
>
> As an aside, you can use Form.recordError() as a convenience around
> getDefaultTracker().getErrors().add().
>
> HTH. Cheers,
> lasitha.
>
> [1]
> http://tapestry.apache.org/tapestry5/tapestry-core/apidocs/org/apache/tapestry/annotations/InjectComponent.html
> [2]
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/validation.html
>
>
> On 9/29/07, Marc A. Donis <ma...@runbox.com> wrote:
>> Hi all,
>>
>> I am trying to understand how to implement custom validation of form
>> fields.
>> Here's what I've got so far:
>>
>> CreateAccount.java:
>>
>> public class CreateAccount {
>> @InjectComponent
>> private Form createAccountForm;
>>
>> @OnEvent(value = "validate", component = "createAccountForm")
>> void validate() throws ValidationException {
>> log.debug("validate");
>> if (password == null || !password.equals(password2)) {
>>
>> createAccountForm.getDefaultTracker().getErrors().add("passwords
>> don't match");
>> }
>> }
>> }
>>
>> and CreateAccount.html:
>>
>> <t:form t:id="createAccountForm">
>> <t:errors/>
>> <t:passwordfield t:id="password" t:validate="required,minLength=4"/>
>> <t:passwordfield t:id="password2" t:validate="required"/>
>> ... etc
>>
>>
>> This is failing because Tapestry is trying to cast CreateAccount to
>> Form...
>> but why? Am I going about this all wrong? What am I missing here?
>>
>> I feel a bit like I am stumbling around in the dark. Does anybody know
>> of
>> some T5 examples I can look at, just to get me going?
>>
>> tia,
>> Marc
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5 form field validation, component injection
Posted by lasitha <la...@gmail.com>.
Hello Marc,
I think you want the @Component annotation instead of
@InjectComponent. The latter is "Used exclusively inside a mixin to
connect the mixin to the component to which it is attached."[1]
I haven't tested whether this will solve your problem, but it seems likely.
A good starting point for basic form validation is probably the 'Input
Validation' page of the online documentation[2]. It comes with a
simple example and a lot of useful info.
As an aside, you can use Form.recordError() as a convenience around
getDefaultTracker().getErrors().add().
HTH. Cheers,
lasitha.
[1] http://tapestry.apache.org/tapestry5/tapestry-core/apidocs/org/apache/tapestry/annotations/InjectComponent.html
[2]
http://tapestry.apache.org/tapestry5/tapestry-core/guide/validation.html
On 9/29/07, Marc A. Donis <ma...@runbox.com> wrote:
> Hi all,
>
> I am trying to understand how to implement custom validation of form fields.
> Here's what I've got so far:
>
> CreateAccount.java:
>
> public class CreateAccount {
> @InjectComponent
> private Form createAccountForm;
>
> @OnEvent(value = "validate", component = "createAccountForm")
> void validate() throws ValidationException {
> log.debug("validate");
> if (password == null || !password.equals(password2)) {
> createAccountForm.getDefaultTracker().getErrors().add("passwords
> don't match");
> }
> }
> }
>
> and CreateAccount.html:
>
> <t:form t:id="createAccountForm">
> <t:errors/>
> <t:passwordfield t:id="password" t:validate="required,minLength=4"/>
> <t:passwordfield t:id="password2" t:validate="required"/>
> ... etc
>
>
> This is failing because Tapestry is trying to cast CreateAccount to Form...
> but why? Am I going about this all wrong? What am I missing here?
>
> I feel a bit like I am stumbling around in the dark. Does anybody know of
> some T5 examples I can look at, just to get me going?
>
> tia,
> Marc
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
T5 form field validation, component injection
Posted by "Marc A. Donis" <ma...@runbox.com>.
Hi all,
I am trying to understand how to implement custom validation of form fields.
Here's what I've got so far:
CreateAccount.java:
public class CreateAccount {
@InjectComponent
private Form createAccountForm;
@OnEvent(value = "validate", component = "createAccountForm")
void validate() throws ValidationException {
log.debug("validate");
if (password == null || !password.equals(password2)) {
createAccountForm.getDefaultTracker().getErrors().add("passwords
don't match");
}
}
}
and CreateAccount.html:
<t:form t:id="createAccountForm">
<t:errors/>
<t:passwordfield t:id="password" t:validate="required,minLength=4"/>
<t:passwordfield t:id="password2" t:validate="required"/>
... etc
This is failing because Tapestry is trying to cast CreateAccount to Form...
but why? Am I going about this all wrong? What am I missing here?
I feel a bit like I am stumbling around in the dark. Does anybody know of
some T5 examples I can look at, just to get me going?
tia,
Marc
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: when/where to contribute a PageRenderCommand
Posted by Chris Lewis <ch...@bellsouth.net>.
My Start.java follows - note that *themes.default* is a symbol
contributed in my app module. It is valid as I am able to inject and
access it via a getter.
package com.propertypix.www.pages;
import org.apache.tapestry.Asset;
import org.apache.tapestry.annotations.Environmental;
import org.apache.tapestry.annotations.Inject;
import org.apache.tapestry.annotations.Path;
public class Start
{
@Inject
@Path("${theme.default}")
private Asset style;
@Environmental
private DocumentStyleBuilder styleBuilder;
void onActivate() {
styleBuilder.addStyleLink(style);
}
}
Howard Lewis Ship wrote:
> Could we see your Start page?
>
>
> On 9/28/07, Chris Lewis <ch...@bellsouth.net> wrote:
>
>> I'm creating something like DocumentScriptBuilder for inserting
>> stylesheets, much like DocumentScriptBuilderImpl does for javascripts. I
>> have this method in my app module, inspired by the method in
>> TapestryModule:
>>
>> public void
>> contributePageRenderInitializer(OrderedConfiguration<PageRenderCommand>
>> configuration) {
>>
>> configuration.add("DocumentStyleBuilder", new PageRenderCommand()
>> {
>>
>> public void cleanup(Environment environment) {
>> DocumentStyleBuilder builder =
>> environment.pop(DocumentStyleBuilder.class);
>> Document doc = environment.peek(Document.class);
>> builder.updateDocument(doc);
>> }
>>
>> public void setup(Environment environment) {
>> environment.push(DocumentStyleBuilder.class, new
>> DocumentStyleBuilderImpl());
>> }
>>
>> }, "before:PageRenderSupport");
>> }
>>
>> When I try to inject this via @Environmental, a RuntimeException is
>> thrown with this message:
>> "No object of type xxx.services.DocumentStyleBuilder is available from
>> the Environment. Available types are ."
>>
>> With logging I've verified that this is thrown _before_ my contribution
>> is called, suggesting that the page using the @Environmental (my Start
>> page) is initialized before my contribution is called. I tried using
>> "before:PageRenderSupport" as a constraint to no avail. How can I get my
>> object into the environment, since mimicking what's in TapestryModule
>> doesn't seem to work?
>>
>> thanks!
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
>
>
>
Re: T5: when/where to contribute a PageRenderCommand
Posted by Howard Lewis Ship <hl...@gmail.com>.
Could we see your Start page?
On 9/28/07, Chris Lewis <ch...@bellsouth.net> wrote:
>
> I'm creating something like DocumentScriptBuilder for inserting
> stylesheets, much like DocumentScriptBuilderImpl does for javascripts. I
> have this method in my app module, inspired by the method in
> TapestryModule:
>
> public void
> contributePageRenderInitializer(OrderedConfiguration<PageRenderCommand>
> configuration) {
>
> configuration.add("DocumentStyleBuilder", new PageRenderCommand()
> {
>
> public void cleanup(Environment environment) {
> DocumentStyleBuilder builder =
> environment.pop(DocumentStyleBuilder.class);
> Document doc = environment.peek(Document.class);
> builder.updateDocument(doc);
> }
>
> public void setup(Environment environment) {
> environment.push(DocumentStyleBuilder.class, new
> DocumentStyleBuilderImpl());
> }
>
> }, "before:PageRenderSupport");
> }
>
> When I try to inject this via @Environmental, a RuntimeException is
> thrown with this message:
> "No object of type xxx.services.DocumentStyleBuilder is available from
> the Environment. Available types are ."
>
> With logging I've verified that this is thrown _before_ my contribution
> is called, suggesting that the page using the @Environmental (my Start
> page) is initialized before my contribution is called. I tried using
> "before:PageRenderSupport" as a constraint to no avail. How can I get my
> object into the environment, since mimicking what's in TapestryModule
> doesn't seem to work?
>
> thanks!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Howard M. Lewis Ship
Partner and Senior Architect at Feature50
Creator Apache Tapestry and Apache HiveMind