Latest Entries »

Wednesday, March 28, 2012

Tool that every developer should know

Introduction

Today I'll discuss about things that make our work effortless and bring to us tools that your IDE won't give you. I can bet that in your workshop you use Visual Studio, SQL Managment Studio or NetBeans, Eclipse etc... but there is a whole bunch of tools that they are so helpful and when you find them you cannot live without using it. I'll introduce my list of software that is really helpful for me and you can check some of them if you didn't heard about it. Of course all is freeware.


LINQPad

How many times did you spend when you want to check small chunk of your code and see what it print out? Or you want to visualize some of your Linq Queries? This tool did a real impact on my and how to test small stuff. From time when I started using LINQPad I realize that I don't need debugger so often and I run my code inline.



Expresso

I had always know that regular expression are powerful tool build in all programming languages but I hadn't opportunity to learn them from scratch. Even tutorials across web doesn't seem to be nice because there were whole of theory and I want test my expression in practise. With regex developer can do a lot of stuff and I used them but I was just copying rules from regular expression database websites for my purposes and I didn't use them on my own. Nevertheless that day come and I find Expresso. Great tool for visual building expression, testing them without any problems. Now when I come across many common tasks (text replacing from SQL queries, writing some logs, replacing Strings in my code, using Validation) I saw that I can do two thing. First learn some more and finally I solve my problems more in more sophisticated way. In every detail I recommend this program for everyone.




Notepad++

Yes. I know that everybody use it and are familiar with this program. But did you explore most of assistance that come with Notepad++ ?

  • With ALT + SHIFT + ARROWS you have Column Mode Selection,
  • With regular expression you can replace everything you need
  • You can jsbeautify/js.minify your javascripts with JsMin plugin
  • You can execute all commands with NppExec 
  • You can see json files hierarchically
  • More stuff is inside all of available plugins



Code compare

In this category you propably have your own best software. I had simple but very useful called WinMerge for a long time. Once I had more time I started to looking for software for comparing files and finally found one which is my top 1 in source comarision. Code Compare by Devart exceeded my expectations. This program show file diffrences like in modern comparision tools, it has Visual Studio plugin for inline IDE comparision and last very handy feautre: Integration with Explorer. You can choose two diffrent files selecting 'Select left', 'Select right' and then compare those files without any waste of time. This software has great support for merging files with '3 window comparision' feature.




PowerShell and PowerGUI


When I realized that all tasks in work doesn't fire google and I've got all in my head I sadly found I did not learn anything new. In meantime I've got task for analyze logs made by my application to check whether some code is bugged. Finally I despite cmd.exe and love unix bash! Quick serching over web and I found. I can learn one more script language which is strongly connected with .NET and automates routine taks and thus bring some coding entertainment. I've started with some simple scripts and now I get one important thought. Everything you thought is difficult or impossible you can do with PowerShell scripts!. After some scripts in Notepad++ I was searching for powerfull "IDE" for PowerShell. God hear my prays and I found PowerGUI. Again I found amazing tool which is one of secret weapon.




SQL Search

While you are implementing your enormous project and you use stored procedures, sql functions and other sql objects? One day you look inside stored procedures and whisper to yourselve "Where the hell that procedure is? I can't find it!". So am I. Working in one company my friend gave mi a link to SQL Search plugin for Managment Studio. That was awesome shot! I found tool for finding stored procedure by name. Moreover I could find even search inside body of sql objects?!?! No more headache when I had to modify some sql statements! Gloria !!




Open DBDiff

As far as SQL database cannot be versioned by Source Control System a'la Subversion I had nightmares when came to moving procedure changes between testing and production environment. Previously I had chance to synchronize database using Visual Studio Ultimate which had great SQL Schema/Data Comparision tool but when I moved to new company I was on my own. I've been saving all modified sql procedures to file system but when I simply forgot some of procedures? Customer will be calling and I will get headache fixing all bugs? Of course no. I could use Open DBDiff and check what did changed between test and production and I can generate script for this! What a relief ...





ClipX

This program is dedicated for everyone (including me) who had a chance to copy/paste, copy/paste lot of code, copy/paste log information, copy/paste, copy/paste, copy/paste lot of code, copy/paste, copy/paste, copy/paste another code, copy/paste another code, copy/paste log information and simple CTRL + C and CTRL + V is not enought. With ClipX you have clipboard with 25 or 50 items, you can search across clipboard pastes and you can pate each item you wish copying it just once! This is really handy tool when you work with many projects or between documents when you need to copy/paste, copy/paste, copy/paste some of your previous code.




soapUI

Did you have occasion debugging SOAP WebServices? Did you get nuts when you get insane when you receive WSDL file and ask yourseve: Why it's not working?. Maybe you was looking for some bugs across sent XML reqest or responses? For me each question is answered YES. I had problems with SOAP when was working with some WebServices. Earlier when I didn't know about soapUI I was receiving all traffic via Fiddler but it was like torture. Finding one request beyond all network traffic... This software is perfectly written because you have all you want and all you need in one.



