You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Tobias Frech <to...@frech.info> on 2003/03/04 18:16:36 UTC

Wrong way to go back to the back that called me ?

Hi!

I have a page which displays various items. Each of these items has an 
addtional  "edit" link. When the user clicks on that link he is taken to 
a page that lets him edit that item. Since this edit page can be 
"called" from various different pages I'd like to go back to the page 
that called the edit page after the user is done with editing.

I go to the edit page with this code in the listener method:

FunclinkEdit tledit = (FunclinkEdit) cycle.getPage("FunclinkEditSeite");
tledit.setFunclink(aktuellerFunclink);
tledit.setCallingPage(this);
cycle.setPage(tledit);

The item that should be edited is stored in aktuellerFunclink. The idea 
is to pass the calling page to the component ("this") and let it return 
with (also in a listener method):

public void speichernAusgewaehlt(IRequestCycle cycle) {
  cycle.setPage(callingPage);
}

callingPage contains the value that has been set by setCallingPage() 
(see above).
This worked pretty well up to now.


Lately I started to store some stuff (namely a reference to a 
UserTransaction) in the Visit object of the session. I access the object 
with code like this:

UserTransaction trans = ((Visit) this.getVisit()).getUserTransaction();

Now, if the user is done editing and the program tries to return to the 
calling page the above line of code fails. I do get this error:

17:46:29,308 ERROR [STDERR] java.lang.NullPointerException
17:46:29,309 ERROR [STDERR]     at 
net.sf.tapestry.AbstractPage.getVisit(Abstrac
tPage.java:430)
17:46:29,309 ERROR [STDERR]     at 
info.frech.DetailEdit.getAlleTechlinks(Detail
Edit.java:261)
17:46:29,310 ERROR [STDERR]     at 
sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)


I am using Tapestry 2.4 Alpha 3 so the NPE happens here :


    /**
     *  Returns the visit object obtained from the engine via
     *  {@link IEngine#getVisit(IRequestCycle)}.
     *
     **/

    public Object getVisit()
    {
        if (_visit == null)
            _visit = _engine.getVisit(_requestCycle);   /** in this 
line, so _engine is null ? **/

        return _visit;
    }


If I return to the calling page with code like in the very first code 
example in this post everything works fine.

My question is if that what I am doing (using "this" to pass the page to 
which should be returned) is forbidden ?
Should this work ?
If it should, shall I file a bug report then ?

If there is any reason why this can't work, I'd to know the reason and 
learn a bit more about the Tapestry framework ;)

