object should /not/ be initialized on page creation.
Pages are pooled; state information in the page is not.
If the page-property is a "persistent" property, it is "attached" at
page render and "detached" (page property set to null) when the page
finishes rendering by the framework. If the property is not persistent,
it is still set back to null at the end of page rendering to prevent
goofups like user b seeing user a's account information.
So, you initialize things in pageBeginRender.
Now, you've inited in pageBeginRender, but you probably don't want to
re-init when the form is submitted, because you may be "re-initting"
something that shouldn't be initialized. One solution to this dilemma
is to do something like:
pageBeginRender(PageEvent event) {
if (!event.getRequestCycle.isRewinding()) {
//initialize objects here.
}
}
Then, you use the "hidden" component to store necessary objects at the
top of your form. Then your object gets re-initialized automatically on
form submission in time for things after it to not be null.
Or... you can just make the property persistent, depending on your views
on stateful vs. stateless webapps, session-use, etc.
Robert
Chris Chiappone wrote:
> now im totally confused. The object should have been initialized on
> page creation, how come it would become null when submitting the form?
>
> On 7/15/05, Danny Mandel <[EMAIL PROTECTED]> wrote:
>
>>This error means that your appInfo object is null. So, wherever you
>>moved your appInfo restoration/initialization logic, it's not getting
>>called int this case anymore.
>>
>>Danny
>>
>>Chris Chiappone wrote:
>>
>>
>>>Thanks for the quick responses. The two responses I got were
>>>basically the same so I tried it. The problem is now I get:
>>>
>>>binding: ExpressionBinding[EditApp appInfo.name]
>>>location: context:/WEB-INF/EditApp.page, line 41, column 58
>>>
>>>ognl.OgnlException
>>>source is null for getProperty(null, "name")
>>>
>>>So I am still a bit stuck on what I should do.
>>>
>>>On 7/15/05, Danny Mandel <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>>
>>>>In your pageBeginRender method you can check to see if the form is
>>>>rewinding. If it is, you probably don't want to initialize things in
>>>>there i.e.:
>>>>
>>>>public void pageBeginRender(PageEvent event) {
>>>> if (!event.getRequestCycle().isRewinding()) {
>>>> // do your normal initialization stuff and create if null
>>>> }
>>>>}
>>>>
>>>>In the case where it is rewinding, then you'll want to move your object
>>>>retrieval/restoration to a different place. This can be done by binding
>>>>your object's id to a hidden field that will fetch it or by use of a
>>>>data squeezer. This has been addressed many times on this list so it
>>>>should be in the archives and I know that there is a wiki page on using
>>>>a data squeezer to do this sort of thing:
>>>>
>>>>http://wiki.apache.org/jakarta-tapestry/DataSqueezer
>>>>
>>>>Hope that helps,
>>>>Danny
>>>>
>>>>Chris Chiappone wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>I am a bit confused about how pageBeginRender works during a form
>>>>>submission Here is the code i have:
>>>>>
>>>>> public void pageBeginRender(PageEvent event) {
>>>>> // initialize app
>>>>> retrieveApp(getAppVerId());
>>>>> }
>>>>>
>>>>> private void retrieveApp(Long id){
>>>>> if(id != null){
>>>>> System.out.println("Updating App: "+ id);
>>>>> AppDAO dao = new AppDAO();
>>>>> AppVer ver = null;
>>>>> AppInfo info = null;
>>>>> ver = dao.getAppVerId(id, false);
>>>>> info = ver.getAppInfo();
>>>>> setAppInfo(info);
>>>>> setAppVer(ver);
>>>>> }
>>>>> if(getAppInfo() == null){
>>>>> System.out.println("Creating a new application");
>>>>> setAppInfo(new AppInfo());
>>>>> setAppVer(new AppVer());
>>>>> getAppVer().setRegdate(new Date());
>>>>> }
>>>>> }
>>>>>
>>>>> /**
>>>>> * Action taken when this form has been submitted
>>>>> *
>>>>> * @param cycle
>>>>> */
>>>>> public void formSubmit(IRequestCycle cycle){
>>>>> System.out.println("Current VerId = "+ getAppVerId());
>>>>> // Check to see all validation was a success
>>>>> ValidationDelegate delegate =
>>>>>(ValidationDelegate)getBeans().getBean("delegate");
>>>>>
>>>>> if(!delegate.getHasErrors()){
>>>>> // Insert the new version
>>>>> AppDAO dao = new AppDAO();
>>>>> AppInfo info = getAppInfo();
>>>>> AppVer ver = getAppVer();
>>>>>
>>>>>....
>>>>>
>>>>>Basically I need to initialize the AppInfo and AppVer objects when the
>>>>>page is rendered. The page is an add/edit form. If appVerId is not
>>>>>null I lookup AppInfo and AppVer to populate my form for editing, if
>>>>>null create new objects. This seems to work fine. THe problem I am
>>>>>having is that when I submit the form It create a new AppVer and
>>>>>AppInfo because appVerId appears to be null in pageBeginRender(Event)
>>>>>but when it continues to formSubmit my print is showing the the
>>>>>appVerId != null which is what I expect. The problem is the objects
>>>>>have been intialized as new so it ends up creating duplicates. Hope I
>>>>>made this clear.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>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]