My JSF Books/Videos My JSF Tutorials OmniFaces/JSF PPTs
JSF 2.3 Tutorial
JSF Caching Tutorial
JSF Navigation Tutorial
JSF Scopes Tutorial
JSF Page Author Beginner's Guide
OmniFaces 2.3 Tutorial Examples
OmniFaces 2.2 Tutorial Examples
JSF Events Tutorial
OmniFaces Callbacks Usages
JSF State Tutorial
JSF and Design Patterns
JSF 2.3 New Features (2.3-m04)
Introduction to OmniFaces
25+ Reasons to use OmniFaces in JSF
OmniFaces Validators
OmniFaces Converters
JSF Design Patterns
Mastering OmniFaces
Reusable and less-verbose JSF code

My JSF Resources ...

Java EE Guardian
Member of JCG Program
Member MVB DZone
Blog curated on ZEEF
OmniFaces is an utility library for JSF, including PrimeFaces, RichFaces, ICEfaces ...

[OmniFaces Utilities] - Find the right JSF OmniFaces 2 utilities methods/functions

Search on blog

Petition by Java EE Guardians

Twitter

duminică, 26 aprilie 2015

[OmniFaces utilities (2.0)] Check if a String, Collection, Map or Array is empty


[OmniFaces utilities] The isEmpty() method returns true if the given value is null or is empty. Types of String, Collection, Map and Array are recognized. If none is recognized, then examine the emptiness of the toString() representation instead.

Methods:

This method uses the below ones (which can be invoked individually):
Usage:

Testing a String:

String aString = null;
String bString = "";
String cString = "Done!";

import org.omnifaces.util.Utils;
...   
boolean a = Utils.isEmpty(aString);  // true
boolean b = Utils.isEmpty(bString);  // true
boolean c = Utils.isEmpty(cString);  // false

Testing an Object[]:

Object[] aObjectArray = null;
Object[] bObjectArray = new Object[1];
Object[] cObjectArray = {1};

boolean a = Utils.isEmpty(aObjectArray);  // true
boolean b = Utils.isEmpty(bObjectArray);  // false
boolean c = Utils.isEmpty(cObjectArray);  // false

Testing a List:

List aList = null;
List bList = new ArrayList();
List<String> cList = new ArrayList<>();
ArrayList<String> dList = new ArrayList<String>() {
            {
                add("A");
                add("B");
                add("C");
            }
        };

 boolean a = Utils.isEmpty(aList);  // true
 boolean b = Utils.isEmpty(bList);  // true
 boolean c = Utils.isEmpty(cList);  // true
 boolean d = Utils.isEmpty(dList);  // false

Testing a Map:

Map aMap = null;
Map bMap = new HashMap();
Map<String, String> cMap = new HashMap<>();  
Map<Byte, Integer> dMap = new HashMap<Byte, Integer>() {
            {
                put(new Byte("1"), 1);
                put(new Byte("2"), 2);
            };
        };

 boolean a = Utils.isEmpty(aMap);  // true
 boolean b = Utils.isEmpty(bMap);  // true
 boolean c = Utils.isEmpty(cMap);  // true
 boolean d = Utils.isEmpty(dMap);  // false

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

OmniFaces/JSF Fans

Follow by Email

Visitors Starting 4 September 2015

Locations of Site Visitors