If you have any general advice about what I am doing I am happy to hear 
your advice (hope I didn't get the whole Tapestry concept wrong).

Thanks for your time,
ciao,

Tobias




Re: Wrong way to go back to the back that called me ?

Posted by Geoff Longman <gl...@intelligentworks.com>.
Try ICallback:

public class Originator extends BasePage {

  public void someListener(IRequestCycle cycle) {

    EditPage target = (EditPage)cycle.getPage("EditPage");
    target.setCallback(new PageCallback(getName());
    cycle.setPage(target);
  }
}

public class EditPage extends BasePage {

 private ICallback callback;

 public void setCallback(ICallback callback) {
   this.callback = callback;
 }

  public void someOtherListener(IRequestCycle cycle) {
    if (callback != null) {
       callback.performCallback(cycle);
   }
}

Geoff
----- Original Message ----- 
From: "Tobias Frech" <to...@frech.info>
To: "Tapestry User" <ta...@jakarta.apache.org>
Sent: Tuesday, March 04, 2003 12:16 PM
Subject: Wrong way to go back to the back that called me ?


> Hi!
> 
> I have a page which displays various items. Each of these items has an 
> addtional  "edit" link. When the user clicks on that link he is taken to 
> a page that lets him edit that item. Since this edit page can be 
> "called" from various different pages I'd like to go back to the page 
> that called the edit page after the user is done with editing.
> 
> I go to the edit page with this code in the listener method:
> 
> FunclinkEdit tledit = (FunclinkEdit) cycle.getPage("FunclinkEditSeite");
> tledit.setFunclink(aktuellerFunclink);
> tledit.setCallingPage(this);
> cycle.setPage(tledit);
> 
> The item that should be edited is stored in aktuellerFunclink. The idea 
> is to pass the calling page to the component ("this") and let it return 
> with (also in a listener method):
> 
> public void speichernAusgewaehlt(IRequestCycle cycle) {
>   cycle.setPage(callingPage);
> }
> 
> callingPage contains the value that has been set by setCallingPage() 
> (see above).
> This worked pretty well up to now.
> 
> 
> Lately I started to store some stuff (namely a reference to a 
> UserTransaction) in the Visit object of the session. I access the object 
> with code like this:
> 
> UserTransaction trans = ((Visit) this.getVisit()).getUserTransaction();
> 
> Now, if the user is done editing and the program tries to return to the 
> calling page the above line of code fails. I do get this error:
> 
> 17:46:29,308 ERROR [STDERR] java.lang.NullPointerException
> 17:46:29,309 ERROR [STDERR]     at 
> net.sf.tapestry.AbstractPage.getVisit(Abstrac
> tPage.java:430)
> 17:46:29,309 ERROR [STDERR]     at 
> info.frech.DetailEdit.getAlleTechlinks(Detail
> Edit.java:261)
> 17:46:29,310 ERROR [STDERR]     at 
> sun.reflect.NativeMethodAccessorImpl.invoke0(
> Native Method)
> 
> 
> I am using Tapestry 2.4 Alpha 3 so the NPE happens here :
> 
> 
>     /**
>      *  Returns the visit object obtained from the engine via
>      *  {@link IEngine#getVisit(IRequestCycle)}.
>      *
>      **/
> 
>     public Object getVisit()
>     {
>         if (_visit == null)
>             _visit = _engine.getVisit(_requestCycle);   /** in this 
> line, so _engine is null ? **/
> 
>         return _visit;
>     }
> 
> 
> If I return to the calling page with code like in the very first code 
> example in this post everything works fine.
> 
> My question is if that what I am doing (using "this" to pass the page to 
> which should be returned) is forbidden ?
> Should this work ?
> If it should, shall I file a bug report then ?
> 
> If there is any reason why this can't work, I'd to know the reason and 
> learn a bit more about the Tapestry framework ;)
> 
> If you have any general advice about what I am doing I am happy to hear 
> your advice (hope I didn't get the whole Tapestry concept wrong).
> 
> Thanks for your time,
> ciao,
> 
> Tobias
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 


RE: Wrong way to go back to the back that called me ?

Posted by "Howard M. Lewis Ship" <hl...@attbi.com>.
You should not hold onto the page *instance*.  Tapestry pools pages, so from
request to request, a single user may "touch" many different page instances
with the same name.

Instead, have your edit page use a persistent page property to store the
*name* of the page to return to.

For more flexibility, use the ICallback interface instead.  It is designed
for this exact purpose.  The Virtual Library uses ICallback to handle
returning the user to the right spot after they log in (on the fly).

--
Howard M. Lewis Ship
Creator, Tapestry: Java Web Components
http://jakarta.apache.org/proposals/tapestry



> -----Original Message-----
> From: Tobias Frech [mailto:tobias@frech.info] 
> Sent: Tuesday, March 04, 2003 12:17 PM
> To: Tapestry User
> Subject: Wrong way to go back to the back that called me ?
> 
> 
> Hi!
> 
> I have a page which displays various items. Each of these 
> items has an 
> addtional  "edit" link. When the user clicks on that link he 
> is taken to 
> a page that lets him edit that item. Since this edit page can be 
> "called" from various different pages I'd like to go back to the page 
> that called the edit page after the user is done with editing.
> 
> I go to the edit page with this code in the listener method:
> 
> FunclinkEdit tledit = (FunclinkEdit) 
> cycle.getPage("FunclinkEditSeite");
> tledit.setFunclink(aktuellerFunclink);
> tledit.setCallingPage(this);
> cycle.setPage(tledit);
> 
> The item that should be edited is stored in 
> aktuellerFunclink. The idea 
> is to pass the calling page to the component ("this") and let 
> it return 
> with (also in a listener method):
> 
> public void speichernAusgewaehlt(IRequestCycle cycle) {
>   cycle.setPage(callingPage);
> }
> 
> callingPage contains the value that has been set by setCallingPage() 
> (see above).
> This worked pretty well up to now.
> 
> 
> Lately I started to store some stuff (namely a reference to a 
> UserTransaction) in the Visit object of the session. I access 
> the object 
> with code like this:
> 
> UserTransaction trans = ((Visit) 
> this.getVisit()).getUserTransaction();
> 
> Now, if the user is done editing and the program tries to 
> return to the 
> calling page the above line of code fails. I do get this error:
> 
> 17:46:29,308 ERROR [STDERR] java.lang.NullPointerException
> 17:46:29,309 ERROR [STDERR]     at 
> net.sf.tapestry.AbstractPage.getVisit(Abstrac
> tPage.java:430)
> 17:46:29,309 ERROR [STDERR]     at 
> info.frech.DetailEdit.getAlleTechlinks(Detail
> Edit.java:261)
> 17:46:29,310 ERROR [STDERR]     at 
> sun.reflect.NativeMethodAccessorImpl.invoke0(
> Native Method)
> 
> 
> I am using Tapestry 2.4 Alpha 3 so the NPE happens here :
> 
> 
>     /**
>      *  Returns the visit object obtained from the engine via
>      *  {@link IEngine#getVisit(IRequestCycle)}.
>      *
>      **/
> 
>     public Object getVisit()
>     {
>         if (_visit == null)
>             _visit = _engine.getVisit(_requestCycle);   /** in this 
> line, so _engine is null ? **/
> 
>         return _visit;
>     }
> 
> 
> If I return to the calling page with code like in the very first code 
> example in this post everything works fine.
> 
> My question is if that what I am doing (using "this" to pass 
> the page to 
> which should be returned) is forbidden ?
> Should this work ?
> If it should, shall I file a bug report then ?
> 
> If there is any reason why this can't work, I'd to know the 
> reason and 
> learn a bit more about the Tapestry framework ;)
> 
> If you have any general advice about what I am doing I am 
> happy to hear 
> your advice (hope I didn't get the whole Tapestry concept wrong).
> 
> Thanks for your time,
> ciao,
> 
> Tobias
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>