On Thursday 29 December 2005 11:06, Andreas Idl wrote:
> Hi
>
> 1. session = use visit objects for session values.
> 2. parameters between to pages = you may call a setter of the destination
> page
>
> here an example of a directlink listener:
>
> Integer value= (Integer)cycle.getServiceParameters()[0];
> DestinationPage page = (DestinationPage)
>       cycle.getPage("DestinationPage");
> page.setValue(value);
> cycle.activate(page);
>
> Andreas

That seems more complex than it need be.  The examples below carries an 
integer variable around between all the pages called function which is used 
to determine a high level function I am performing

I do something like the following

In the template

<form jwcid="@Form" listener="listener:doUpdate" delegate="bean:delegate">
<span jwcid="@Hidden" value="ognl:function" />
...
</form

and in the java PageClass

        @InjectPage("Select")
        public abstract Select getSelectPage();

        public abstract void setFunction(int function);
        public abstract int getFunction();

        public IPage doUpdate () {
                Select select = getSelectPage();
                select.setFunction(getFunction());  // Don't say done anything
                return select;
        }

This shows calling a new page called "Select" with the function that I am 
carrying around in a hidden field in my form. (It was set in a similar way by 
the previous caller to this page.)

This avoids the need to create a session for the user with the additional 
overhead that it needs.

It is of course also possible to set a new parameter via DirectLink parameters

Here is a little snippet from a table (using contrib:table) where the 
directlink has a parameter (an id) which gets passed to the listener and then 
on to the called page

                <td jwcid="[EMAIL PROTECTED]">
                <a jwcid="[EMAIL PROTECTED]"
                listener="listener:doEdit"
                parameters="ognl:{function,components.table.tableRow.id}"
                class="name"
                ><span jwcid="@Insert"
                        value="ognl:components.table.tableRow.surname"
                        >Chandler</span></a></td>


And from the page class

        @InjectPage("Edit") 
        public abstract Edit getEditPage();  
         
        public Edit doEdit(int function, int id) { 
                Edit edit = getEditPage(); 
                // ignore the function parameter - not using it in the html - 
set directly 
                edit.setFunction(Function.EDIT); 
                edit.setPersonId(id); 
                return edit; 
        } 


Again, avoiding setting up a session at this point.

Just a little point about ordering on the target page.  The page attach 
listener in the last example is fired at the point where I call 
getEditPage().  I use the parameter id to read the database in the edit page.  
I have to do that in the Page Validate Listener - since when the page attach 
listener is called the value is not yet set.

-- 
Alan Chandler
http://www.chandlerfamily.org.uk
Open Source. It's the difference between trust and antitrust.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to