[prev in list] [next in list] [prev in thread] [next in thread] 

List:       tapestry-user
Subject:    Re: Components inside For component
From:       pipothebit <pipo_ex () yahoo ! es>
Date:       2006-10-31 6:50:24
Message-ID: 1162277424.5953.26.camel () localhost
[Download RAW message or body]

Hello all and very thnak you for your reply,
My level in this framework is beginer (and my english too, sorry).
I go to explain me a litle bit more concise.
I have a bean User that have a List of Rol object, in Java this is:

public class User {
  private List<Rol> rols = new ArrayList<Rol>();
....
}

With a For component I list all items in rols property, the code can be
like this:

<Page code>
public abstract class UserPage extends BasePage implements
PageBeginRenderListener {
@Persist
public abstract User getUser();
public abstract void setUser(User user);
....
}

<html code>
...
<tr jwcid="@For" source="ognl:user.rols" value="ognl:rol" element="tr"
index="ognl:index">
<td>
  <select jwcid="@PropertySelection" model="ognl:RolsModel"
value="ognl:rol">
  </select>
</td>
<td>
  <a href="#" jwcid="@DirectLink" listener="listener:delRolAction"
parameters="ognl:{index}">del</a>
</td>
</tr>
....

With this code I try to set every element of Rol List with the
PropertySelect component but this state is not saved, I add and delete
items from Rol list but every time I make a submit (to add items, delete
items or make the page submit to save the data) the List have all items
that I have add but all are without state (default constructor values).

Perhaps I have forgot something, I don't know what but I understand that
user property is persistent and Rol list too (is part of the User class)
and RolsModel returns Rols object to set the state but this not work.

What can I do?

Very Thank You.

P.D. Perhaps palette component is better option but at this point of
learning this framework I need to understand all posibilities but Very
Thank You Jesse Kuhnert, it is a good advice.





El lun, 30-10-2006 a las 22:41 +0100, Christian Haselbach escribió:
> On Mon, Oct 30, 2006 at 08:46:41PM +0000, pipothebit wrote:
> > I add rols and delete (throught index property of For component) but my
> > rol values are not set during post, and when i go to save it to database
> > all items of rols List are empty (state is not saved).
> 
> I do not really understand what you are doing, but there are different
> ways to manipulate state according to elements in a For loop.
> 
> Assuming you render something like a button for each element, you
> could use the current value (assigned via value) or the index
> (assigned via index parameter) to associate the rendered button
> with the element, so you know for which element the button has been
> pressed.
> 
> Another way, if things are more complicated, is to use hand tailored
> setters and getters which take into account what the current element
> in the loop is, backed by a persisted property.
> 
> Lets say you have a property elementChecked (a set) and iterate
> with the For component over elements:
> <span jwcid="@For" source="ognl:elements" value="ognl:element">
> ...
> </span>
> 
> In this component you have a checkbox accessing a property elementCheck.
> For this property define the getter and setter as follows:
> public boolean isElementCheck() {
>    this.getElementChecked().contains(getElement());
> }
> public void setElementCheck(boolean checked);
>   if (checked) {
>     this.getElementChecked().add(getElement());
>   } else {
>     this.getElementChecked().remove(getElement());
>   }
> }
> 
> Well, elementChecked does not need to be persistent, if you do not need
> it after the rewind.
> 
> Regards,
> Christian
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


		
______________________________________________ 
LLama Gratis a cualquier PC del Mundo. 
Llamadas a fijos y móviles desde 1 céntimo por minuto. 
http://es.voice.yahoo.com

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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic