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ă, 6 septembrie 2015

[OmniFaces utilities 2.0] Concatenate the string representation of the given objects


[OmniFaces utilities] The concat() concatenate the string representation of the given objects.

Function:
Usage:

In order to highlight the OmniFaces of:concat() function let's suppose that we have the following two objects (Foo and Buzz):

public class Foo implements Serializable {

 private String foofat;
 private String fooweight;

 public Foo(String foofat, String fooweight) {
  this.foofat = foofat;
  this.fooweight = fooweight;
 }

 public String getFoofat() {
  return foofat;
 }

 public void setFoofat(String foofat) {
  this.foofat = foofat;
 }

 public String getFooweight() {
  return fooweight;
 }

 public void setFooweight(String fooweight) {
  this.fooweight = fooweight;
 }

 @Override
 public String toString() {
  return "Foo is " + foofat + ", and his weight is " + fooweight + "! ";
 }   
}

public class Buzz implements Serializable {

 private String buzzfat;
 private String buzzweight;

 public Buzz(String buzzfat, String buzzweight) {
  this.buzzfat = buzzfat;
  this.buzzweight = buzzweight;
 }

 public String getBuzzfat() {
  return buzzfat;
 }

 public void setBuzzfat(String buzzfat) {
  this.buzzfat = buzzfat;
 }

 public String getBuzzweight() {
  return buzzweight;
 }

 public void setBuzzweight(String buzzweight) {
  this.buzzweight = buzzweight;
 }

 @Override
 public String toString() {
  return "Buzz is " + buzzfat + ", and his weight is " + buzzweight+ "! ";
 }
}

Now, let's test the EL 2.2 concat() function, += EL 3.0 concatenation operator and the OmniFaces of:concat() function for concatenating Foo and Buzz objects string representations:

<c:set var="foobuzz" value="#{(testBean.fooman.toString()).concat(testBean.buzzman.toString())}"/>

<c:set var="foobuzz" value="#{testBean.fooman += testBean.buzzman}"/>

<c:set var="foobuzz" value="#{of:concat(testBean.fooman, testBean.buzzman)}"/>

·         both objects are declared non-null in a managed bean named, TestBean

Foo fooman = new Foo("well-fed", "105kg");       
Buzz buzzman = new Buzz("corpulent", "92kg");

#{foobuzz} - will render in all three cases:

Foo is well-fed, and his weight is 105kg! Buzz is corpulent, and his weight is 92kg!

·         Foo is non-null, Buzz is null

Foo fooman = new Foo("well-fed", "105kg");       
Buzz buzzman = null;

#{foobuzz} - In case of += EL 3.0 operator we will get a java.lang.NullPointerException.
The EL 2.2 concat() function and the OmniFaces of:concat() function will render:

Foo is well-fed, and his weight is 105kg!

Further, let's try to concatenate the properties of the same object (e.g. Foo):

<c:set var="foo" value="#{testBean.fooman.foofat.concat(testBean.fooman.fooweight)}"/>

<c:set var="foo" value="#{testBean.fooman.foofat += testBean.fooman.fooweight}"/>

<c:set var="foo" value="#{of:concat(testBean.fooman.foofat, testBean.fooman.fooweight)}"/>

·         Foo is non-null, but it contains a null property

Foo fooman = new Foo("well-fed", null);       

#{foo} - In case of += EL 3.0 operator we will get a java.lang.NullPointerException.
The EL 2.2 concat() function and the OmniFaces of:concat() function will render:

well-fed

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