Felix Dorner | 20 Jul 01:42

Problem with Checkboxes

Hey,

first, I am a Squeak/Smalltalk newcomer, so please forgive me if I make 
an obvious error. I also give as much detail as I can and would greatly 
appreciate general comments.

I am trying to write a small survey application, for that I created a 
class WASurvey:

WAComponent subclass: #WASurvey
    instanceVariableNames: 'survey questionsPerPage currentPage'
    classVariableNames: ''
    poolDictionaries: ''
    category: 'questionaire'

survey is a list of questions, questionsPerPage/currentPage should be 
obvious.

The component is rendered like that:

renderContentOn: html
    | first last |
    first := currentPage - 1 * questionsPerPage + 1.
    last := first + questionsPerPage - 1.
    html heading: survey title.
    html text: currentPage; text: '/'; text: self pageCount.
    html form: [
        survey questions from:first to:last do: [ :question | question 
renderContentOn: html ].
        html submitButton text: 'Previous Page';
(Continue reading)

Julian Fitzell | 20 Jul 03:05

Re: Problem with Checkboxes

So in the top frame of the stack you can see that the error is #value:
being called on nil. If you look at the second frame, you can see that
#value is being called on the instance variable 'callback', so clearly
that must be nil. And sure enough, if you look at your rendering code,
you have not set a callback for your checkboxes (if you don't set a
callback, you won't get the value submitted by the user).

If you add a call to #callback: when rendering your checkbox the
problem should go away. That said, obviously the framework should
handle the case of no callback more gracefully. I created the
following issue: http://code.google.com/p/seaside/issues/detail?id=106

Welcome to Seaside,

Julian

On Sun, Jul 20, 2008 at 7:46 AM, Felix Dorner <felix_do <at> web.de> wrote:
> Hey,
>
> first, I am a Squeak/Smalltalk newcomer, so please forgive me if I make an
> obvious error. I also give as much detail as I can and would greatly
> appreciate general comments.
>
> I am trying to write a small survey application, for that I created a class
> WASurvey:
>
> WAComponent subclass: #WASurvey
>   instanceVariableNames: 'survey questionsPerPage currentPage'
>   classVariableNames: ''
>   poolDictionaries: ''
(Continue reading)

Felix Dorner | 20 Jul 11:01

Re: Problem with Checkboxes

Hi Julien,

> If you add a call to #callback: when rendering your checkbox the
> problem should go away. That said, obviously the framework should
> handle the case of no callback more gracefully. I created the
> following issue: http://code.google.com/p/seaside/issues/detail?id=106
>   

Great. I simply assumed that not setting a callback would not break 
anything. (I didn't set a callback for the radio button (group) either, 
and didn't have problems there). I simply wanted to add the callbacks in 
a second step, and definitely agree that a nil callback shouldn't cause 
a problem.

Thanks for helping,
Felix
cdrick | 20 Jul 06:38

Re: Problem with Checkboxes

> WAComponent subclass: #WASurvey
>   instanceVariableNames: 'survey questionsPerPage currentPage'
>   classVariableNames: ''
>   poolDictionaries: ''
>   category: 'questionaire'
>
> survey is a list of questions, questionsPerPage/currentPage should be
> obvious.
>
> The component is rendered like that:
>
> renderContentOn: html
>   | first last |
>   first := currentPage - 1 * questionsPerPage + 1.
>   last := first + questionsPerPage - 1.
>   html heading: survey title.
>   html text: currentPage; text: '/'; text: self pageCount.
>   html form: [
>       survey questions from:first to:last do: [ :question | question
> renderContentOn: html ].

another remark:

[:question | html render: question]

"It's important that you use #render:, rather than directly calling
the #renderContentOn: method of the subcomponent. " if question is a
component (then don't forget to use children).

If Question is not a subclass of WAComponent, then implement renderOn:
(Continue reading)

Felix Dorner | 21 Jul 17:04

Re: Problem with Checkboxes

Hi Cdric,

>>   html form: [
>>       survey questions from:first to:last do: [ :question | question
>> renderContentOn: html ].
>>     
>
> another remark:
>
> [:question | html render: question]
>
> "It's important that you use #render:, rather than directly calling
> the #renderContentOn: method of the subcomponent. " if question is a
> component (then don't forget to use children).
>   
Question is actually not a WAComponent subclass. Anyway, thanks for the 
advice, I'll keep that in mind.

> If Question is not a subclass of WAComponent, then implement renderOn:
> instead of renderContentOn:
>   
Why? Simply to avoid confusion?

Thanks,
Felix
Julian Fitzell | 21 Jul 17:18

Re: Problem with Checkboxes

On Mon, Jul 21, 2008 at 11:04 PM, Felix Dorner <felix_do <at> web.de> wrote:
>> If Question is not a subclass of WAComponent, then implement renderOn:
>> instead of renderContentOn:
>>
>
> Why? Simply to avoid confusion?

Because then you can pass it to "html render:" :)

Any object that is renderable should implement #renderOn:. WAComponent
implement that to do a bunch of other stuff and then calls
#renderContentOn: for its subclasses.

Obviously if you're the only one using your class, you can call it
#fooBarBaz: if you feel like, but if you implement #renderOn: you can
do:

html render: aCollectionOfQuestions

or:

html div id: 'foo'; with: aQuestion

And yes, it's just sort of standard I guess.

Julian

Gmane