You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jabbar <aj...@gmail.com> on 2006/10/14 00:14:34 UTC

Propertyselection model not working during render cycle

Hello,
My page contains a persistent byte property which is used as the value
in Property Selection.
The persistent value is assigned inside pageBeginRender. During
debugging I can see the property being assigned a value other then
one. After the render the property selection always shows the first
item as being selected. I've spent hours looking at this. Can anybody
provide any clues?

Page class extract

@Persist
public abstract byte getLoggingRate();
public abstract void setLoggingRate(byte b);

public LoggingRateSelectionModel getLoggingRateSelectionModel(){
       return new LoggingRateSelectionModel();
}

public void pageBeginRender(PageEvent pageEvent){


      if (!pageEvent.getRequestCycle().isRewinding()){

// if doing a render and the channel list is empty then obtain a new
channel list and persist.
if ((getChannelSetup()==null)||(getChannelSetup().size()==0)){
     try {
          refreshCelloPagesSettings();
      } catch (Exception e) {
	e.printStackTrace();
				}

      }
			System.out.println("rendering");
		} else {
			System.out.println("rewinding");
		}
	}


public void refreshCelloPagesSettings(){
Cello6 cello6=null;
   try {
     cello6 = getCello6DAO().get(getCelloSerialNumber());
    } catch (SQLException e1) {
        e1.printStackTrace();
     } catch (Exception e1) {
        e1.printStackTrace();
     }

    if (cello6==null) return;

    setChannelSetup(getCello6DAO().getChannelSetup(getCelloSerialNumber()));
    setBatteryAlarm(getCello6().isBatteryAlarm());
    byte rate = (byte)cello6.getLoggingRate();
    setLoggingRate(rate);
}

page.page file
<component id="loggingRate" type="PropertySelection">
    <binding name="model" value="loggingRateSelectionModel"/>
    <binding name="value" value="loggingRate"/>
</component>

page.html file

<table>

							
<tr><td class="Cello6DetailsChannelPropertyTitle" nowrap>Logging Rate</td>
    <td class="Cello6DetailsChannelPropertyValue"><input
jwcid="loggingRate" type="text"/></td>
</tr>
<tr><td colspan="4">
	<input type="Submit" value="Update" jwcid="@Submit"
action="listener:doUpdateChannelDataAndInfo"
ognl:!updateChannelDataAndInfo"/> &nbsp; <div class="warning"
jwcid="@Insert" value="ognl:dataMessage"/></td>
</tr>
						
propertyselection model	 source
public class LoggingRateSelectionModel implements IPropertySelectionModel {

                public static Map<String, Short> rate = new
LinkedHashMap<String, Short>();

	static {
		rate.put("1 minute", (short)1);
		rate.put("2 minutes", (short)2);
		rate.put("3 minutes",(short)3);
		rate.put("4 minutes",(short)4);
		rate.put("5 minutes", (short)5);
		rate.put("6 minutes", (short)6);
		rate.put("10 minutes", (short)10);
		rate.put("12 minutes", (short)12);
		rate.put("15 minutes", (short)15);
		rate.put("20 minutes", (short)20);
		rate.put("30 minutes", (short)30);
		rate.put("1 hour", (short)60);
	}

	public int getOptionCount() {
		return rate.size();
	}

	public Object getOption(int index) {
		Short[] values = rate.values().toArray(new Short[0]);

		return values[index];
	}

	public String getLabel(int index) {
		String[] keys = rate.keySet().toArray(new String[0]);
		return keys[index];
	}

	public String getValue(int index) {
		return Integer.toString(index);
	}

	public Object translateValue(String value) {
		Short[] values = rate.values().toArray(new Short[0]);
		return new Short(values[Integer.parseInt(value)]);
	}

}

-- 
Thanks

 A Jabbar Azam

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


Re: Propertyselection model not working during render cycle

Posted by Karthik N <ka...@gmail.com>.
you're not the only one - it takes time to get a hang of PropSelModel - but
once the functionality of PropSel is clear, it's a breeze.

by the way - HL Ship's tapestry in action has a really nice explanation of
PropSel - worth a read.

all the best.

On 10/14/06, Jabbar <aj...@gmail.com> wrote:
>
> Karthik,
>
> Thank you very much for that. It's fixed the problem. I had spent many
> hours on this but couldn't see the problem!
>
>
>

Re: Propertyselection model not working during render cycle

Posted by Jabbar <aj...@gmail.com>.
Karthik,

Thank you very much for that. It's fixed the problem. I had spent many
hours on this but couldn't see the problem!


