You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael Engelhart <me...@mac.com> on 2004/12/06 15:52:45 UTC
Re: primitive conversion [SOLVED]
Over the weekend I found that by creating my own PropertySelection
model which I called IntegerPropertySelectionModel which is as follows
in case anyone else needs this in the future.
Mike
******************* IntegerPropertySelectionModel.java
***************************
import org.apache.tapestry.form.IPropertySelectionModel;
public class IntegerPropertySelectionModel implements
IPropertySelectionModel {
public IntegerPropertySelectionModel(Integer[] options) {
this.options = options;
}
public int getOptionCount() {
return options.length;
}
public Object getOption(int index) {
return options[index];
}
public String getLabel(int index) {
return String.valueOf(options[index]);
}
public String getValue(int index) {
return String.valueOf(index);
}
public Object translateValue(String value) {
int index;
index = Integer.parseInt(value);
return options[index];
}
private Integer[] options;
}
On Dec 4, 2004, at 10:07 AM, Michael Engelhart wrote:
> I have a question about primitives. I've seen various posts but still
> don't really understand what's going on. I have a domain object
> that has a field
> private int numberOfAdults;
>
> that I set using a StringPropertySelectionModel component and while
> debugging I note that my domain object is updated correctly by logging
> the value during pageBeginRender/pageEndRender, but if I redisplay to
> show an validation error for example the drop-down
> StringPropertySelectionModel itself isn't getting updated correctly -
> it always is rendered with no items selected.
>
> So to test I created a field in my domain object as a String instead
> of an int
> private String numberOfAdultsString;
>
> and changed my component to use that value and everything worked
> perfectly.
>
> What's the correct approach to this. Am i supposed to modify my
> domain objects to support tapestry (guessing this would be very
> unlikely) or create a custom PropertySelection (this doesn't seem
> correct since IPropertySelectionModel requires that you return Object
> in the getOption() method) or something else?
>
> Any help would be appreciated.
>
> Thanks
> Mike
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org