No, I understood what you are saying, when you put something on the environment in the page and then try to access it in a component, you are using the environment (via the Environmental annotation). What you are missing is that the forms event phases do not have access to the environment that is setup during the render phases of the page, only the environment that is setup during the onActivate of a page.
So back to my previous recommendation, using the form context would look something like this: MyPage.java public class MyPage { @Inject private Environment environment; @Inject private UserLookup userLookup; Private User user; @OnEvent("activate") onActivate(int userId) { user = userLookup(userId); } @SetupRender void setupRender() { environment.push(User.class, user); } @CleanupRender void cleanupRender() { environment.pop(User.class); } } MyComponent.java Public class MyComponent { @Inject private UserLookup userLookup; @Environmental User user; public final String getUserName() { return user.getName(); } public final List<Object> getFormContext() { List<Object> context = new ArrayList<Object>(); context.add(user.getId()); return context; } @OnEvent(value = "success", component = "myForm") Void onSuccessFromMyForm(int userId) { User localUser = userLookup(userId); doSomeActionOnUser(localUser); } } MyComponent.tml: <div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"> <span>Current User: ${username}</span> <t:form t:id="myForm" context="formContext"> ... </t:form> </div> -----Original Message----- From: Kevin Crenshaw [mailto:[EMAIL PROTECTED] Sent: Thursday, August 21, 2008 7:07 PM To: Tapestry users Subject: Re: Unable to process form submission Adam, Thanks for responding (again :-) ) . However, as you can see in my question, I'm not trying to use the environment during an event phase - sorry if I misspoke before. The user object is placed on the environment in the SetupRender phase. The problem is that after I submit the form I get the 'user not available on the environment' error. I have attempted to add the userId onto the context of the form as you suggest, but I still get the error. Since I have never dealt with form submissions in tapestry before, I was hoping for an example of how to utilize the context to avoid the error and process the form as expected. thanks, Kevin Adam Ayres wrote: > The best way to achieve this is to put the userId on the context of the > form using the "context" parameter. You will then have access to the > userId in the OnEvent of the form to do a lookup of the User. > > If you insist on using the environment during the form submission event > phase to get the User, which I recommend against, then you could push > the User onto the environment during the onActivate of the page. The > onActivate of a page is run during the event phase of a form action as > well as the normal rendering of a page, however the environment is > cleared after the onActivate, so you would need to setup the environment > in both the onActivate and setupRender if you took this approach. > > Philosophically I am against setting up the environment in onActivate of > a page since the onActivate would need to know about all possible > enviornmentals needed by any of the forms or actions it may contain that > require context. By putting the context into the form action (or in the > context of an action link) the component that contains the form or > action is then responsible for providing the context of the event. > > Thanks, > Adam > > > -----Original Message----- > From: Kevin Crenshaw [mailto:[EMAIL PROTECTED] > Sent: Thursday, August 21, 2008 3:49 PM > To: users@tapestry.apache.org > Subject: Unable to process form submission > > I have a page that contains a component that contains a form component. > > The page places a user object on the environment in its SetupRender > phase that is used by the page's components. The User object is obtained > > using the userId that is passed in the page context. When I submit the > form I get the error > org.apache.tapestry.runtime.ComponentEventException. No object of type > IUser is available from the environment. Available types are.... How > do get around this error? Do I need to place the userId back on the > page context? Does anyone have an example of how to do this? > > I am using Tapestry 5.0.11 > > TIA, > > Kevin > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]