You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Joerg Heinicke <jo...@gmx.de> on 2004/03/10 16:29:28 UTC

[cforms] selection list binding

Hello,

below you will find the mail I wanted to send first, but after having written it
I found the solution myself:
I thought about the correct event instead of on-value-changed, I came to on-bind
and in the binding docu I found wb:javascript and came to following code that
nearly satisfies me:

<wb:javascript id="filter.object" path="objects" direction="load">
  <wb:load-form>
    var objects = jxpathPointer.getNode();
    widget.setSelectionList(objects, "id", "name")
  </wb:load-form>
</wb:javascript>

The question is just if this could be added with a "real" element in the wb
namespace, e.g. wb:list and the path has to point to a collection.

And another question related to this: I want to add a first item to the
selection list with an empty value meaning nothing is filtered due to this
field. But when using setSelectionList() this item is replaced and I found no
addSelectionList that does an addCollection(coll) on the java.util.Collection
level. Any suggestions for this?

Joerg

================================================================================

Hello,

as you might already know I'm using the CForms framework for my recent project.
At the moment I'm at a point where the options that I have and know about don't
satisfy me. It's about dynamic selection lists. I know two possibilities:
@src="uri" in form definition and setSelectionlist(obj, str, str) in flow. Both
need a not so straight handling. @src="uri" needs a complete separate call back
to the backend. And also with flow it's more complicated then maybe necessary.

The pages are for searching different types of objects and different types of
objects also need different types of filters. But until now I also have only one
flow function for all the object list display pages. I don't want to add form
specific code into the generic flow function. So I don't want to add form
specific setSelectionlist() calls into it.

I have the filter values in a filter object to which I do the binding. It would
be no problem to also put the collection for the selection list into it, but to
set the selection list on the widget. As I would need flow to get the collection
from the filter object and set it by hand (the form specific part would need to
know about the widget to set the selection list and the path in the bean).

I really wonder why this is not directly doable by the binding - or is it?

I also saw the country selector sample, which shows a nice solution for the form
specific flow, but there the selection list is set on-value-changed. I want to
set it always, independent of any event.

Hope this mail was not to irritating :)

Joerg


Re: [cforms] selection list binding

Posted by Joerg Heinicke <jo...@gmx.de>.
Ugo Cei <u.cei <at> cbim.it> writes:

> > Do you have a solution for the 'non-value' entry in the items collection? I
> > use the selection list as filter for the list pages. And I want to provide an
> > option to do no filtering by this selection list.
> 
> I usually do the following:
> 
> 	var collection = getSomeCollection(); // Typically from a DB
> 	collection.add(0, null);

Nice one, thanks. JavaScript seems to ignore the Collection interface and goes
straight forward to my Collection implementation in use, the ArrayList.

Joerg


Re: [cforms] selection list binding

Posted by Ugo Cei <u....@cbim.it>.
Joerg Heinicke wrote:
> Do you have a solution for the 'non-value' entry in the items collection? I use
> the selection list as filter for the list pages. And I want to provide an option
> to do no filtering by this selection list.

I usually do the following:

	var collection = getSomeCollection(); // Typically from a DB
	collection.add(0, null);


		Ugo



Re: [cforms] selection list binding

Posted by Joerg Heinicke <jo...@gmx.de>.
Ugo Cei <u.cei <at> cbim.it> writes:

> > Ok, let me clarify. I think I do nothing unusual. Yes, I have a form 
> > with a simple dynamic selection list. And I do the binding against a bean.
> 
> This is what I do all the time.

I thought so too :)

> > There are two known ways to set the selection list dynamically: 
> > setSelectionList(String uri) and setSelectionList(Object model, String 
> > valuePath, String labelPath). The first one is for the  <at> src, the latter 
> > one for setting the selection list from flow (and using 
> > FlowJXPathSelectionList internally).
> > 
> > As I do not want to go back to sitemap I chose the latter one, remains 
> > only the question where to use it. 
> 
> var items = // some collection ...
> form.showForm("uri", { "items" : items });
> 
> <wd:field>
> ...
>    <wd:selection-list type="flow-jxpath" list-path="items"
>      value-path="value" label-path="label"/>
> ...
> </wd:field>

Ah, thanks, I did not know that it is possible this way. This would move it out
of the binding into the definition with usage of the business data object.

Only the flow script is "polluted" by "items" handling:
I have a displayList() function handling all list forms, some need a selection
list, other not, other two.

> > I hope this time it was written more straight forward and not that much 
> > irritating.
> 
> Don't worry, it's not you that are irritating, it's really me that's 
> being obtuse . And please excuse me if I still don't get what your 
> aiming for.

:-)

Do you have a solution for the 'non-value' entry in the items collection? I use
the selection list as filter for the list pages. And I want to provide an option
to do no filtering by this selection list.

Thanks,

Joerg


Re: [cforms] selection list binding

Posted by Ugo Cei <u....@cbim.it>.
Joerg Heinicke wrote:
> Ok, let me clarify. I think I do nothing unusual. Yes, I have a form 
> with a simple dynamic selection list. And I do the binding against a bean.

This is what I do all the time.

