[Seaside] onAnswer error on embedded component
C. David Shaffer
cdshaffer at acm.org
Wed Jul 21 17:53:38 CEST 2004
LK wrote:
> I'm calling a grid object from withing my may renderContentOn method.
> I get this error below. Do I need an #onAnswer method? What would I
> put in it?
> -Larry
> PMLogsTask>>renderContentOn: html
>
> |db |
> db _ self connect.
> html cssId: 'banner'.
> html table: [
> html tableRowWith: [
> html divNamed: 'title' with: self title.
> html divNamed: 'subtitle' with: self subtitle.
> ]
> ].
> self call: (PMLogsView new renderContentOn: html and: db).
This is a pretty common misunderstanding of #call:. #call: should
generally not be called from #renderContentOn:, except with great care
as one sees in WATask subclasses. What you really are doing is
embedding a component, not calling it. So, to embed a component you
need to pass it as an argument to #render:
html render: pmLogsView
now, notice that I didn't create the instance here...that's because if a
component embeds another component it must include that component in its
response to #children. So, what I'd suggest is something like this:
add pmLogsView as an i-var to your class
initialize
pmLogsView := PMLogsView new.
children
^Array with: pmLogsView
renderContentOn: html
| db |
.... your code except the call: here...
pmLogsView useDb: db during: [html render: pmLogsView]
db logout
Then in your PMLogsView add a db i-var and the method
useDb: aDatabase during: aBlock
db := aDatabase.
aBlock ensure: [db := nil]
That way your i-var doesn't keep the reference to the database around
any longer than needed. Actually, what I'd really recommend is storing
the db in a custom session subclass...if your app is bigger than these
two classes then you'll eventually probably find that you need access to
the database in many of your views. I believe that there is a tutorial
around which shows you how to do this. Look at
http://beta4.com/seaside2/docs.html as a possible starting place.
David
More information about the Seaside
mailing list