You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Alan Chandler <al...@chandlerfamily.org.uk> on 2006/03/05 16:42:45 UTC

Unwinding unstored parameters?

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="rolenam@TextField" 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: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Unwinding unstored parameters?

Posted by Alan Chandler <al...@chandlerfamily.org.uk>.
On Sunday 05 March 2006 15:42, Alan Chandler wrote:

> Am I missing something stupid here

Yes - you have to save the file when you make an update.  If you don't it uses 
the old version (which didn't clone).

Seems to be working great now!
-- 
Alan Chandler
http://www.chandlerfamily.org.uk
Open Source. It's the difference between trust and antitrust.

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org