> There are two known ways to set the selection list dynamically: 
> setSelectionList(String uri) and setSelectionList(Object model, String 
> valuePath, String labelPath). The first one is for the @src, the latter 
> one for setting the selection list from flow (and using 
> FlowJXPathSelectionList internally).
> 
> As I do not want to go back to sitemap I chose the latter one, remains 
> only the question where to use it. 

var items = // some collection ...
form.showForm("uri", { "items" : items });

<wd:field>
...
   <wd:selection-list type="flow-jxpath" list-path="items"
     value-path="value" label-path="label"/>
...
</wd:field>

> I hope this time it was written more straight forward and not that much 
> irritating.

Don't worry, it's not you that are irritating, it's really me that's 
being obtuse ;-). And please excuse me if I still don't get what your 
aiming for.

	Ugo



Re: [cforms] selection list binding

Posted by Joerg Heinicke <jo...@gmx.de>.
On 10.03.2004 22:01, Ugo Cei wrote:

> Not it's me that's not getting your point here ;-).

Ok, let me clarify. I think I do nothing unusual. Yes, I have a form 
with a simple dynamic selection list. And I do the binding against a bean.

There are two known ways to set the selection list dynamically: 
setSelectionList(String uri) and setSelectionList(Object model, String 
valuePath, String labelPath). The first one is for the @src, the latter 
one for setting the selection list from flow (and using 
FlowJXPathSelectionList internally).

As I do not want to go back to sitemap I chose the latter one, remains 
only the question where to use it. I found wd:on-value-changed in the 
samples, the usage in the "normal" flowscript works of course too. 
on-value-changed is not appropriate for me. The usage of 
setSelectionList in the "normal" script makes it specific to the form, 
at the moment it is so generic that it is applicable for all my forms.

So when/where shall the selection list be set? I liked the idea of doing 
it during the binding, wb:javascript made it possible to me. Do you 
think it's bad? I added therefore the collection to fill the selection 
list to my DTO.

For the case this is not a completely stupid way of handling it I 
suggested to replace the wb:javascript code with a common usable wb:list 
element.

But still I have one problem independent of this: When using 
setSelectionList() the entry without a value, that should be there to 
unset any choice, is replaced/removed.

I hope this time it was written more straight forward and not that much 
irritating.

Thanks in advance for any comment.

Joerg

Re: [cforms] selection list binding

Posted by Ugo Cei <u....@cbim.it>.
Joerg Heinicke wrote:
> Thanks for your answer, Ugo, I only do not get your point.
> 
> My problem was about binding and I solved it with the above wb:javascript code
> and it works for the moment. But I could imagine that I'm not the only one
> binding selection lists to a collection, so maybe adding an element like the
> above mentioned wb:list could replace the need for the wb:javascript above. It's
> like the sample on the wiki - instead you can simply use wb:value.

Pardon me if I'm being obtuse, but why would you want to set a selection 
list's contents via binding? Isn't your aim to generate the <option>s of 
a <select> using a collection? If so, what is the flow-jxpath selection 
list missing? Or is it me that is missing something obvious here? Can 
you describe your use case?

> Now what should @type="flow-jxpath" change, especially as it is in the form
> definition? setSelectionList() also works without specifying the @type, even
> without having wd:selection-list in the form definition.

Not it's me that's not getting your point here ;-).

	Ugo


Re: [cforms] selection list binding

Posted by Joerg Heinicke <jo...@gmx.de>.
Ugo Cei <u.cei <at> cbim.it> writes:

> > <wb:javascript id="filter.object" path="objects" direction="load">
> >   <wb:load-form>
> >     var objects = jxpathPointer.getNode();
> >     widget.setSelectionList(objects, "id", "name")
> >   </wb:load-form>
> > </wb:javascript>
> > 
> > The question is just if this could be added with a "real" element in the wb
> > namespace, e.g. wb:list and the path has to point to a collection.
> 
> Isn't <wd:selection-list type="flow-jxpath"> what you're looking for? If 
> I'm not mistaken, it's already there.

Thanks for your answer, Ugo, I only do not get your point.

My problem was about binding and I solved it with the above wb:javascript code
and it works for the moment. But I could imagine that I'm not the only one
binding selection lists to a collection, so maybe adding an element like the
above mentioned wb:list could replace the need for the wb:javascript above. It's
like the sample on the wiki - instead you can simply use wb:value.

Now what should @type="flow-jxpath" change, especially as it is in the form
definition? setSelectionList() also works without specifying the @type, even
without having wd:selection-list in the form definition.

Joerg


Re: [cforms] selection list binding

Posted by Ugo Cei <u....@cbim.it>.
Joerg Heinicke wrote:
> Hello,
> 
> below you will find the mail I wanted to send first, but after having written it
> I found the solution myself:
> I thought about the correct event instead of on-value-changed, I came to on-bind
> and in the binding docu I found wb:javascript and came to following code that
> nearly satisfies me:
> 
> <wb:javascript id="filter.object" path="objects" direction="load">
>   <wb:load-form>
>     var objects = jxpathPointer.getNode();
>     widget.setSelectionList(objects, "id", "name")
>   </wb:load-form>
> </wb:javascript>
> 
> The question is just if this could be added with a "real" element in the wb
> namespace, e.g. wb:list and the path has to point to a collection.

Isn't <wd:selection-list type="flow-jxpath"> what you're looking for? If 
I'm not mistaken, it's already there.

	Ugo