Scaffolding: overruling specific event types does not work

10 views
Skip to first unread message

marc

unread,
Jan 25, 2012, 8:17:38 AM1/25/12
to model...@googlegroups.com
Hi,

Today I was playing with the scaffolding feature of MG with CF9 Hibernate ORM. Everything worked well but I didn't get MG to update a record, instead it kept adding the modified record. It took me a while to find out I had to add the record's primary key in the editform so that when the form with the modified data is submit, Hibernate knows it has to update the record instead of create a new one.
One of the things I tried before this dawned to me was to override the scaffolds "commit event by doing this:

<modelglue>
    <scaffold object="vrienden" type="delete,edit,list" event-type="mainLayout" />

    <scaffold object="vrienden" type="Commit" event-type="mainLayout">
        <broadcasts>
            <message name="vrienden.commit" />
        </broadcasts>
        <results>
            <result do="vrienden.list" />
        </results>
    </scaffold>

</modelglue>

and including this in my ModelGlue.xml:

    <controllers>
        <controller id="vrienden" type="modelglueapplicationtemplate.controller.vrienden">
            <message-listener message="vrienden.commit" function="commit" />
        </controller>
    </controllers>

</modelglue>

(I split up the main ModelGlue.xml file in separate files and include those with the <include template="/ModelGlueIncludes/xxx.xml" /> tag in ModelGlue.xml.)

To see if this worked, I added a <cfdump> in controllers/vrienden.cfc:

    <cffunction name="Commit">
        <cfargument name="event">

<cfdump var="#event#"><cfabort>
    </cffunction>

But this dump never showed up upon committing the editform. Instead a new record was added or, when I found out about the pk, the existing record was modified.

When I removed the line

    <scaffold object="vrienden" type="Commit" event-type="mainLayout">

and I had an event handler defined in ModelGlue.xml for the event "vrienden.commit", that got executed fine.

So resuming it looks like:
  • the scaffold tag will create the event-handlers specified in it's type attribute or all event-handlers (list,edit,view,commit,delete) when no type attribute is specified;
  • when specifying a subset of event handlers in the <scaffold> type attribute and issuing a request with the missing event-handler MG returns an error message that the event handler is not defined (e.g. <scaffold type="list,edit,delete" ...> and issuing a request to /?event=vrienden.commit);
  • when adding a separate scaffold tag for the missing event, MG ignores the <broadcast>,<results> or <view> subtags. Instead it behaves as if the missing tag type was added to the scaffold's type attribute.
    E.g.
    <scaffold object="vrienden" type="delete,edit,list" event-type="mainLayout" />

    <scaffold object="vrienden" type="commit" event-type="mainLayout">
            <broadcasts>
    [...]
     </scaffold>

    behaves the same as

    <scaffold object="vrienden" type="delete,edit,list,commit" event-type="mainLayout" />
     
Changing the value of Coldspring.xml <defaultScaffolds> tag to not include the "commit" event handler made no difference. Changing the order I included my ModelGlue.xml files in the main ModelGlue.xml made no difference either.

I checked the docs at http://docs.model-glue.com/wiki/HowTos/HowToUseScaffolds#Scaffolds. Am I misinterpreting or overlooking something here?

Thanks,

Marc

Dan Wilson

unread,
Jan 25, 2012, 8:39:58 AM1/25/12
to model...@googlegroups.com
Hey Marc,

Thanks for the detailed post. That was helpful to understand what is going on.

I just tried this on my end and it seems to work out ok.


In the 
<scaffold object="Post" type="Commit,View" >
<broadcasts>
<message-listener name="test" />
</broadcasts>
</scaffold>

I'm aborting in the Controller method test and I do get an abort. You can try one of two things... 

Firstly, I'd recommend looking at the generated Scaffold.xml and see what is being rendered for that particular event. Mine was located at /config/scaffolds/scaffolds.xml


