Monthly Archives: June 2011

Wiki markups – Make simple things simple

With best wishes for sagisou – The weather is not good, hope you are fine and healthy.

wiki,markup,html

If you haven’t edited The Great Wikipedia anytime,  I recommend giving it a try. Since what I discuss here is related closely to them.

This is the story of Wiki markup language.

For a long time studying at university, I always wonder how people can build such complex architecture like .NET Platform, Java, since it took an ordinary student months of learning just to touch the surface. When I began going to work, that fact is reinforced day by day: I almost certain that I don’t fully understand 90% of the libraries used in my projects. “Just believe the creators and use them – you are only big if you stand on giants’ shoulder”. But a question pop out: if mankind continues building such high-level technology pyramid, how long it will take for them to forget the ground?

Enough chit-chatting. When I first come across Wiki-markup, it’s just like another tool out there. I don’t put the question why it is needed, although we already have the HTML, CSS, javascript… I believe such powerful tools can satisfy most the ambitious needs, (with a little dirty hack sometime :p). I never question anything until I have trouble with it, yes, the Wiki Markups.

Most of the syntax is not hard, but some part(especially table) is very very confused! Why they ever make a language like that??

The Wiki Markup Origin

According to Wikipedia, Wiki Markups is the kind of languages which born to ease the normal writers: who don’t need to be a good HTML coders. Well, you may say that HTML is not hard, but the fact is that it’s magic to non-technical guys. In short, a new tool is built to do a simple job, which can be done with current tools instead.

But it’s not the only reason.

The second reason: in Wikipedia (and any other kind of Wiki) – the focus is knowledge, the content, how are they organized, not how they are showed for the eyes. A simple syntax will solve that problem easily, without making too much trash of bad HTML code.

The third reason: the contributors can be anyone, who ranges from a clerk, a free student,… even a blind person, whoever have access to the Internet. If Wikis give them the powerful HTML/CSS/Javascript, not many people can use it. Even if some can use it, many line of HTML code will have severe holes about accessibility. HTML standard contains many strict rules so that the website can be read by a screen-reader for handicapted people, which most websites doesn’t care (If you don’t believe, take any website and go for the w3c HTML validator).

For all those reasons, I think Wiki Markup is a good idea. A good tool helps people do things better than before, and it’s doing a good job.

But it still has much to improve, or I will continuously complain about the marking-up tables.

Put Tomcat in Eclipse

Photobucket

/**

Vietnamese: bài viết hướng dẫn về cách cấu hình để tích hợp Tomcat vào Eclipse

**/

Since most of the step-to-step-guide about this problem (at least the guides I found) are a bit out-dated, I think I had better create a guide here. In fact, this guide is taken from my brothers at Evolus. Special thanks to bro Trương Xuân Tính and bro Lê Hồ Bá Phước for this piece of knowledge and their patience to repeat-and-repeat this damn process for me.

Notice: this guide is not a complete guide, just some kind of a checklist. I’ll add more details over time. Please feel free to ask if there’s something you don’t understand.

0. Download & install Tomcat & Eclipse.

1. Find the Tomcat sysdeo plugin for eclipse. I found a download source here, but the location can change in the future.

2. Install the plugin (taken from the official guide). Extract the plugin file (in my case, its version is 3.3.0). Copy the plugin to:
- “Eclipse_Home/dropins” for Eclipse 3.4, 3.5 and 3.6
- “Eclipse_Home/plugins” for Eclipse 2.1, 3.0, 3.1, 3.2 and 3.3

Plugin activation for Eclipse 3.x :

  • launch eclipse once using this option : -clean
  • if Tomcat icons are not shown in toolbar : select menu ‘Window>Customize Perspective…>Commands’, and check ‘Tomcat’ in ‘Available command groups’

Set Tomcat version and Tomcat home : Workbench -> Preferences, select Tomcat and set Tomcat version and Tomcat home (Tomcat version and Tomcat home are the only required fields, other settings are there for advanced configuration).

This plugin launches Tomcat using the default JRE checked in Eclipe preferences window.

  • To set a JDK as default JRE for Eclipse open the preference window : Window -> Preferences -> Java -> Installed JREs. This JRE must be a JDK (This is a Tomcat prerequisite).
  • The plugin sets itself Tomcat classpath and bootclasspath. Use Preferences -> Tomcat ->JVM Settings, only if you need specific settings. Often, I set the variable -Denv=dev to use different config file for development & production.

3. Finalize

Go to the plugin folder, you will see 2 files: “DevLoader.zip” & “DevloaderTomcat7.jar”. As their name implies, you will use “DevLoader.zip” for Tomcat with version less than 7, and “DevLoaderTomcat7.jar” for Tomcat 7.

  • If you are using Tomcat 7, copy “DevloaderTomcat7.jar” to <TOMCAT_HOME>/lib
  • If you are using other Tomcat 6, rename “DevLoader.zip” to “DevLoader.jar”, then put it in <TOMCAT_HOME>/lib.

Create a web project (I’m using Maven to manage the builds). Go to the properties of your project, go to “Tomcat/Class Loader/”, un-check “servlet-api.jar” and other libraries that are already provided by Tomcat. This is for preventing conflicts among duplicate libraries.

Also in “Project/Properties”,  set the context name and web application root. Context name is the name that you use to access the web-app, for example, if the context name is “test”, your server url may be like: “localhost:8080/test/”. Web application root is the place you put your web-application (it’s the folder that contains WEB-INF folder, often named webapp).

If you are using Maven, remember, all these eclispe settings will be removed if you do “maven eclipse:clean”, so don’t use that command unless you want to do config again. Only use “maven eclipse:eclipse” instead.

