Maybe somebody can help me out here.

I am trying to get my head around the implications of the persistence and the combination with using volatile or not.

I have built a test page which contains a list of objects (for the sake of the example, each one only contains a string. A form is displayed with five items in it. You can change any of the items and commit. All very simple (the source follows).

If I do this using a non volatile loop, the changes in the textfield components are not persisted. When I make the loop volatile, they are.

I assume the persistence strategy has something to do with this, but I don't see the textfield state being saved (actually I also tried using the "client" persistence stratgey, but this just crashed the application).

It seems that when volatile is true, the objects from the list are unserialized from the form data, which makes them different from the objects in the page (which is just plain persisted), causing problems.

Can somebody shed some more light on this? If my assumption above is true, then the documentation for loop and grid need a lot more explanations when volatile should be either true or false.

Thanks,
Joachim

Test.tml
---------------------------------
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
<body>

   <h1>Submit test page</h1>
<p>Test page for the commit of strings inside a loop which are stored in embedded objects.</p>

   <t:form autofocus="false">

<input class="defaultSubmit" t:type="submit" value="Save" t:id="save"/>
       <br />

       <t:loop source="list" value="current" volatile="true">
<input t:type="TextField" maxlength="50" size="50" value="current.content" />
           <br />
       </t:loop>

   </t:form>

</body>
</html>
---------------------------------

Test.java
---------------------------------
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.equanda.example.t5.data.StringContainer;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

public class Test
{
   @Property
   @Persist
   private List<StringContainer> list;

   @Property
   private StringContainer current;

   void onActivate()
   {
       if ( null == list )
       {
           System.out.println( "initialise list" );
           list = new ArrayList<StringContainer>();
           list.add( new StringContainer( "Tapestry" ) );
           list.add( new StringContainer( "GWT" ) );
           list.add( new StringContainer( "Seam" ) );
           list.add( new StringContainer( "Wicket" ) );
           list.add( new StringContainer( "TIBCO GI" ) );
           list.add( new StringContainer( "JSF" ) );
       }
   }

   void onSubmit()
   {
       System.out.println( "onSubmit called, list="+list );
list.add( new StringContainer( Integer.toString( (int)System.currentTimeMillis() % 1000 ) ) );
   }
}
---------------------------------

StringContainer.java
---------------------------------
public class StringContainer
   implements Serializable
{
   private String content;

   public StringContainer() {}
   public StringContainer( String value ) { content = value; }

   public String getContent()
   {
       System.out.println( "Getting content " + content );
       return content;
   }

   public void setContent( String content )
   {
System.out.println( "Context set to " + content + "(was "+this.content+")");
       this.content = content;
   }

   @Override
   public String toString()
   {
       return content;
   }
}
---------------------------------

--
Joachim Van der Auwera
PROGS bvba, progs.be


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

Reply via email to