On 14/10/06, Karthik N <ka...@gmail.com> wrote:
> jabbar,
>
> without looking too deep into your code, the reason why the 1st value is
> getting selected is because you've not got any value in the PropSelection
> that equals loggingRate.
>
> i'd suggest two things
>
> 1. put some SOPs in your property selection model methods - especially
> translateValue to print the value and the returns object
>
> 2. Ensure that the value returned by translateValue .equals() the value of
> getLoggingRate() - this could most likely be the bug.  No value returned
> from the prop selection is considered equal to the loggingRate.
>
>
>
>
> On 10/14/06, Jabbar <aj...@gmail.com> wrote:
> >
> > Hello,
> > My page contains a persistent byte property which is used as the value
> > in Property Selection.
> > The persistent value is assigned inside pageBeginRender. During
> > debugging I can see the property being assigned a value other then
> > one. After the render the property selection always shows the first
> > item as being selected. I've spent hours looking at this. Can anybody
> > provide any clues?
> >
> > Page class extract
> >
> > @Persist
> > public abstract byte getLoggingRate();
> > public abstract void setLoggingRate(byte b);
> >
> > public LoggingRateSelectionModel getLoggingRateSelectionModel(){
> >        return new LoggingRateSelectionModel();
> > }
> >
> > public void pageBeginRender(PageEvent pageEvent){
> >
> >
> >       if (!pageEvent.getRequestCycle().isRewinding()){
> >
> > // if doing a render and the channel list is empty then obtain a new
> > channel list and persist.
> > if ((getChannelSetup()==null)||(getChannelSetup().size()==0)){
> >      try {
> >           refreshCelloPagesSettings();
> >       } catch (Exception e) {
> >         e.printStackTrace();
> >                                 }
> >
> >       }
> >                         System.out.println("rendering");
> >                 } else {
> >                         System.out.println("rewinding");
> >                 }
> >         }
> >
> >
> > public void refreshCelloPagesSettings(){
> > Cello6 cello6=null;
> >    try {
> >      cello6 = getCello6DAO().get(getCelloSerialNumber());
> >     } catch (SQLException e1) {
> >         e1.printStackTrace();
> >      } catch (Exception e1) {
> >         e1.printStackTrace();
> >      }
> >
> >     if (cello6==null) return;
> >
> >
> >     setChannelSetup(getCello6DAO().getChannelSetup(getCelloSerialNumber()));
> >     setBatteryAlarm(getCello6().isBatteryAlarm());
> >     byte rate = (byte)cello6.getLoggingRate();
> >     setLoggingRate(rate);
> > }
> >
> > page.page file
> > <component id="loggingRate" type="PropertySelection">
> >     <binding name="model" value="loggingRateSelectionModel"/>
> >     <binding name="value" value="loggingRate"/>
> > </component>
> >
> > page.html file
> >
> > <table>
> >
> >
> > <tr><td class="Cello6DetailsChannelPropertyTitle" nowrap>Logging Rate</td>
> >     <td class="Cello6DetailsChannelPropertyValue"><input
> > jwcid="loggingRate" type="text"/></td>
> > </tr>
> > <tr><td colspan="4">
> >         <input type="Submit" value="Update" jwcid="@Submit"
> > action="listener:doUpdateChannelDataAndInfo"
> > ognl:!updateChannelDataAndInfo"/> &nbsp; <div class="warning"
> > jwcid="@Insert" value="ognl:dataMessage"/></td>
> > </tr>
> >
> > propertyselection model  source
> > public class LoggingRateSelectionModel implements IPropertySelectionModel
> > {
> >
> >                 public static Map<String, Short> rate = new
> > LinkedHashMap<String, Short>();
> >
> >         static {
> >                 rate.put("1 minute", (short)1);
> >                 rate.put("2 minutes", (short)2);
> >                 rate.put("3 minutes",(short)3);
> >                 rate.put("4 minutes",(short)4);
> >                 rate.put("5 minutes", (short)5);
> >                 rate.put("6 minutes", (short)6);
> >                 rate.put("10 minutes", (short)10);
> >                 rate.put("12 minutes", (short)12);
> >                 rate.put("15 minutes", (short)15);
> >                 rate.put("20 minutes", (short)20);
> >                 rate.put("30 minutes", (short)30);
> >                 rate.put("1 hour", (short)60);
> >         }
> >
> >         public int getOptionCount() {
> >                 return rate.size();
> >         }
> >
> >         public Object getOption(int index) {
> >                 Short[] values = rate.values().toArray(new Short[0]);
> >
> >                 return values[index];
> >         }
> >
> >         public String getLabel(int index) {
> >                 String[] keys = rate.keySet().toArray(new String[0]);
> >                 return keys[index];
> >         }
> >
> >         public String getValue(int index) {
> >                 return Integer.toString(index);
> >         }
> >
> >         public Object translateValue(String value) {
> >                 Short[] values = rate.values().toArray(new Short[0]);
> >                 return new Short(values[Integer.parseInt(value)]);
> >         }
> >
> > }
> >
> > --
> > Thanks
> >
> > A Jabbar Azam
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
> --
> Thanks, Karthik
>
>