luke


Long time ago when I had task to improve e-commerce searching engine. Meanwhile SQL Server 2008 doesn't support my native full text search I found Lucene.NET engine. Everything would be good except one thing. Testing my new improvement was total nightmare. I couldn't just write piece of code, run debugger and check if proper search query was build and then repeat this approach. So I ask uncle google for help and he suggested me luke (Lucene index browser). From that moment I could see structure of Documents, execute queries against full text index and in result improve my software better and faster.



If you read this article and found useful or you got software to share please leave a comment.

Monday, March 12, 2012

JavaServer Faces website navigation map with Primefaces


Introduction


Hello. In this article I will show you how to create a simple website navigation map like those in asp.net (web.sitemap) which contains reference to your pages. Composite Component of navigation path will be localized on many languages and will be build on PrimeFaces BreadCrumb component. Final result will look like this:

Using PrimeFaces

Configuring PrimeFaces is as easy as riding a bike so I ommit this topic.
I'll create JSF 2.0 Composite Component with BreadCrumb inside and point it's dynamic model to ManagedBean which will use our newly created CC component.

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:cc="http://java.sun.com/jsf/composite"
      xmlns:p="http://primefaces.org/ui">

  <!-- INTERFACE -->
  <cc:interface>
      <cc:attribute name="model" required="true" />
      <cc:attribute name="styleClass" required="false" />
      <cc:attribute name="style" required="false" />
  </cc:interface>

  <!-- IMPLEMENTATION -->
  <cc:implementation>
      <p:breadCrumb styleClass="#{cc.attrs.styleClass}" style="#{cc.attrs.style}" model="#{cc.attrs.model}">
        </p:breadCrumb>
  </cc:implementation>
</html>

Implementing code for receive pages in project


Now it's time for ManagedBean holding all data. Most significant piece of code from class below is localized in public getWebsites(). Firstly I load localized messages and load filenames from root path "/". Next step is checking whether filename exists in localized messages:

package com.blogspot.rpiesnikowski.root;

import java.io.File;
import java.lang.String;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
import javax.faces.component.UIForm;
import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FileUtils;
import org.primefaces.component.menuitem.MenuItem;
import org.primefaces.model.DefaultMenuModel;
import org.primefaces.model.MenuModel;

/**
 *
 * @author rpiesnikowski
 */
@Named(value = "template")
@RequestScoped
public class TemplateBean {
    private MenuModel websites;

    /**
     * Method for dynamically create navigation for all pages inside
     * root directory.
     * @return
     */
    public MenuModel getWebsites() {
  // Receiving i18n bundle messages 
        String bundleName = "locales.messages";
        String Name = "";
        Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
        ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale);
        websites = new DefaultMenuModel();
        HttpServletRequest req =  (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        // Getting all files for path and then using Apache Commons 
  String rootPath = req.getServletContext().getRealPath("/");
        Collection<File> files = FileUtils.listFiles(new File(rootPath),new String[]{"xhtml"}, false);
        websites.addMenuItem(createMenuItem("#", "#"));
        for (File f: files){
            Name = f.getName().replace(".xhtml", "");
   // Checking if localized messages has key 
            if(bundle.containsKey(Name))
                websites.addMenuItem(createMenuItem(bundle.getString(Name), f.getName().replace(".xhtml", ".jsf")));
        }
        return websites;
    }

    public void setWebsites(MenuModel websites) {
        this.websites = websites;
    }

    protected MenuItem createMenuItem(String Name, String Url) {
        MenuItem item = new MenuItem();
        item.setValue(Name);
        item.setUrl(Url);
        return item;
    }
 
    public TemplateBean() {
    }
}

Now it's time to use component somewhere in Facelets Template:

<sc:NavigationPath model="${template.websites}" style="width: 99%;" />

Localizing NavigationPath Last but not least thing is to add localization files and modify your faces-config.xml. Put this between application node:

<application>
 <locale-config>
  <default-locale>en-US</default-locale>
  <supported-locale>pl</supported-locale>
  <supported-locale>fr</supported-locale>
  <supported-locale>es</supported-locale>
 </locale-config>
 <resource-bundle>
  <base-name>locales.messages</base-name>
  <var>msgs</var>
 </resource-bundle>
</application>

And it's time for localized message:

Calendar=Calendard a'la France
AjaxEngine=AjaxEngine a'la France
index=Index a'la France
DummyPage=DummyPage a'la France
BreadCrumb=BreadCrumb a'a France
asdf=asdf a'la France
ClientIdExample=ClientId a'la France

Additional tip

I've found really nice trick when I put my all empty localized messages into project. Try right click over messages.properties and choose Open. You this nice GUI form for filling localized strings.