background preloader

General

Facebook Twitter

Easier Multi-Field Validation with JSF 2.0. One of the most frequent needs when developing application forms is multi-field validation (or cross-field, but I’m not using this term because when I put it on Google I actually got some post-war pictures).

Easier Multi-Field Validation with JSF 2.0

I’m talking about situations where we need to compare whether an initial date is earlier than an end date or a value is lower than another one. Isn’t it an obvious feature in every business-oriented framework? Not really. Unfortunately, the JSF specification doesn’t support it by default. Therefore, until its latest production release ( JSR 245 – JSF 2.1), JSF did not offer an out-of-the-box multi-field validation feature. I didn’t like any solution I found. In the following example, I check whether an allocated budget is smaller than a budget limit. Step 1: create an attribute in the managed bean for each field to be validated: The attributes below are exclusively used in the multi-field validation. Step 2: create a validation method in the same managed bean for each field. HOW TO: Read a file from jar and war files (java and webapp archive) ? « Haveacafe's Weblog.

HOW TO: Read a file from jar and war files (java and webapp archive) ?

HOW TO: Read a file from jar and war files (java and webapp archive) ? « Haveacafe's Weblog

19 octobre 2008 at 17 h 01 min As many java programmers, i spent hours searching for the "good recipe" to read a txt file from my java archive to configure an application. The config file aren’t available to final users, so it should only help the programmer to configure his webapp, without having an external file / URL to check. Reading a java archive would generally be done using the classloader of the JVM. How to read from a jar file The files you are looking to must be located in a directory named "classes" at the top of your src folder. If you try to open a file outside the classes folder, the classloader will throw a NullException.

InputStream in = new InputStreamReader(FileLoader.class.getClassLoader().getResourceAsStream("file.txt") ); How to read from a war file Here is what the tomcat documentation says about loading your own files shipped within your webapp archive: It works fine ! Happy coding. Lesson: Formatting (The Java™ Tutorials > Internationalization) This lesson explains how to format numbers, currencies, dates, times, and text messages.

Lesson: Formatting (The Java™ Tutorials > Internationalization)

Because end users can see these data elements, their format must conform to various cultural conventions. Following the examples in this lesson will teach you how to: Format data elements in a locale-sensitive mannerKeep your code locale-independentAvoid the need to write formatting routines for specific locales Numbers and Currencies This section explains how to use the NumberFormat, DecimalFormat, and DecimalFormatSymbols classes.

Dates and Times Version note: This Date and Time section uses the date and time APIs in the java.util package. This section focuses on the DateFormat, SimpleDateFormat, and DateFormatSymbols classes. Messages This section shows how the MessageFormat and ChoiceFormat classes can help you solve some of the problems you might encounter when formatting text messages. Java Tip 68: Learn how to implement the Command pattern in Java. Design patterns not only accelerate the design phase of an object-oriented (OO) project but also increase the productivity of the development team and quality of the software.

Java Tip 68: Learn how to implement the Command pattern in Java

A Command pattern is an object behavioral pattern that allows us to achieve complete decoupling between the sender and the receiver. (A sender is an object that invokes an operation, and a receiver is an object that receives the request to execute a certain operation. With decoupling, the sender has no knowledge of the Receiver's interface.) The term request here refers to the command that is to be executed. The Command pattern also allows us to vary when and how a request is fulfilled. In programming languages like C, function pointers are used to eliminate giant switch statements.

Developers accustomed to using function pointers in another language might be tempted to use the Method objects of the Reflection API in the same way. The Command pattern turns the request itself into an object.