Hello,

I'm trying to update a selection model based on a prior selection, using
AJAX
and Tapestry 4.1.1.

I've built a small test case, connecting an EventListener to the onchange
event
of a PropertySelection. You can find it at the end of this mail.

In the test, the EventListener is properly called (when the value of the
PropertySelection is changed), but the selections are not updated. When
called
from Test.onChange(), Test.getA() returns 'null' instead of the selected
value.

Somebody knows what should I write in the EventListener to get the
selected value?.

Thank you very much, best regards.



Test.page:
----------
<?xml version="1.0"?>
<!DOCTYPE page-specification PUBLIC
       "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
       "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";>

<page-specification
   class="net.nt.web.pages.Test"
>
</page-specification>


Test.html:
----------
<html jwcid="@Shell" title="Test"
       delegate="ognl:new
org.apache.tapestry.components.BlockRenderer(components.remainingHead)"
       renderBaseTag="ognl:false">
<head jwcid="[EMAIL PROTECTED]">
</head>
<body jwcid="@Body">
       <form jwcid="[EMAIL PROTECTED]">
           <span jwcid="[EMAIL PROTECTED]" model="ognl:modelA"
value="ognl:a" />
               <span jwcid="[EMAIL PROTECTED]" model="ognl:modelB"
value="ognl:b" />
       </form>
</body>
</html>


Test.java:
----------

package net.nt.web.pages;

import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.annotations.EventListener;
import org.apache.tapestry.event.BrowserEvent;
import org.apache.tapestry.event.PageBeginRenderListener;
import org.apache.tapestry.event.PageEvent;
import org.apache.tapestry.form.IPropertySelectionModel;
import org.apache.tapestry.form.StringPropertySelectionModel;
import org.apache.tapestry.html.BasePage;


public abstract class Prueba extends BasePage
                                                       implements
 PageBeginRenderListener {
       public abstract String  getA();
       public abstract void    setA(String selected);

       public abstract String  getB();
       public abstract void    setB(String selected);

       public abstract void setModelB(IPropertySelectionModel modelB);
       public abstract IPropertySelectionModel getModelB();

       public IPropertySelectionModel getModelA() {
               return new StringPropertySelectionModel(new String[] {
"Letters",
                               "Numbers", "Colors" });
       }

       @SuppressWarnings("unchecked")
       public void pageBeginRender(PageEvent event) {
               if (getA() == null) {
                       //set it's inital value to the first value available
in the drop down.
                       System.out.println("Setting A to a default
value...");
                       setA("Letters");
                       setModelB(new StringPropertySelectionModel(new
String[] { "A", "B",
                                       "C", "D", "E" }));
               }
       }

       @EventListener(targets = "A", events = "onchange")
       public void onChange(IRequestCycle cycle, BrowserEvent event) {
               System.out.println("changeA()");

               String selectionA = getA();

               if (selectionA.equals("Letters")) {
                       setModelB(new StringPropertySelectionModel(new
String[] { "A", "B",
                                       "C", "D", "E" }));
               } else if (selectionA.equals("Numbers")) {
                       setModelB(new StringPropertySelectionModel(new
String[] { "1", "2",
                                       "3", "4", "5", "6" }));
               } else {
                       setModelB(new StringPropertySelectionModel(new
String[] { "Red",
                                       "Blue", "Green", "Cyan", "Magenta",
"Yellow" }));
               }

               cycle.getResponseBuilder().updateComponent("B");
       }

}

Reply via email to