You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Ron van de Ven <Ro...@mp-objects.com> on 2005/06/16 10:51:57 UTC

[Cforms] Java Selection List

Hi (Sylvain),
 
I have to set a selection list on a field, based on success or failure of a
validation.
 
When I use the following fragment:
 
  TntCformsJavaSelectionList mySelectionList = new
TntCformsJavaSelectionList(true);
  mySelectionList.setDatatype(new StringType());
  myField.setSelectionList(mySelectionList);
 
I get an error: Tried to assign a SelectionList that is not associated with
this widget's datatype.
 
The fragment responsible for this Exception: 
 
 public void setSelectionList(SelectionList selectionList) {
        if (selectionList != null &&
            selectionList.getDatatype() != null &&
            selectionList.getDatatype() != getDatatype()) {
            throw new RuntimeException("Tried to assign a SelectionList that
is not associated with this widget's datatype.");
        }
 
 
The problem is, that this tests for java reference equality. 
 
Could you maybe implement an equals() method in the Datatype subclasses, and
test for equality?
like:
selectionList.getDataType().equals(getDatatTypeI())
 
Regards,    Ron
 
PS If you think this is a good idea, I can do it myself.
PPS Keep up the good work on Cforms. I'm love it!

             

RE: [Cforms] Java Selection List

Posted by Ron van de Ven <Ro...@mp-objects.com>.
Hi Bruno,

Your last suggestion resembles how I basically have overwritten the
setSelectionListBox(SelectionList) method in the Field.java source.
However, I have to admit that for my problem, your first solution would have
been a lot easier!

Thanx,

Ron

 

-----Original Message-----
From: Bruno Dumon [mailto:bruno@outerthought.org] 
Sent: Thursday, June 16, 2005 8:33 PM
To: dev@cocoon.apache.org
Subject: Re: [Cforms] Java Selection List

On Thu, 2005-06-16 at 11:05 -0400, Vadim Gritsenko wrote:
> Bruno Dumon wrote:
> > On Thu, 2005-06-16 at 10:51 +0200, Ron van de Ven wrote:
> > 
> >>I have to set a selection list on a field, based on success or 
> >>failure of a validation.
> >> 
> >>When I use the following fragment:
> >> 
> >>  TntCformsJavaSelectionList mySelectionList = new 
> >>TntCformsJavaSelectionList(true);
> >>  mySelectionList.setDatatype(new StringType());
> >>  myField.setSelectionList(mySelectionList);
> >> 
> >>I get an error: Tried to assign a SelectionList that is not 
> >>associated with this widget's datatype.
> > 
> > 
> > then why not do:
> > 
> > mySelectionList.setDatatype(myField.getDatatype());
> > 
> > ?
> 
> I think I had similar situation, with this answer to the question 
> above: you may want to share potentially large selection list(s) 
> between multiple widgets, here widgets might be on the same form, or even
on multiple forms for multiple users.
> It could be quite substantial memory savings... In this scenario, you 
> need either multiple widgets have same instance of datatype on 
> multiple widgets (is it even possible?), or use equals() instead of '=='
as was suggested.

I see. But is it feasible to implement equals? Testing the equality of a
datatype includes testing the equality of its contained convertor, which
could be configurable in all sorts of ways.

Another possibility would be to change the contract of the SelectionList,
letting the field pass its datatype (or even just its
convertor) to the SelectionList.generateSaxFragment method. To check the
type-compatibility, a SelectionList.getTypeClass() method could be added
(cfr. Datatype.getTypeClass()).

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org



Re: [Cforms] Java Selection List

Posted by Bruno Dumon <br...@outerthought.org>.
On Thu, 2005-06-16 at 11:05 -0400, Vadim Gritsenko wrote:
> Bruno Dumon wrote:
> > On Thu, 2005-06-16 at 10:51 +0200, Ron van de Ven wrote:
> > 
> >>I have to set a selection list on a field, based on success or failure
> >>of a validation.
> >> 
> >>When I use the following fragment:
> >> 
> >>  TntCformsJavaSelectionList mySelectionList = new
> >>TntCformsJavaSelectionList(true);
> >>  mySelectionList.setDatatype(new StringType());
> >>  myField.setSelectionList(mySelectionList);
> >> 
> >>I get an error: Tried to assign a SelectionList that is not associated
> >>with this widget's datatype.
> > 
> > 
> > then why not do:
> > 
> > mySelectionList.setDatatype(myField.getDatatype());
> > 
> > ?
> 
> I think I had similar situation, with this answer to the question above: you may 
> want to share potentially large selection list(s) between multiple widgets, here 
> widgets might be on the same form, or even on multiple forms for multiple users. 
> It could be quite substantial memory savings... In this scenario, you need 
> either multiple widgets have same instance of datatype on multiple widgets (is 
> it even possible?), or use equals() instead of '==' as was suggested.

I see. But is it feasible to implement equals? Testing the equality of a
datatype includes testing the equality of its contained convertor, which
could be configurable in all sorts of ways.

Another possibility would be to change the contract of the
SelectionList, letting the field pass its datatype (or even just its
convertor) to the SelectionList.generateSaxFragment method. To check the
type-compatibility, a SelectionList.getTypeClass() method could be added
(cfr. Datatype.getTypeClass()).

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Re: [Cforms] Java Selection List

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Bruno Dumon wrote:
> On Thu, 2005-06-16 at 10:51 +0200, Ron van de Ven wrote:
> 
>>I have to set a selection list on a field, based on success or failure
>>of a validation.
>> 
>>When I use the following fragment:
>> 
>>  TntCformsJavaSelectionList mySelectionList = new
>>TntCformsJavaSelectionList(true);
>>  mySelectionList.setDatatype(new StringType());
>>  myField.setSelectionList(mySelectionList);
>> 
>>I get an error: Tried to assign a SelectionList that is not associated
>>with this widget's datatype.
> 
> 
> then why not do:
> 
> mySelectionList.setDatatype(myField.getDatatype());
> 
> ?

I think I had similar situation, with this answer to the question above: you may 
want to share potentially large selection list(s) between multiple widgets, here 
widgets might be on the same form, or even on multiple forms for multiple users. 
It could be quite substantial memory savings... In this scenario, you need 
either multiple widgets have same instance of datatype on multiple widgets (is 
it even possible?), or use equals() instead of '==' as was suggested.

Vadim

Re: [Cforms] Java Selection List

Posted by Bruno Dumon <br...@outerthought.org>.
On Thu, 2005-06-16 at 10:51 +0200, Ron van de Ven wrote:
> Hi (Sylvain),
>  
> I have to set a selection list on a field, based on success or failure
> of a validation.
>  
> When I use the following fragment:
>  
>   TntCformsJavaSelectionList mySelectionList = new
> TntCformsJavaSelectionList(true);
>   mySelectionList.setDatatype(new StringType());
>   myField.setSelectionList(mySelectionList);
>  
> I get an error: Tried to assign a SelectionList that is not associated
> with this widget's datatype.
<snip/>

then why not do:

mySelectionList.setDatatype(myField.getDatatype());

?

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org