Next, if that wasn't helpful, turn on the Model Glue debugging and see if there is anything in there that is helpful to understanding why the routing is working as it is, and not as you intend...



Post back and let me know what you find. I'm not saying there isn't an issue, but I don't yet have something to replicate on my end.

DW



--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog
 
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to model...@googlegroups.com
To unsubscribe from this group, send email to
model-glue+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en



--
Plutarch - "The mind is not a vessel to be filled but a fire to be kindled."

marc

unread,
Jan 25, 2012, 9:40:21 AM1/25/12
to model...@googlegroups.com
Hi Dan,'

Thanks for pointing out the Scaffolds.xml, overlooked that one.

I found out that if I add

    <scaffold object="vrienden" type="delete,edit,list" event-type="mainLayout" />

to my custom scaffolds.xml, the generated scaffolds.xml contains the generated eventhandlers for those 3 types (delete,edit,list).

When I add

     <scaffold object="vrienden" type="commit" event-type="mainLayout">
        <broadcasts>
            <message name="vrienden.commit" />
        </broadcasts>
        <results>
            <result do="vrienden.list" />
        </results>
    </scaffold>

to my custom scaffolds.xml , in the generated Scaffolds.xml an entry is generated for the commit eventhandler. It contains the default ModelGlue.genericCommit handler in <broadcasts> and the default event "vrienden.edit" in <results>.
In addition my custom message <message name="vrienden.commit" /> is added _after_ the default genericCommit in <broadcasts> .
So whatever I add in my custom scaffold tag is added after the <broadcasts> tag in the generated Scaffolds.xml.
In the generated Scaffolds.xml <results> section, my custom result <result do="vrienden.list" /> is added _before_ the default result.vrienden.Edit.

So whatever I specify in custom scaffold.xml is _added_ to the generated events and doesn't overrule it.
Plus the order in which things are added (before or after the generated tags) is not consistent.

But I just saw in your pastebin that you have a <controllers> section containing a listener for your custom event "test" in Scaffolds.xml. I have no such section in generated Scaffolds.xml. Maybe that's why my custom added event handler doesn't get executed?

See http://pastebin.com/Sc2cfzu1 for my generated and custom Scaffolds.xml.

Marc

Dan Wilson

unread,
Jan 25, 2012, 10:14:38 AM1/25/12
to model...@googlegroups.com
Yup,. that makes total sense. I think I see what you were getting at initially.

Model Glue scaffold customization is additive and will always decorate the base scaffold with your customizations.

In your case, I think you just want to define an event handler called Vrienden.Commit, rather than use the scaffold tag.

Now, if you need to change EVERY xxx.Commit event handler generated by Model Glue, we have something that will let you do that. Basically, you can change the patter used by MG to suit your custom needs, and when MG needs to generate a type of scaffold (like Commit), it'll use your pattern every time, and not the built in one.

If, in fact you need to do that, let me know and I'll dig up specifics on how to do it.


DW


--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog
 
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to model...@googlegroups.com
To unsubscribe from this group, send email to
model-glue+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en

Marc Bakker

unread,
Jan 25, 2012, 11:20:20 AM1/25/12
to model...@googlegroups.com
ok, that's clear. custom scaffolding's results in decorating the generated event handlers and not overriding them. I was looking for overriding the generated event handler "comit "since I thought I couldn't update a record, but there's no need for since I found out how to do that.
Just wondering why I am not getting a <cfdump><abort> in my controller's method since the message tag is there in the generated Scaffold.xml. I 'll look into the MG debugging if the event fires and where it leads to.

Anyway, thanks for bearing with me on this one,

Marc
Met vriendelijke groet,

Marc Bakker

Dan Wilson

unread,
Jan 25, 2012, 1:14:21 PM1/25/12
to model...@googlegroups.com
It might be the commit logic is redirecting before you get to the custom message/controller function. 

DW
Reply all
Reply to author
Forward
0 new messages