Jul 14, 2010

Dojo Layout Tips

Dojo has gone through much work to build a nice set of widgets to help with the layout of your web applications.  They currently have many different layout managers.  From the highly usable dijit.layout.BorderContainer, to the functional, (or at least it doesn’t crash) dijit.layout.AccordianContainer.

But with all these layout managers, you can also use a multitude of pane objects.  SplitPane, SliderPane and so on.  But it’s the ContentPane, that really holds the guts of your application together.

Dojo now has 3 different content panes.  The dojo.layout.ContentPane, the dijit.layout.ContentPane, and the (you guessed it)…  the dojox.layout.ContentPane.

All three can be declaratively or programmatically created.

Declarative

<script type="text/javascript">
    dojo.require("dijit.layout.ContentPane");
</script>
<div dojoType="dijit.layout.ContentPane">
    &lt;!—Put your info here à
</div>

Programmatic

<div id="targetID">
    IE Rules
</div>
&lt;script type="text/javascript"&gt;
    dojo.require("dijit.layout.ContentPane");
    dojo.addOnLoad(function() {
        new dijit.layout.ContentPane({
            content: "<p>Honestly, it sucks</p>",
            style: "height:125px"
        },
        "targetID");
    });
&lt;/script&gt;
 
 

Where, once again, Dojo fails to excel is in their documentation.  While working on an application with many nested containers and layouts, I encountered several headaches, which forced me to head to Google to solve.

<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;">Back when in the early days of Dojo (0.4 to be honest), Dojo had the </span>dojo.widget.ContentPane, which executed javascript when you the set the executeScripts parameter to true.

This was removed in 0.9, to make the widget more streamlined (Huh???).  Since the dijit ContentPane was next logically choice, they must have added to the ability to run script code there. Well not exactly  To run script code, you need to should actually use dojox.layout.ContentPane.  Even though its in the dojox package it has been well tested and used.

Another helpful tip, when nesting multiple panes and containers together, the dojo.addOnLoad() method is ONLY executed on the first load.  Even if you href another page in, that addOnLoad will not be executed.  This means you can declaratively build your initial page, but subsequent pages that are “sucked in” your existing content panes, need to be built programmatically.

About the Author

Object Partners profile.
Leave a Reply

Your email address will not be published.

Related Blog Posts
Natively Compiled Java on Google App Engine
Google App Engine is a platform-as-a-service product that is marketed as a way to get your applications into the cloud without necessarily knowing all of the infrastructure bits and pieces to do so. Google App […]
Building Better Data Visualization Experiences: Part 2 of 2
If you don't have a Ph.D. in data science, the raw data might be difficult to comprehend. This is where data visualization comes in.
Unleashing Feature Flags onto Kafka Consumers
Feature flags are a tool to strategically enable or disable functionality at runtime. They are often used to drive different user experiences but can also be useful in real-time data systems. In this post, we’ll […]
A security model for developers
Software security is more important than ever, but developing secure applications is more confusing than ever. TLS, mTLS, RBAC, SAML, OAUTH, OWASP, GDPR, SASL, RSA, JWT, cookie, attack vector, DDoS, firewall, VPN, security groups, exploit, […]