You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Tim Sawyer <li...@calidris.co.uk> on 2008/04/03 11:09:09 UTC

T5 Checkbox Problem

Hi Folks,

I have a list of checkboxes on a page:

        <tr t:type="Loop" source="displayActorList" value="actor">
          <td><t:checkbox t:value="actor.enabled"/></td>
          <td>${actor.name}</td>
        </tr>

The method to return the displayActorList is 

  public List<Actor> getDisplayActorList()
  {
    if (this.getActorList() == null)
    {
      this.setActorList(this.getStoredActorList());
    }

    return this.getActorList();
  }

where actor list is persistant.

  @Persist private List<Actor> actorList;

The problem I'm having is that after submitting the page with my checkbox list 
in, the actor list is not being updated with the new values.  Can anyone 
suggest what I could be doing wrong?

Thanks,

Tim.

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


Re: T5 Checkbox Problem

Posted by shelly <lo...@gmail.com>.
Hi,

I had the same problem and then I've tried changing the code using your
solution.

But the solution won't work for the last row of the list.
So when I change the value of the enabled (checkbox) in last row, the record
won't change?
This problem didn't happen for other previous rows.

why could it be?

thanks,
shelly


When form submission occurs Tapestry5 do not look at binding that was 
used during render phase. Instead it use ValueEncoder to restore object 
from String id. If you do not provide an ValueEncoder (I think you 
don't, do you?) tapestry will use default. Default ValueEncoder use java 
serialization mechanism for conversion from and to object. So when your 
form is submitted _new_ objects are deserialized from serialization 
data. Those object are not the same objects as in actorList (equals will 
return true, but == will return false).

To solve the problem you need to provide your own ValueEncoder. 
Something similar to follow.

        <tr t:type="Loop" source="displayActorList" value="actor"
encoder="encoder">
          <td><t:checkbox t:value="actor.enabled"/></td>
          <td>${actor.name}</td>
        </tr>

public ValueEncoder getEncoder() {
return new ValueEncoder() {
public String toClient(Object value) {
// TODO: indexOf is not very effective operation
return String.valueOf(getDisplayActorList().indexOf(value));
}

public Object toValue(String clientValue) {
return getDisplayActorList().get(Integer.parseInt(clientValue));
}
};
}

With code above you do not ever need to persist actorList, because it is 
restored from getStoredActorList every request.

Tim Sawyer пишет:
> Hi Folks,
>
> I have a list of checkboxes on a page:

-- 
View this message in context: http://www.nabble.com/T5-Checkbox-Problem-tp16470624p16698258.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5 Checkbox Problem

Posted by Dmitry Shyshkin <sh...@devoler.com>.
When form submission occurs Tapestry5 do not look at binding that was 
used during render phase. Instead it use ValueEncoder to restore object 
from String id. If you do not provide an ValueEncoder (I think you 
don't, do you?) tapestry will use default. Default ValueEncoder use java 
serialization mechanism for conversion from and to object. So when your 
form is submitted _new_ objects are deserialized from serialization 
data. Those object are not the same objects as in actorList (equals will 
return true, but == will return false).

To solve the problem you need to provide your own ValueEncoder. 
Something similar to follow.

        <tr t:type="Loop" source="displayActorList" value="actor" encoder="encoder">
          <td><t:checkbox t:value="actor.enabled"/></td>
          <td>${actor.name}</td>
        </tr>

public ValueEncoder getEncoder() {
return new ValueEncoder() {
public String toClient(Object value) {
// TODO: indexOf is not very effective operation
return String.valueOf(getDisplayActorList().indexOf(value));
}

public Object toValue(String clientValue) {
return getDisplayActorList().get(Integer.parseInt(clientValue));
}
};
}

With code above you do not ever need to persist actorList, because it is 
restored from getStoredActorList every request.

Tim Sawyer пишет:
> Hi Folks,
>
> I have a list of checkboxes on a page:
>
>         <tr t:type="Loop" source="displayActorList" value="actor">
>           <td><t:checkbox t:value="actor.enabled"/></td>
>           <td>${actor.name}</td>
>         </tr>
>
> The method to return the displayActorList is 
>
>   public List<Actor> getDisplayActorList()
>   {
>     if (this.getActorList() == null)
>     {
>       this.setActorList(this.getStoredActorList());
>     }
>
>     return this.getActorList();
>   }
>
> where actor list is persistant.
>
>   @Persist private List<Actor> actorList;
>
> The problem I'm having is that after submitting the page with my checkbox list 
> in, the actor list is not being updated with the new values.  Can anyone 
> suggest what I could be doing wrong?
>
> Thanks,
>
> Tim.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
>   


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