Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts
Tuesday, August 26, 2008
PureMVC Gotcha
Don't send notifications that you're expecting a response to in your mediator's constructor (or during construction). Instead, override the onRegister() function and call them there. Your Mediator won't receive notifications it's interested in until after the registration process is finished. Seems pretty obvious, but you can loose track real quick of what's going on in the background when you're using a system like PureMVC that just seems to work.
Thursday, August 21, 2008
Crazy Flex DateField Insanity
So, I've been busily putting together a Flex application at work, and we ran into a curious issue where Flash would infinitely loop and crash itself/the browser. (Not tested in Air) To give a little background first, we're following the convention of keeping our data in data objects (or data models), and binding both the visual component to the data model field and the data model field back to the visual component. All of our code is dynamic, so it's written in Actionscript, not MXML.
The problem occurred when we had two DateField interface components pointing to the same data model field. The two DateFields would be hooked up to a single data model field, and we saw the following behavior:
My theory is that Date comparisons are broken or behave oddly, and if you just compare Date.time, it works as expected. I'm assuming this is why the binding went forever, but I can't be sure.
Hope this helps someone else.. some also possibly helpful links:
http://devel.teratechnologies.net/steve_examples/Flex_BindingProblem/DateTest.html
http://bugs.adobe.com/jira/browse/SDK-15618
The problem occurred when we had two DateField interface components pointing to the same data model field. The two DateFields would be hooked up to a single data model field, and we saw the following behavior:
- If we bound the DateField.selectedDate to the model.birthday (as an example), with one DateField Instance, all would work. Underneath, it set off the bindings twice when you changed the selectedDate, but that was OK. With multiple DateField Instances, it would crash as it tried to create the second DateField. (This happened when we preinitialized the DateField and without preinitializing the DateField) Underneath, it would set off the bindings between the three items infinitely.
- If we bound the DateField.data to the model.birthday, it would never infinitely loop, but model.birthday wouldn't get updated when DateField was changed. I think that the code for DateField.data is screwy, but according to the documentation, it seems like this is the property you should bind to.
- If I tried binding the DateField.data to the model.birthday and the model.birthday to the DateField.selectedDate, it would also loop infinitely.
My theory is that Date comparisons are broken or behave oddly, and if you just compare Date.time, it works as expected. I'm assuming this is why the binding went forever, but I can't be sure.
Hope this helps someone else.. some also possibly helpful links:
http://devel.teratechnologies.net/steve_examples/Flex_BindingProblem/DateTest.html
http://bugs.adobe.com/jira/browse/SDK-15618
Labels:
adobe,
bug,
crash,
date,
flex,
infiniteloop,
programming,
tip
Thursday, March 06, 2008
Grails Date Trick
If you have a Date field in one of your domain classes, for instance:
tag. Now, maybe you don't have to dig.
class Person{and you're struggling to figure out a way to get stuff into it without explicitly creating a date and converting strings or integers into it, Grails provides a handy (yet not documented?) set of properties for you. In our example, I could set birthday_year, birthday_month, birthday_day, birthday_hour, etc.. I found this by digging in the scaffolded views and figuring out how they render the
String Name
Date Birthday
}
Friday, February 29, 2008
Gotcha: Grails Auto Recompile Doesn't Do GSP
Grails does the auto recompile thing, much like Turbogears etc., but it doesn't seem to work for gsp pages, in particular, main.gsp. Which can trip you up, if you're trying to make a couple simple changes to your first Grails app.
Wednesday, February 27, 2008
Gotcha: Grails Capitalization
So, apparently Grails doesn't like Controllers starting with multiple capitol letters (i.e. TLAcronym). If you create a domain class with all lowercase, it will capitalize it for you, but if you try to create TLAcronym, it happily plays along. Then if you generate-all or do scaffolding for that domain class, you won't be able to access your controller. I've raised an issue for this here: GRAILS-2541.
Wednesday, September 26, 2007
Toscawidgets Forms: Passing Compound Widgets
For lack of documentation's sake, and because it wasn't initially obvious to me after poking around in the code (in fact, I got led astray, thinking there was some dot notation I would have to use), this is how you pass values into Compound Widgets in Toscawidgets:
Say you have some Widget like this:
and displayed in your template like this:
${ form.display(**form_args)}
then you can pass values into it from your controller like so:
I guess it's pretty obvious in retrospect, in fact, the compound Form outputs something much like this (minus the outside dictionary), and those values can be passed right back into the Compound Form again. Perhaps, had I been actually using a Model, or gotten more sleep, this all would have been more natural - but hopefully this helps someone else.
Hint: If you're overriding templates, be sure that you're still passing the right values in to fetch the children arguments, i.e.:
${section.display(value_for(section), **args_for(section))}
Say you have some Widget like this:
form = Form('FormName',
children=[
FieldSet('FieldSetName',
children=[
TextField('TextFieldName')])
])and displayed in your template like this:
${ form.display(**form_args)}
then you can pass values into it from your controller like so:
def controller(self):
return dict(form=form,
form_args={'value':{
'FieldSetName':{ 'TextFieldName':
'Desired TextField Value'}}})
I guess it's pretty obvious in retrospect, in fact, the compound Form outputs something much like this (minus the outside dictionary), and those values can be passed right back into the Compound Form again. Perhaps, had I been actually using a Model, or gotten more sleep, this all would have been more natural - but hopefully this helps someone else.
Hint: If you're overriding templates, be sure that you're still passing the right values in to fetch the children arguments, i.e.:
${section.display(value_for(section), **args_for(section))}
Monday, September 24, 2007
Gotcha: Toscawidgets and Mochikit
So, after much annoyingness, I've finally realized why I was having so much trouble using the Mochikit extension to Toscawidgets. As the Toscawidgets docs state, you need to include this template if you're using Genshi, which basically adds these lines (plus matching matching body top and bottom lines):
Now, if you're silly, like me, and don't really pay attention, you just include it, without looking too hard at your master template, which includes these lines by default:
As soon as you put the widget in your controller:
You start to get funny Genshi errors, mine was "AttributeError: 'Stream' object has no attribute 'tag'" which prompted me to try various combinations of adding ET() and HTML() to my templates, when the problem was that Toscawidgets cleans that whole ET/Genshi issue up and breaks when you leave them in.
So, long story short, add the site template and remove the conflicting lines from your master template. (Though, if you are mixing Toscawidgets and Turbogears widgets, you'll have to do something like what's outlined here.)
<link for=\"css in tg_css\" replace=\"css.display()\">
<link for=\"js in tg_js_head\" replace=\"js.display()\">
Now, if you're silly, like me, and don't really pay attention, you just include it, without looking too hard at your master template, which includes these lines by default:
<link for=\"css in tg_css\" replace=\"ET(css.display())\">
<link for=\"js in tg_js_head\" replace=\"ET(js.display())\">
As soon as you put the widget in your controller:
from toscawidgets.widgets.mochikit import mochikit
class Root(controllers.RootController):
@expose("genshi:mumapp.templates.sections")
def info(self):
return dict( form = InformationForm,
js = mochikit )
You start to get funny Genshi errors, mine was "AttributeError: 'Stream' object has no attribute 'tag'" which prompted me to try various combinations of adding ET() and HTML() to my templates, when the problem was that Toscawidgets cleans that whole ET/Genshi issue up and breaks when you leave them in.
So, long story short, add the site template and remove the conflicting lines from your master template. (Though, if you are mixing Toscawidgets and Turbogears widgets, you'll have to do something like what's outlined here.)
Saturday, August 04, 2007
Turbogears Banner
Tuesday, July 17, 2007
Turbogears Interpreter Goodness
I'd just like to say that I officially love working with Turbogears. It's just so great to be able to run interactive commands, with the environment that your code is working in already loaded up. (This isn't advertised enough in the Turbogears docs. They should have you do it in the tutorials) I hope it's still this fun when they switch everything over to Pylons, Genshi, and SQLAlchemy in 2.0. Maybe I am just odd, but it brightened up my so far kinda crappy week.
Tuesday, July 10, 2007
Gotcha: C# Windows.Forms Madness
So, if you are ever creating dynamic forms in C#, and things aren't showing up for some reason, and you sillily left one non-dynamic thing there, just to be sure that you're not loosing the whole container, check that the dynamic stuff isn't being created underneath other things. For some reason, I expect them to show up over older stuff, but apparently I'm wrong. (I.E. set form.Location = new System.Drawing.Point( [not 0], [also not 0]); )
[Spell check doesn't think that sillily is a word. Pssht.]
[Spell check doesn't think that sillily is a word. Pssht.]
Monday, July 09, 2007
Gotcha: Unicode Error with SQLObject + Turbogears + mysql
I spent a bit of time this morning trying to figure out why the code I wrote at 3am last night wasn't working. I kept getting a crazy Unicode conversion not supported error, and all the solutions that I found Googling were not satisfactory. Eventually, I found that I had used the wrong validator on one of my fields (specifically, a Date field, though I imagine this will happen with others as well). If you run into this, double check your validators before you do anything crazy like change your model to use all UnicodeCols.
Also, on the subject of validators in Turbogears, I recommend using the FormEncode documentation directly, it's much more complete than what you find listed in Turbogears docs.
Also, on the subject of validators in Turbogears, I recommend using the FormEncode documentation directly, it's much more complete than what you find listed in Turbogears docs.
Subscribe to:
Posts (Atom)

