Tuesday 11 September 2012

Checking for Null or Empty or White Space Only String in Java

/**
 * Demonstrate checking for String that is not null, not empty, and not white
 * space only using standard Java classes.
 *
 * @param string String to be checked for not null, not empty, and not white
 *    space only.
 * @return {@code true} if provided String is not null, is not empty, and
 *    has at least one character that is not considered white space.
 */
public static boolean isNotNullNotEmptyNotWhiteSpaceOnlyByJava(
   final String string)
{
   return string != null && !string.isEmpty() && !string.trim().isEmpty();
}


Refer:
http://marxsoftware.blogspot.in/2011/09/checking-for-null-or-empty-or-white.html

Struts2 Date Format

<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Struts 2 Format Date Example!</title>

<link href="<s:url value="/css/main.css"/>" rel="stylesheet"
type="text/css"/>

</head>
<body>


<s:form action="FormatDate" method="POST">


<tr>
<td>Date in (yyyy-MM-dd) Format:</td>
<td>
<b><s:date name="todayDate" format="yyyy-MM-dd" /></b>
</td>
</tr>

<tr>
<td>Date in (MM/dd/yyyy hh:mm AM/PM) Format:</td>
<td>
<b><s:date name="todayDate" format="MM/dd/yyyy 'at' hh:mm a" /></b>
</td>
</tr>

<tr>
<td>Date in (dd-MMM-yyyy hh:mm AM/PM) Format:</td>
<td>
<b><s:date name="todayDate" format="dd-MMM-yyyy 'at' hh:mm a" /></b>
</td>
</tr>

<tr>
<td>Date in (dd/MM/yyyy hh:mm) Format:</td>
<td>
<b><s:date name="todayDate" format="dd/MM/yyyy hh:mm" /></b>
</td>
</tr>

<tr>
<td>Nice Format:</td>
<td>
<b><s:date name="todayDate" format="yyyy-MM-dd" nice="true"/></b>
</td>
</tr>

</s:form>

</body>

</html>