Understanding e.MarkDirty()

92 views
Skip to first unread message

Nigel Vickers

unread,
Aug 14, 2013, 12:32:34 PM8/14/13
to gowebui...@googlegroups.com
I have been evaluating gowut and am impressed with its functionality. The use of the components , event handlers and events are easy to follow. However, e.MarkDirty() doesn't behave as I expected. I  have  a table that renders a "resultset" obtained from a database query. The initial rendering works as expected. Two button event handlers update "resultset" and MarkDirty() the panel containing the table. The table is marked "dirty" cascaded from panel. The table is then passed to the browser as expected. However it still contains the intial values of the "resultset"  not the updated values. Have I missed something?  The code suggests that "dirty" should cause the reload of the table with the updated values not just replay. I can't find anything that would suggests that the component is cached anywhere. I would add an event handler to the table but I haven't found a way to communicate events between event handlers or raising an event within a handler. so that wouldn't help. Any thoughts/suggestions would be gratefully received.
Nigel Vickers

András Belicza

unread,
Aug 14, 2013, 1:47:18 PM8/14/13
to Nigel Vickers, gowebui...@googlegroups.com
How do you build the table? You add components to its cells, e.g. Labels containing the data to display?
If so, then the data displayed in the table is "cached" in the values (e.g. texts) of the components added to the table.

e.MarkDirty() tells gowut that components (or their look) might have changed and they need to be re-rendered.
If you built the table in the way I think, you have to re-add/replace the components in its cells having the new values to be displayed, or simply changes their values.
For example if you added a label to a cell having the text to be displayed, simply change the label's text to the new value.

e.MarkDirty() will cause the components to be re-rendered: the client in the browser will requests their new look and update the client DOM appropriately. But if the dirty components send the same look and HTML code, they obviously will not change.

Nigel Vickers

unread,
Aug 14, 2013, 2:26:27 PM8/14/13
to gowebui...@googlegroups.com, Nigel Vickers
Here is the table definition. It is loaded correctly on the initial rendering. However if the contents of "resultset" is updated how do i get it to reread "resultset"? MarkDirty() doesn't cut it.
// add result table
        t := gwu.NewTable()
        t.SetCellPadding(2)
        t.Style().SetFontSize("80%")
        var tsize int
        tsize = qRows * 3
        t.EnsureSize( tsize , 6)
        var i int = 0 
        for tuple := 0; tuple < tsize ; tuple += 3 {
                Element := resultSet[i]
                for attribute := 0; attribute < 17 ; attribute++ {
                        switch attribute {
                        case 0 : t.Add(gwu.NewLabel(Element.Fname.String), tuple , 0)
                        case 1 : t.Add(gwu.NewLabel(Element.Land.String), tuple, 1)
                        case 2 : t.Add(gwu.NewLabel(Element.Plz.String), tuple, 2)
                        case 3 : t.Add(gwu.NewLabel(Element.Ort.String), tuple, 3)
                        case 4 : t.Add(gwu.NewLabel(Element.Straße.String), tuple, 4)
                        case 5 : t.Add(gwu.NewLabel(Element.Cdate.String()), tuple, 5)
                        case 6 : t.Add(gwu.NewLabel(Element.Title.String), tuple + 1, 0)
                        case 7 : t.Add(gwu.NewLabel(Element.Acdtitle.String), tuple + 1, 1)
                        case 8 : t.Add(gwu.NewLabel(Element.Firstname.String), tuple + 1, 2)
                        case 9 : t.Add(gwu.NewLabel(Element.Surname.String), tuple + 1, 3)
                        case 10 : t.Add(gwu.NewLabel(Element.Source.String), tuple + 1, 4)
                        case 11 : t.Add(gwu.NewLabel(Element.Sourceref.String), tuple + 1, 5)
                        case 12 : t.Add(gwu.NewLabel(Element.Workemail.String), tuple + 2, 0)
                        case 13 : t.Add(gwu.NewLabel(Element.Workphone.String), tuple + 2 , 1)
                        case 14 : t.Add(gwu.NewLabel(Element.Workfax.String), tuple + 2, 2)
                        case 15 : t.Add(gwu.NewLabel(Element.Workmobile.String), tuple + 2, 3)
                        case 16 : t.Add(gwu.NewLabel(Element.Workurl.String), tuple  + 2, 3)
                        }
                if tuple % 2 == 0{
                        t.RowFmt(tuple).Style().SetBackground("#C9CDD8")
                        t.RowFmt(tuple + 1).Style().SetBackground("#C9CDD8")
                        t.RowFmt(tuple + 2).Style().SetBackground("#C9CDD8")
                        }else{
                        t.RowFmt(tuple).Style().SetBackground("#EFF2F8")
                        t.RowFmt(tuple + 1).Style().SetBackground("#EFF2F8")
                        t.RowFmt(tuple + 2).Style().SetBackground("#EFF2F8")

                        }

                }
        i++
        //fmt.Println("rendering table ", i)
        }
        p.Add(t)

thanks for your advice,
Nigel Vickers

András Belicza

unread,
Aug 14, 2013, 6:03:45 PM8/14/13
to Nigel Vickers, gowebui...@googlegroups.com
You can build the table (create it and add labels to it), and you can write a fillTable method which would fill the result set to the table.
Call this fill table method on startup, and later, when you want to refresh the table (e.g. in the event handler of your button), call this fill table method again which will add/set all the data from the result set to the table.
Once this is done, the MarkDirty() will cause a table re-render after the event is processed - now with the new data.

I can create a more detailed explanation, but I don't have more time now. Let's see if this is enough.

András

Nigel Vickers

unread,
Aug 15, 2013, 3:05:27 AM8/15/13
to gowebui...@googlegroups.com, Nigel Vickers
OK! got it; it works.
 For some unknown reason I had got the impression you could only add an eventhandler within the immediate parent . Of course this is not the case. Thanks for your assistance.

I really like your Style library. I can understand why css3/html5 is not part of the basic implementation . However, extending Style to handle "border-radius " was trivial. 

Nigel Vickers
Reply all
Reply to author
Forward
0 new messages