Can I do this with a select list?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Can I do this with a select list?

Rick Flower
I've got a collection of objects that are read in from a database and
I'd like to be able for Seaside to use that collection (which will be
used elsewhere as well) to build a list of stuff to show up in a select
list -- specifically labels of my own choosing (based on the database
objects read in).  So, if I've got some objects with a #name instance
variable in them (among other things), I'd like to be able to do
something like the following :

"Read the items from the database -- this returns full objects"
| catCollection |
catCollection := self readDBItems.
.
.
.
(html select) list: catCollection; useMappingMethod: #name; selected: (catCollection first); callback: [:i | self cat: i].
.
.
.

Right now, I have code that massages my "catCollection" and extracts
out the #name from each object and populates an Array which is used for
the #list: and #selected: messages.  Unfortunately, this gets ugly
with the callback where I have to take the selected string and do a
reverse lookup from the collection to get the actual object which is
what I'm interested in saving.  

I looked at the code for WACollectionTag, but didn't see anything in
there that would support this sort of mechanism..  I'd love to have
the ability to register a method (care of the above #useMappingMethod:)
that can be called for each item in the collection to obtain the string
that the select list needs.. On the other hand, when the callback is called,
instead of returning the selected string as the argument to the callback,
it would return the entire selected object..

Has anyone else needed to do something like this, or is there some easier
way to achieve this without doing the to/from translations?

Thanks!
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Can I do this with a select list?

keith1y
Rick,

have a look in the image for users of #select and see how they do it.
I think that what you are looking for is #labels:

I found this example from Magritte which I have loaded in my image.

renderEditorSelectedOn: html
    html select
        attributes: self attributes;
        size: 6; style: 'width: 150px';
        list: self selectedList;
        selected: self selectedSelected;
        callback: [ :value | self selectedSelected: value ];
        labels: [ :value | self description toString: value ]

also this example from WAConfigurationEditor

visitBooleanAttribute: anAttribute with: html
    html select
        list: (Array with: true with: false);
        selected: (configuration valueForAttribute: anAttribute);
        callback: [:v | configuration takeValue: v forAttribute:
anAttribute];
        labels: [ :b | b ifTrue: [ 'true' ] ifFalse: [ 'false' ] ]

best regards

Keith




       
       
               
___________________________________________________________
All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine
http://uk.docs.yahoo.com/nowyoucan.html
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Can I do this with a select list?

keith1y
In reply to this post by Rick Flower
Rick

so your example would be something like this

html select
    list: catCollection;
    selected: catCollection first;
    labels: (catCollection collect: [ :item | item name ]);
    callback: [ :item | self cat: item ];
    yourself.

Keith
   
>
> .
> .
> (html select) list: catCollection; useMappingMethod: #name; selected:
> (catCollection first); callback: [:i | self cat: i].
> .

       
       
               
___________________________________________________________
All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine
http://uk.docs.yahoo.com/nowyoucan.html
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Can I do this with a select list?

Rick Flower
Keith Hodges wrote:

> Rick
>
> so your example would be something like this
>
> html select
>    list: catCollection;
>    selected: catCollection first;
>    labels: (catCollection collect: [ :item | item name ]);
>    callback: [ :item | self cat: item ];
>    yourself.

Thanks Keith!

I tried it and it died as I thought it might in the following place:

Seaside.WASelectTag>>labels: aBlock
        labelsBlock := aBlock fixTemps.


Array(Object)>>doesNotUnderstand: #fixTemps

I looked around in the code for fixTemps and both places seem to be
place holders only.. Did I miss something?


_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Re: Can I do this with a select list?

Lukas Renggli
> >    labels: (catCollection collect: [ :item | item name ]);

#labels: expects a block. Try something like:

    labels: [ :item | item name ]

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Can I do this with a select list?

keith1y
Lukas Renggli wrote:
>> >    labels: (catCollection collect: [ :item | item name ]);
>
> #labels: expects a block. Try something like:
>
>    labels: [ :item | item name ]
>
> Cheers,
> Lukas
>
Thats why I shouldn't be doing this a 6am

Keith

               
___________________________________________________________
The all-new Yahoo! Mail goes wherever you go - free your email address from your Internet provider. http://uk.docs.yahoo.com/nowyoucan.html
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

WAListener

keith1y
In reply to this post by Lukas Renggli
Is it just me or is WAListener unable to handle authentication?

Keith

               
___________________________________________________________
The all-new Yahoo! Mail goes wherever you go - free your email address from your Internet provider. http://uk.docs.yahoo.com/nowyoucan.html
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: WAListener

Lukas Renggli
> Is it just me or is WAListener unable to handle authentication?

A few days ago I sent the following mail to Michel. The same I write
about WATask holds for authentication as it uses #returnResponse:

Cheers,
Lukas

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -

Hi Michel,

obviously WAListener does not work together with users of
#returnResponse:. I guess this cannot be avoided due to the nature of
HTTP streaming. The best solution would certainly be to change the
implementation of WATask not to use #returnResponse:.

When WAListener was introduced January 2006 Avi wrote in the mailing list:

> Ok, I promised a hack and a hack it is, but...
>
> 1. Make sure you have FastSocketStream loaded from SqueakMap
> 2. Load http://squeaksource.com/Seaside/Seaside2.6a2-avi.77.mcz
> 3. WAListener startOn: 8081
>
> Now try accessing your app from 8081 instead of 8080 or whatever
> usual port you use.  Notes:
>
> - This doesn't do Keep-Alive or chunked encoding; it uses HTTP 1.0,
> not 1.1
> - WAListener largely bypasses Comanche (using it only to parse the
> HttpRequest), so there's much less there in terms of error handling
> or configurability
> - It WILL NOT WORK if you use a WATask subclass
> - I can't measure or perceive a performance benefit on localhost,
> though I *can* see the difference if I use telnet to simulate an HTTP
> request.  I have yet to do any testing with remote servers.
>
> I'm curious to see if this makes a difference for anyone.

There was no reply to this message, so I guessed I am the first real
user of WAListener with Comet.

Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Can I do this with a select list?

Rick Flower
In reply to this post by keith1y
Keith Hodges wrote:

> Lukas Renggli wrote:
>>> >    labels: (catCollection collect: [ :item | item name ]);
>>
>> #labels: expects a block. Try something like:
>>
>>    labels: [ :item | item name ]
>>
>> Cheers,
>> Lukas
>>
> Thats why I shouldn't be doing this a 6am

Thanks Keith & Lukas!  I'll have to admit that it didn't really make
much sense to me last night when this email conversation took place,
but now that it's morning and I've had a good nights sleep, it seems
perfectly reasonable.. Of course, it also seems to work just fine!
Thanks again!
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside