Monthly Archives: May 2012

Simple way to convert af:inputText to upperCase,lowerCase,capitalize

Environment (JDeveloper 11.1.2.2.0,ADF Faces)

Sometimes you need to force the user to enter upperCase or lowerCase or capitalize letters for input text component. fortunately, there is an easy way to do this by setting contentStyle of the input text.

  • To enforce the user to enter upperCase text use this style:
<af:inputText label="Label 1" id="it1" contentStyle="text-transform:uppercase;"/>
  • To enforce the user to enter lowerCase text use this style:
<af:inputText label="Label 1" id="it1" contentStyle="text-transform:lowercase;"/>
  • To enforce the user to enter capitalize (InitCap) text use this style:
<af:inputText label="Label 1" id="it1" contentStyle="text-transform:capitalize;"/>

5 Comments

Filed under ADF

How to convert StackTrace to String

Recently we had a requirement in our application that whenever an exception occurred we   need to store all StackTrace elements in the application’s log file. So we need to get a string representation of the  StackTrace.

Starting by searching in java.lang.Throwable class, we have found two methods   printStackTrace(PrintWriter)  which prints the throwable and its backtrace to the specified print writer, and printStackTrace(PrintStream) which prints the throwable and its backtrace to the specified print stream. So which method best fit our case?

To answer this question we referred to API documentation for PrintStream and PrintWriter classes and we found this statement:

All characters printed by a PrintStream are converted into bytes using the platform’s default character encoding. The PrintWriter class should be used in situations that require writing characters rather than bytes.

So our choice was printStackTrace(PrintWriter)  method and here is the method we used.

import java.io.PrintWriter;
import java.io.StringWriter;

...........................................

...........................................

public String getStackTrace(Exception e){
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
return stringWriter.toString();
}

1 Comment

Filed under Java