Saturday, March 8, 2014

Grails : UnknownHostException at startup


I had the following error when starting Grails project :

| Error 2014-03-08 20:54:41,199 [localhost-startStop-1] ERROR [localhost].[/toolprod]  - StandardWrapper.Throwable
Message: IO Exception: "java.net.UnknownHostException: blopux: blopux: Nom ou service inconnu" [90028-173]


To solve my problem, I had the hostname in /etc/hosts :

127.0.0.1   blopux        localhost

Sunday, February 16, 2014

firefox plugin


Recently, I wanted to learn how to make firefox plugin.To do that,  I followed the official firefox tutorials: https://developer.mozilla.org/en-US/Add-ons/Overlay_Extensions/XUL_School
I was simple and quicly I obtain a result.
So, if you want to see from curiosity a firefox plugin, you can see my GitHub project : https://github.com/drieu/checker.

Tuesday, January 7, 2014

How to add a sitemap in my Grail war application ?

Today, I decided to add a sitemap for my new Grail website.First of all, I generated one by using online sitemap generator. For example, there is the following http://www.xml-sitemaps.com . You have to put your website url and it will produce sitemaps files (xml, zip, and so on). Here is an example of sitemap :
<?xml version="1.0" encoding="UTF-8"?>
<urlset
      xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<!-- created with Free Online Sitemap Generator www.xml-sitemaps.com -->

<url>
  <loc>http://opendoowap-totalprog.rhcloud.com/</loc>
</url>
<url>
  <loc>http://opendoowap-totalprog.rhcloud.com/page/training</loc>
</url>
<url>
  <loc>http://opendoowap-totalprog.rhcloud.com/page/about</loc>
</url>
<url>
  <loc>http://opendoowap-totalprog.rhcloud.com/page/under</loc>
</url>
<url>
  <loc>http://opendoowap-totalprog.rhcloud.com/page/website</loc>
</url>
</urlset> 

Then, I download the file sitemap.xml and I paste it in the web-app directory of my Grails application.After that, I modified my BuildConfig.groovy like the following :

grails.war.copyToWebApp = { args ->
    fileset(dir:"web-app") {
        include(name: "js/**")
        include(name: "css/**")
        include(name: "fonts/**")
        include(name: "images/**")
        include(name: "WEB-INF/**")
        include(name: "sitemap.xml")
    }
}
To finish, I run grails war command and deploy it in Tomcat web container.
That's all. Now, your sitemap is available in http://your.app.com/sitemap.xml and you can add for example to google webmaster tools.




Thursday, January 2, 2014

Grails meta tag and internationalization

If you used Grails with internationalization, you knew the use of <g:message> but how to use it in Meta tag content description ?
Here is how :

<meta name="description" content="${message(code:'index.goal')}" />


Thursday, December 26, 2013

Problem while deploying ROOT.war on Openshift Tomcat application

I had a problem when I deployed  my war on Tomcat in OpenShift cloud.
It always takes OpenShift's ROOT.war and not the ROOT.war I had copy in the webapps directory.
It's because when you make git push, it runs a mvn command or in my case, I don't want to build my project but only deploy a single war file.
To solve this problem :

- Delete src/ directory
- Delete pom.xml


Thursday, December 19, 2013

Bootstrap add active class to li

In the following example, we use a classic Bootstrap menu.Note that, none li had a class active.We will use after.
    <div class="navbar navbar-default span12" role="navigation">
            <...>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li><a href="/fjLearning/"><g:message code="menu.home" /></a></li>
                    <li><a href="/fjLearning/page/training"><g:message code="menu.training" /></a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown"><g:message code="menu.about" /> <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            <li><a href="/fjLearning/page/about"><g:message code="menu.about.perso" /></a></li>
                            <li class="divider"></li>
                            <li class="dropdown-header"><g:message code="menu.about.site" /></li>
                            <li><a href="/fjLearning/page/under"><g:message code="menu.underTheHood" /></a></li>
                            <li><a href="#">FAQ</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
    </div>

To make it works you have in each page to add :
<body>
<script>
    $(document).ready(function() {
        $('a[href="' + this.location.pathname + '"]').parent().addClass('active');
    });
</script>
...

Now, when I clicked on the menu, the link active changes automatically. If you want to see an example, go on my GittHub project : https://github.com/drieu/fjLearning

Here is the usefull files :
https://github.com/drieu/fjLearning/blob/master/grails-app/views/layouts/_menu.gsp
https://github.com/drieu/fjLearning/blob/master/grails-app/views/page/training.gsp

Sunday, December 15, 2013

Bootstrap : span doesn't work

I tried this simple Bootstrap row without success :

<div class="row" style="border: 1px solid green">
        <div class="span2" style="border: 1px solid red">Foo!</div>
        <div class="span2" style="border: 1px solid red">Bar!</div>
        <div class="span2" style="border: 1px solid red">Baz!</div>
        <div class="span2" style="border: 1px solid red">Foo!</div>
        <div class="span2" style="border: 1px solid red">Bar!</div>
        <div class="span2" style="border: 1px solid red">Baz!</div>
</div>

In fact, it's simple.I used Bootstrap 3.x and not Bootstrap 2.x which contains some change in class names.
For example, span-* became col-md-*.

So the solution, for this example above :

<div class="row" style="border: 1px solid green">
        <div class="col-md-2" style="border: 1px solid red">Foo!</div>
        <div class="col-md-2" style="border: 1px solid red">Bar!</div>
        <div class="col-md-2" style="border: 1px solid red">Baz!</div>
        <div class="col-md-2" style="border: 1px solid red">Foo!</div>
        <div class="col-md-2" style="border: 1px solid red">Bar!</div>
        <div class="col-md-2" style="border: 1px solid red">Baz!</div>
</div>

See following link for details :
http://getbootstrap.com/getting-started/#migration
http://stackoverflow.com/questions/18527466/twitter-bootstrap-span-columns-not-displaying-correctly/18527554#18527554