That should complete the task. Good luck!

Reference: http://www.eclipsetotale.com/tomcatPlugin.html

Annotation Validation in Spring Framework 3

/* Vietnamese: bài viết hướng dẫn một cách ngắn gọn cách thực hiện kiểm tra điều kiện của đối tượng (validation) bằng cách dùng ký hiệu (annotation) với Spring Framework */

Validation is not a problem in Spring Framework, at least, by the normal way.

But the “Validation by Annotation” is not that popular, since this utility was only available from Spring 3. Up to now I found no resource which give a short & comprehensive tutorial yet (at least to this time – 05/2011)

How to make annotation validation works in Spring Framework 3

1. Configure Maven to include Hibernate Validator

2. Setup default validator bean in config file:
[sourcecoce language="xml"]
<bean id=”validator” class=”org.springframework.validation.beanvalidation.LocalValidatorFactoryBean” />
[/sourcecode]

3. Add @annotation

Let’s see what is annotation validation in its action:

public class User implements Serializable {
        private long id;
        @NotNull(message=&quot;{user.name.notnull}
        @Length(max = 255, message=&quot;{user.name.length}&quot;)
	private String username;
	public void setUsername(String name) {
		this.username = name;
	}
	public int getUsername() {
		return username;
	}
}

Code for the controller:

@Controller
@RequestMapping(&quot;/administration/*&quot;)
public class AdministrationController {
    /**
     * For every request for this controller, this will
     * create a user instance for the form.
     */
    @ModelAttribute
    public User newRequest(@RequestParam(required=false) String id) {
        return (id != null ? userService.getUserById(id) : new User());
    }

    @RequestMapping(value=&quot;/editUser&quot;, method=RequestMethod.GET)
	public final String edit(@Valid User user, BindingResult result) throws Exception {

		if (user == null) {
			return &quot;redirect:/administration/manageUser&quot;;
		}

		return null;
	}

	@RequestMapping(value=&quot;/editUser&quot;, method=RequestMethod.POST)
	public final String updateUser(@Valid User user, BindingResult result) throws Exception {

		if (result.hasErrors()) {
			return null;
		}

		userService.updateUser(user);

		return &quot;redirect:/administration/manageUser&quot;;
	}
}

And in the end, for the jsp:

&lt;/pre&gt;
&lt;h1&gt;Edit Site User&lt;/h1&gt;
&lt;div&gt;
&lt;fieldset&gt;&lt;legend&gt;Edit Site User&lt;/legend&gt;
 &lt;input type=&quot;hidden&quot; name=&quot;userId&quot; value=&quot;${user.id}&quot; /&gt;
				&lt;p&gt;
					&lt;form:label for=&quot;id&quot; path=&quot;id&quot;&gt;Id&lt;/form:label&gt;
					&lt;br /&gt;
					&lt;form:input path=&quot;id&quot; readonly=&quot;true&quot; /&gt;
					&lt;font color=&quot;red&quot;&gt;&lt;form:errors path=&quot;id&quot; /&gt;
					&lt;/font&gt;
				&lt;/p&gt;
				&lt;p&gt;
					&lt;form:label for=&quot;username&quot; path=&quot;username&quot;&gt;User Name&lt;/form:label&gt;
					&lt;br /&gt;
					&lt;form:input path=&quot;username&quot; readonly=&quot;true&quot; /&gt;
					&lt;font color=&quot;red&quot;&gt;&lt;form:errors path=&quot;username&quot; /&gt;
					&lt;/font&gt;
				&lt;/p&gt;
&lt;/fieldset&gt;
&lt;/div&gt;
&lt;pre&gt;

Every tool has its cost

tools,eclipse,ide,web-development

For such a fairly long time I haven’t written anything. Not because I don’t have anything to write, but it’s hard to pull complex things out of my head. But now it seems to be time for a warm-up :)

One of my senior, Mr An, has a favorite sayings: “Until you don’t depends on tools, you are not truly a developer.”

Truthfully, I don’t think I have fully understand what he means. A developer with more than 10 years in this industry may have a different view to a young one like me. But to some extent, it seems to be a good idea.

For a certain amount of time I have tackled Maven, Spring Framework, Java Serverpage, Freemarker… I end up spending most of the time trying to fix bugs, caused not only by the framework, but also by mis-configuring Eclipse & its plugins. To be honest, it’s annoying

Actually, Eclipse is such a good tool: nearly everything you think that a good IDE should have, it exists in this free solution: refactoring, navigation, source-control-supported, Maven-tools… Such many functions integrated in a single program. Pretty handy, isn’t it?

But here a problem arise: when you have too much utilities, it will be hard to have a meaningful organization. It make me frustrated when right-click in Eclipse and have a 20-items context menu pop up. Still, navigating through that menu isn’t as hard as understand why and how to use the Eclipse view, explorer, hot key, configuring it to auto-compiling… Those are also the things you need to know to speed the work up. As far as I know, there’s no simple coherent way to do all the tasks.

The same semaphore also applies to any of our developer tools, no matter if it’s an IDE, framework, libraries… or even, methods. In my view, the best tool is a tool with few familiar functions, so that we can easily master and get the best results with minimal efforts. But the fact is that, as long as people want to stuff their tools out to fit everyone needs, that goal is hard to meet.

You must master a tool before you can make it work for you, so there’s a hidden cost. Imagine, if a tool doesn’t allow you work 2 times faster, do you spend 2 weeks to master it, just for use in a 1-month project?

Let’s choose and use tools wisely.