Following on from my problem with the @For loop in the thread just above this, 
I have re-achitected my page to use the @InvokeListener componenent.

The problem I am trying to address is that roleList (see below) is read from a 
database via a single SQL instruction, and I want to avoid having to re-read 
it to see if a record is changed in the form - to see if I need to update it.

I am doing something like this

<span jwcid="@For" source="ognl:roleList" value="ognl:role">
        <span jwcid="@InvokeListener" listener="listener:saveOriginal" />
        <input jwcid="[EMAIL PROTECTED]" value="ognl:role.name" />
... (other fields)
        <span jwcid="@InvokeListener" listener="listener:doUpdate" />
</span>


In my java page class I have the following

        public abstract Role getRole();
        public abstract Role getOriginal();
        public abstract void setOriginal(Role role);

and the listeners

        public void saveOriginal(IRequestCycle cycle) {
                if (cycle.isRewinding()) {
                        Role role = new Role(getRole());      //Role class 
creates a cloned object
                        setOriginal(role);
                }
        }

        public void doUpdate(IRequestCycle cycle) {
                if(cycle.isRewinding()) {
                        Role updatedRole = getRole();
                        Role originalRole = getOriginal();
...

I display the page, and in one of the rolenam Textfields I change the value 
and submit the form.

I can put  breakpoint in "saveOriginal", and can see the getRole() call 
bringing in the value that the @For loop saved in a hidden field before its 
been updated from the form field.

I then continue on until the second listener and hit a breakpoint there. At 
this point, I would expect the getOriginal to return the same value that I 
set in the first listener.  But it doesn't - it also seems to have been 
updated from the form fields.

Am I missing something stupid here (I could imagine if the clone had not 
worked properly this wouldn't have worked) but in the Role constructor I do 
this ...

        public Role(Role r) {
                this.name = new String(r.name);
...

Or is the @For loop doing something strange?




-- 
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