-- 
Thanks

 A Jabbar Azam

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


Re: Propertyselection model not working during render cycle

Posted by Karthik N <ka...@gmail.com>.
jabbar,

without looking too deep into your code, the reason why the 1st value is
getting selected is because you've not got any value in the PropSelection
that equals loggingRate.

i'd suggest two things

1. put some SOPs in your property selection model methods - especially
translateValue to print the value and the returns object

2. Ensure that the value returned by translateValue .equals() the value of
getLoggingRate() - this could most likely be the bug.  No value returned
from the prop selection is considered equal to the loggingRate.




On 10/14/06, Jabbar <aj...@gmail.com> wrote:
>
> Hello,
> My page contains a persistent byte property which is used as the value
> in Property Selection.
> The persistent value is assigned inside pageBeginRender. During
> debugging I can see the property being assigned a value other then
> one. After the render the property selection always shows the first
> item as being selected. I've spent hours looking at this. Can anybody
> provide any clues?
>
> Page class extract
>
> @Persist
> public abstract byte getLoggingRate();
> public abstract void setLoggingRate(byte b);
>
> public LoggingRateSelectionModel getLoggingRateSelectionModel(){
>        return new LoggingRateSelectionModel();
> }
>
> public void pageBeginRender(PageEvent pageEvent){
>
>
>       if (!pageEvent.getRequestCycle().isRewinding()){
>
> // if doing a render and the channel list is empty then obtain a new
> channel list and persist.
> if ((getChannelSetup()==null)||(getChannelSetup().size()==0)){
>      try {
>           refreshCelloPagesSettings();
>       } catch (Exception e) {
>         e.printStackTrace();
>                                 }
>
>       }
>                         System.out.println("rendering");
>                 } else {
>                         System.out.println("rewinding");
>                 }
>         }
>
>
> public void refreshCelloPagesSettings(){
> Cello6 cello6=null;
>    try {
>      cello6 = getCello6DAO().get(getCelloSerialNumber());
>     } catch (SQLException e1) {
>         e1.printStackTrace();
>      } catch (Exception e1) {
>         e1.printStackTrace();
>      }
>
>     if (cello6==null) return;
>
>
>     setChannelSetup(getCello6DAO().getChannelSetup(getCelloSerialNumber()));
>     setBatteryAlarm(getCello6().isBatteryAlarm());
>     byte rate = (byte)cello6.getLoggingRate();
>     setLoggingRate(rate);
> }
>
> page.page file
> <component id="loggingRate" type="PropertySelection">
>     <binding name="model" value="loggingRateSelectionModel"/>
>     <binding name="value" value="loggingRate"/>
> </component>
>
> page.html file
>
> <table>
>
>
> <tr><td class="Cello6DetailsChannelPropertyTitle" nowrap>Logging Rate</td>
>     <td class="Cello6DetailsChannelPropertyValue"><input
> jwcid="loggingRate" type="text"/></td>
> </tr>
> <tr><td colspan="4">
>         <input type="Submit" value="Update" jwcid="@Submit"
> action="listener:doUpdateChannelDataAndInfo"
> ognl:!updateChannelDataAndInfo"/> &nbsp; <div class="warning"
> jwcid="@Insert" value="ognl:dataMessage"/></td>
> </tr>
>
> propertyselection model  source
> public class LoggingRateSelectionModel implements IPropertySelectionModel
> {
>
>                 public static Map<String, Short> rate = new
> LinkedHashMap<String, Short>();
>
>         static {
>                 rate.put("1 minute", (short)1);
>                 rate.put("2 minutes", (short)2);
>                 rate.put("3 minutes",(short)3);
>                 rate.put("4 minutes",(short)4);
>                 rate.put("5 minutes", (short)5);
>                 rate.put("6 minutes", (short)6);
>                 rate.put("10 minutes", (short)10);
>                 rate.put("12 minutes", (short)12);
>                 rate.put("15 minutes", (short)15);
>                 rate.put("20 minutes", (short)20);
>                 rate.put("30 minutes", (short)30);
>                 rate.put("1 hour", (short)60);
>         }
>
>         public int getOptionCount() {
>                 return rate.size();
>         }
>
>         public Object getOption(int index) {
>                 Short[] values = rate.values().toArray(new Short[0]);
>
>                 return values[index];
>         }
>
>         public String getLabel(int index) {
>                 String[] keys = rate.keySet().toArray(new String[0]);
>                 return keys[index];
>         }
>
>         public String getValue(int index) {
>                 return Integer.toString(index);
>         }
>
>         public Object translateValue(String value) {
>                 Short[] values = rate.values().toArray(new Short[0]);
>                 return new Short(values[Integer.parseInt(value)]);
>         }
>
> }
>
> --
> Thanks
>
> A Jabbar Azam
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Thanks, Karthik