July 4, 2010

Grails App not deploying on tomcat your server? Here’s the fix.

If you are trying to deploy a grails app on tomcat using a war and for some reason the war isn’t deploying then your app may be trying to create log files that it does not have permission to create or write too.

Just add the following to your grails-app/Config.groovy file and you should be good to go

def catalinaBase = System.properties.getProperty(‘catalina.base’)
if (!catalinaBase) catalinaBase = ‘.’   // just in case
def logDirectory = “${catalinaBase}/logs”

log4j

= { root ->
    appenders
{
        rollingFile name
:‘stdout’, file:“${logDirectory}/${appName}.log”.toString(),  maxFileSize:’100MB’
        rollingFile name
:‘stacktrace’, file:“${logDirectory}/${appName}_stack.log”.toString(), maxFileSize:’100MB’
     
}

     error  

‘org.codehaus.groovy.grails.web.servlet’,  //  controllers
           
‘org.codehaus.groovy.grails.web.pages’, //  GSP
           
‘org.codehaus.groovy.grails.web.sitemesh’, //  layouts
           
‘org.codehaus.groovy.grails.web.mapping.filter’, // URL mapping
           
‘org.codehaus.groovy.grails.web.mapping’, // URL mapping
           
‘org.codehaus.groovy.grails.commons’, // core / classloading
           
‘org.codehaus.groovy.grails.plugins’, // plugins
           
‘org.codehaus.groovy.grails.orm.hibernate’, // hibernate integration
           
‘org.springframework’,
           
‘org.hibernate’
     root
.level = org.apache.log4j.Level.WARN
 
}

Special thanks to lazygun for his article on setting up rackspace cloud for grails. http://www.lazygun.net/deploying-a-grails-app-to-rackspace-cloud-ser

Posted via email from Matthew Sloan Wallace

June 28, 2010

Mapping current grails domain classes to use mongodb

I have a grails app that I am building and wanted try out using mongodb sense i have heard so many good things about it. The quick start guide doesn’t give you and helpful hints on how to map current domain classes to use mongodb. It only helps you create new domain classes to use mongo.

The excerpt below is strait from the wiki of the mongodb plugin for grails github account. Hope this helps some of you out.

 

The MongoDB Grails plugin is primarily exposed to Grails applications as a Spring bean called ‘mongo’.
Grails classes can then easily make use of it throughout their code by simply adding a ‘mongo’
property to their classes which support dependency injection (domain/controllers/services), eg:

class UserController{ def mongo }

Configuration

At startup the MongoDB plugin will look for a ‘mongo’ configuration property in your
Config.groovy file which defines your MongoDB databases and related configuration
properties.

#Config.groovy  mongo{ databases{ server1{ host = "localhost" port = 1234  // if ommited, will use the default MongoDB port }  server2{ host = "192.168.1.2" } }  shortcuts{ users = "server1/app/users" comments = "server2/app/comments" } }

The above example registers two different database hosts which can then be accessed using the mongo
bean: mongo.server1.<dbname>.<collection>. ‘dbname’ and ‘collection’ will
return the corrisponding Java MongoDB driver equivalents (DB, DBCollection).

Shortcuts

Shortcuts can also be defined to shorten the syntax required to access a collection by registering a
root-level mongo property directly with a collection. For example, in the above
example we mapped the ‘users’ shortcut to “server1/app/users”, which lets us use mongo.users
instead of mongo.server1.app.users.

Shortcuts have the added benefit of making it easier to change your server topology without having to
change your code; if you were to move your users collection to a different server, you would just update
your alias.

Shortcuts will also be used in the future to reference server-pools.

Mapping Domain Objects

The MongoDbWrapper makes it easy to save and restore your Grails domain objects
to a collection by using mappers which convert your domain objects to BasicDBObjects,
and vice-versa.

To register your Domain class with a mapper you need to add two static helper fields
to your class:

class User{ String firstName String lastName  static mongoTypeName = "user" static mongoFields = ['fn':firstName','ln':'lastName'] }

When your objects are converted to documents a property ‘_t’ is added to help identify the type.
This type identifier is specified with mongoTypeName. You then specify which fields
should be saved, and their respective keys.

Domain objects can then be coverted to docs by calling the MOP added method “toMongoDoc()”.

def user = new User( firstName:"mark", lastName:"priatel" ) def userDoc = user.toMongoDoc()

You can also convert documents retured from queries back into their Domain equivilants
using the toObject() method added to BasicDBObject and BasicDBList (via MOP):

mongo.users.find().each{ doc -> def userDomainObject = doc.toObject() }

The mapper will also process mapped properties and Lists:

class Address{ String city String country  static mongoTypeName = "address" static mongoFields = [ 'ci':'city' , 'co' : 'country' ] }  class User{ String firstName String lastName Address address  static mongoTypeName = "user" static mongoFields = ['fn':firstName','ln':'lastName','adrs':'address'] }  def adrs = new Address( city:'ottawa' , country:'canada' ) def user = new User( firstName:'mark', lastName:'priatel',address:adrs)  mongo.users.save( user.toMongoDoc() )  (bson) { "_id" : ObjectId("4b952284d8e992502c9629e3"), "_t" : "u", "fn" : "mark", "ln" : "priatel", "adrs" : { "_t" : "a", "ci" : "ottawa", "co" : "canada" } }

Of course, you can still save your domain objects using GORM.

def user = new User( firstname:"mark" ) user.save() mongo.users.save( user.toMongoDoc() )

MongoDB Document Builder

The mongo bean exposes a special root-level property ‘doc’ which can be used to create
BasicDBObjectS (which are used by the Java driver to represent MongoDB documents) using a
Groovy builder syntax:

def userData = mongo.doc{ firstName("mark") lastName("priatel") company("iolog") address{ city("ottawa") country("canada") } }  mongo.user.save(userData)  println userData._id

-

 

Posted via email from Matthew Sloan Wallace

June 24, 2010

Fix for break points, line numbers, and other UI bugs in Eclipse on OS X

There are a number of small bugs with Eclipse on OS X that you may run into from time to time. Some of the biggest ones that I have seen are line numbers not showing up in the code editor, break points not showing, line numbers not scrolling when you scroll the code window, errors not showing in the code editor and a host of other small things like this with the UI.

This mainly takes place when I go from having a duel display environment to unhooking my laptop from the external monitor or vice versa. Use too think the the only fix for this was restarting OS X after I make the switch from one setup to another but passing an argument to eclipse when it startes up seems to do the trick. Restarting Eclipse is way faster than having to restart OS X.

Here is what you do:

  1. close Eclipse if it is open
  2. open up a terminal window … (if you don't know what terminal is then you may not really be a developer)
  3. execute Eclipse from terminal and pass it the "clean" argument like so  
$ /Applications/eclipse/eclipse -clean

If eclipse is installed somewhere else on your system then naturally you will need to use the proper path to get to the eclipse directory.

Posted via email from Matthew Sloan Wallace

Setting a spark Window x and y on screen

I am starting to do a lot more AIR development and found something that baffled me a bit the other day. I am creating new Windows in my AIR app and I wanted to create the window and then have it open on screen where I would like. An example of this is I have a window that acts like a menu for my app so I wanted the window I create to open at 4px on the Y and 25px on the Y.

 
You would think it would be a easy as doing the following:
 
 
var mywindow:Window = new Window();
mywindow.x = 4;
mywindow.y = 25;
mywindow.open();
 
However this does not work as you would expect. This was a bit lame if you as me and the answer was not obvious unless you have doen a lot of AIR development and know what I am about to say. You have to listen for the window open to complete and then call the move() function and pass it the x and y for this to work. 
 
Checkout the following code:

protected function creationCompleteHandler(event:FlexEvent):void
{

var mywindow:Window = new Window();
 
mywindow.addElement( workingSets );
mywindow.width = 115;
mywindow.height =200;
mywindow.maximizable = false;
mywindow.resizable = false;
mywindow.addEventListener(AIREvent.WINDOW_COMPLETE, onWindowComplete);
.open();
}
 
private function onWindowComplete(event:AIREvent):void
{
event.currentTarget.move(4,25);
}

Posted via email from Matthew Sloan Wallace

Create a ToggleButton Menu / Bar in Flex 4

In Flex 4 you have the ability to use the mx components or the new spark components. I started a project the other day and wanted to use a ToggleButtonBar and noticed the only on available was the mx component. Spark does come with a toggle button but it is a single button. Also I wanted to be able to use the ToggleButtonBar as a vertical menu and the mx component, to my knowledge, only lays out horizontally, and extending that component to get it to layout vertical just seemed like to much of a pain.

 
After thinking about the issue for a moment I dove right in and here is the resulting code that I came up with.
 

package com.mswallace.components.menus { import flash.events.FocusEvent; import flash.events.KeyboardEvent; import flash.events.MouseEvent;  import mx.collections.ArrayCollection; import mx.collections.ArrayList; import mx.events.FlexEvent;  import spark.components.Group; import spark.components.ToggleButton;  public class ToggleMenu extends Group {  public function ToggleMenu() { super(); this.addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete); }  private function onCreationComplete(event:FlexEvent):void { this.addEventListener(FocusEvent.FOCUS_IN, onFocusIn); }  private function onFocusIn(event:FocusEvent):void { this.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown); }  private function onKeyDown(event:KeyboardEvent):void { trace(event.keyCode); }   private function createMenu():void  { if(this.numChildren > 0) this.removeAllElements();  for (var i:String in toggleButtons)  { var value:String = toggleButtons.getItemAt(int(i)) as String;  var toggleButton:ToggleButton = new ToggleButton(); toggleButton.label = value; toggleButton.id = 'bn_' + value; toggleButton.addEventListener(MouseEvent.CLICK, onClick); this.addElement(toggleButton);   }  //this is optional code to select the first item  }  private function onClick(event:MouseEvent):void { if(event.currentTarget.selected == false) { event.currentTarget.selected = true; selectedIndex = this.getChildIndex(event.currentTarget as ToggleButton); }   for(var i:int=0; i< this.numChildren; ++i ) { var button:ToggleButton = this.getElementAt(i) as ToggleButton; if(event.currentTarget != button) button.selected = false; } }  ///////// vars \\\\\\\\\\\\  //array of string values that is passed in to create the buttons private var _toggleButtons : ArrayCollection; public function get toggleButtons():ArrayCollection { return _toggleButtons; }  public function set toggleButtons( value : ArrayCollection ):void { _toggleButtons = value;  if(value != null && value.length > 0) createMenu(); }  //selected index private var _selectedIndex:int; public function get selectedIndex():int { return _selectedIndex; }  public function set selectedIndex(value:int):void { _selectedIndex = value; }    } }

 
Here is the component implemented in MXML after creating the Actionscript Class.
I only did this so that I could control the layout in mxml tags but you could also implement the layout in the Actionscript class if you like.
I tend to follow a “code behind” method when creating some of my components.
 

<?xml version="1.0" encoding="utf-8"?> <menus:ToggleMenu xmlns:menus="com.mswallace.components.menus.*" xmlns:fx="http://ns.adobe.com/mxml/2009"  xmlns:s="library://ns.adobe.com/flex/spark"  xmlns:mx="library://ns.adobe.com/flex/mx">  <menus:layout> <s:VerticalLayout /> </menus:layout> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations>  </menus:ToggleMenu>

Posted via email from Matthew Sloan Wallace

Improve your compile time in Flash Builder / Eclipse on OS X

With out getting into a long explanation. If you feel like compiling your Flex or Actionscript project on OSX takes forever do the following and I am pretty sure you will notice an improvement. This is most noticeable on large projects with lots of files. 

Start System Preferences, select the Spotlight icon, then the Privacy tab, then click the Add button (“+”) and find your workspace directory that your projects are in the dialog that appears, or you could just open finder and drag the directory into the window.

Posted via email from Matthew Sloan Wallace

February 5, 2010

Learn Actionscript 3 and FDT for free. Limited time!

The Rich Media Institute rocked my February by providing these excellent online training for *FREE*! Response fast though; this is a limited time offer!

If you have been wanted to get started with Actionscript 3 or need a refresh the jump right in. Also FDT is a great coding enviroment for Actionscript and Flex development. The are offering an intro to using FDT for your development.

I recommend that no matter who you are you check out both of these video tutorials.

Introduction to ActionScript Development with FDT

Free through February!
http://www.richmediainstitute.com/catalog.php?item=70

Comprehensive ActionScript 3

Free till February 15th!
http://www.richmediainstitute.com/catalog.php?item=72

September 13, 2009

Setting up Flash Media Server on OS X with VirtualBox

After doing some Red5 development over the last year I am have recently started working with Flash Media Server 3.5. One of the unfortunate things about Adobe’s product is that they do not have an OS X version of the server. Not to worry. If you are on a Mac (Intel Only) then just do the following.

1. Download VirtualBox (free from Sun) and install Windows or Linux. If you go with Windows I would suggest XP. It runs really fast even for running in VirtualBox and it does not seam to hit the processor quit as hard. If you go with Linux then I would suggest CentOS. We are not going to cover getting the OS installed.

Screen shot 2009-09-13 at 8.56.41 PM [ September 13 ]

2. After you get your new OS up and running you need to open a web browser in the OS that you installed and download and install the latest version of Flash Media Server.

3. Finally you need to allow OS X to see the IP address of the VirtualBox so that you can access FMS Server. By default VB’s network adapter is set to NAT so basically it keeps OS X from being able to see it. Close down your OS so that you can make some changes. Make sure you choose power off. Now right click on the OS in VB and choose settings > network icon > under Attached To drop down change it to “Bridged Adapter”  and then click OK and restart your OS.

Screen shot 2009-09-13 at 9.12.52 PM [ September 13 ]

4. Now all you need is the IP address to the VB guest OS. If you go with running windows then that is as easy as opening a command prompt window and typing ipconfig.

Screen shot 2009-09-13 at 8.56.41 PM [ September 13 ]

5. Now you should be able to launch the FMS Admin swf and use it to connect to your newly running FMS server.

Screen shot 2009-09-13 at 9.21.40 PM [ September 13 ]

August 28, 2009

Speaking of Recruiters

As a Developer and a User Group manager I have encountered my share of “pimps” AKA recruiters. Now to be fair all recruiters aren’t douchbags. To name a couple Scott Gordon and Tiffany Jennings are two excellent examples of recruiters that do there job well and know how to work with someone to find them the best development position they can.

What’s this all about?
In the next week or two Sept 23rd, I have been given the opportunity to speak at a recruiter “lunch and learn”. Now I am not one to speak at something like that unless it is a Flash or Flex event but one thing that I have been trying to do is help bring the talented developers and talented recruiters together so I am taking it for what it is. It’s a great opertunity to layout “our” thoughts as developers and bridge the gap. I have been given up too a 30min spot to speak. Not sure I can fill that much time but there will be some Q/A that should be cool.

Where do you come in?
What I would like to do is get your honest comments below, of things you would like recruiters to know that would make the relationship better. Also feel free to share the good, bad and ugly experiences that you have had. This is all about laying it out there so that everyone can learn and hopefully help each other out.

So it’s up to you. Post your comments now. I will use them in my talk! I need your experiences, thoughts and suggestions from a developers perspective toward recruiting and what would make it better or even if you think it can’t be made better let me know your thoughts and I will do my best to make it heard.

August 22, 2009

Thoughts on Open Screen Project and iPhone

I was reading a blog post on Effective UI blog and I started to leave a comment and I relized my comment was pretty much turning into a blog post so figured I would just post my thoughts on the matter here.

Here is the Effective UI post that I was starting to comment on.

As a Flash Developer myself I would love to see the flash player come to iphone. Now the question remains to be seen if Apple should actually play nice and join the open screen project. Why have they not done this? I am guessing it has to do with the value of the App Store. If Flash developers could bring games to the phone the I guess it would be some loss in sales but I really don’t see that happening.

In regards to the App Store …. Apple could bring a tone of developers to the phone to sell more apps if they would some how work out a way for flash developers to build games that could be sold on the app store. Just a thought I had, as I myself start learning iphone development. I keep wishing I could just write AS3, a language that I have spent a tone of time learning and becoming really good at. Some of the other things that would be wonderful would be to just be able to view Flash content on a web page and not get the damn missing plugin icon in safari on the phone.

What I do know is a couple of things. Apple is a very innovative company, but sometimes we have to think “WTF” and scratch your head at things Apple does. “Why are they doing what they are doing?” Safari on the phone runs extreamly well and they built it to run web standard code like know other mobile browser. To not include support for a plugin that corners the market with an astonding 98.8% penetration for Flash Player 9 and 86.7% for Flash Player 10 seems pretty lame to me to leave that out for this long as they have. Expecially when you have a company like Adobe who is ready willing and able to work with Apple to make the improvemnts needed to the player to get it “iPhone worthy”.

I truly believe that Apple has the best intentions to supply their costumers with the best experience using both innovative hardware and software. I am sure Adobe is doing all they can too make mobile experiences better for everyone. Over the last few years we have seen there products become better and better when they have taken the lead to work with the community and other companies to make there technology better and has truly made platforms like Flash a world wide standard. I wish that apple would get on board. I guess we will just have to see.

I truly feel that iPhone and the SDK is taking mobile development by storm and it is a great way to go if you want to become a mobile developer and I also feel just as strong about Flash Player. It is installed and used on more devices than any other plugin technology in the world. My personal openion is that Flash Player will become more used and just as powerful if not more powerful than Sun Microsystems JVM. We are starting to see this with other technologies from Adobe. Namely Adobe AIR. I know we will continue to see great things from Adobe and Apple and as a Developer I am excited to see these things evolve. I only ask that companies like Apple and Adobe continue to do their best to listen to there customers and bring our thoughts and talent into the evolutions of there products as well.