Sunday, December 19, 2010

Setting locale programmatically in jsf

In jsf you can set locale programmatically by this


UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
viewRoot.setLocale(new Locale("de"));


Friday, December 17, 2010

Setting value through EL in JSF

Sample method can be used to set new object programmatically:


public static void setObject(String expression, Object newValue) {
FacesContext facesContext = getFacesContext();
Application app = facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
ValueExpression valueExp =
elFactory.createValueExpression(elContext, expression,
Object.class);

//Check that the input newValue can be cast to the property type
//expected by the managed bean.
//Rely on Auto-Unboxing if the managed Bean expects a primitive
Class bindClass = valueExp.getType(elContext);
if (bindClass.isPrimitive() || bindClass.isInstance(newValue)) {
valueExp.setValue(elContext, newValue);
}
}


Resolving Method expression programmatically In JSF

EL is used in JSF to bind java methods with userinterface actions like commandbutton and commandlink. But sometimes It is needed to resolve method binding programmatically. Sample method can be used for this purpose:


public static Object resloveMethodExpression(String expression,
Class returnType,
Class[] argTypes,
Object[] argValues) {
FacesContext facesContext = getFacesContext();
Application app = facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
MethodExpression methodExpression =
elFactory.createMethodExpression(elContext, expression, returnType,
argTypes);
return methodExpression.invoke(elContext, argValues);
}


Resolving EL programmatically to retrieve value

EL is used in JSF to set values from java classes with User Interface. Sometimes, EL is needed to resolve programmatically to retrieve value. Sample method can be used for this purpose:


public static Object resolveExpression(String expression) {
FacesContext facesContext = getFacesContext();
Application app = facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
ValueExpression valueExp =
elFactory.createValueExpression(elContext, expression,
Object.class);
return valueExp.getValue(elContext);
}


Wednesday, October 27, 2010

CSS Classes for ADF Faces Component

Whenever we work in ADF, we will have to customize ui components to our own theme and color scheme. Often people find it hard to find list of CSS classes for ADF components as it is not directly mentioned in Web Developers guide. Here is the link in which you can find complete list of CSS classes for all ADF components

ADF CSS Selectors

Sunday, October 24, 2010

Android Permissions

In Android, an application needs permissions from user to use certain type of resources e.g. if your application wants to have functionality to read user's contacts, then you need permission "READ_CONTACTS" permission. Similarly in order to use internet of user's device, you need "INTERNET_PERMISSION". There is a long list of permissions which you have to include if you want to use a particular type of functionality in your application. This list is documented in Manifest.permission class.

http://developer.android.com/reference/android/Manifest.permission.html

Thursday, October 14, 2010

ActionListener versus Action

Action method is used to perform navigation and ActionListener is used to perform some logic in backing bean.While it is possible to define a backing bean method that performs navigation and binds the method to the actionListener attribute, this is not best practice. Instead, application logic should be placed in the backing bean method to which the actionListener is bound. Following successful execution of that method, the ADF Faces lifecycle will call the method or control flow case specified by the action attribute. If the method bound to the actionListener fails, developers can change the action outcome to suppress navigation so that the user has the opportunity to correct the issue.

Tuesday, September 28, 2010

ADF Iterator's RangeSize Property

RangeSize property does not control the number of rows displayed in a table based on the collection. In fact, the rich table in ADF 11g actually will display as many rows as can fit into the available space physically allocated to the table component, so all the range size controls is the number of AJAX transactions that are required to populate the table as the user scrolls up and down. You can set it to -1 if you want to get all records at once.

Tuesday, September 14, 2010

Which Collection Should be used when?

* Use Vector if there are multiple threads and ArrayList if there is only a single thread.

* Use Hashtable if there are multiple threads and HashMap if there is only a single thread.

* Use StringBuffer if there are multiple threads and StringBuilder if there is only a single thread.

For explanation visit Skeleton Coder

Sunday, September 12, 2010

Html Host Page In GWT

For every GWT application, a html hosted page is required. This hosted page starts the GWT application. This hosted html page can be generated from Servlet or JSP.

Sunday, September 5, 2010

Creating more than one folder as client in GWT

The package does not necessarily have to be called “client,” and in fact, you can specify multiple packages to be considered for JavaScript by modifying your <module> by adding an extra <source path=""> tag. The client package is simply an implicit default value to help you out. See the full definition of modules here: http://code.google.com/webtoolkit/documentation/com.google.gwt.doc.DeveloperGuide.Fundamentals.html#Modules.
In GWT, package structure is divided in three folders: client, public, and server. Everything in client folder is converted to javascript. public folder contains resources like css and images while server folder contains services.
Moreover, all domain objects are placed in client folder as POJOs.

Saturday, August 28, 2010

Static Imports

We use "imports" in java so that in order to refer classes we don't have to use fully qualified name. Similar, static imports are used so that we don't have to use classname to call a static method. e.g. java.lang.String class contains a lot of static methods, so you can import this class statically and later on in the code just use method name to use it without mentioning "String" class name. Static imports are usually used when you are using a class's static methods repeatedly.

Wednesday, August 18, 2010

In order get application's context path in JSF, do the following:
FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();

Friday, August 6, 2010

Programmatically Setting Filter for ADF Table

You can set the criteria programmatically to filter data in ADF table by:

DCBindingContainer bc =
(DCBindingContainer)context.getApplication().evaluateExpressionGet(facesContext,
"#{bindings}",
DCBindingContainer.class);
if (bc != null){
DCIteratorBinding ib = (DCIteratorBinding)bc.getIterBindings().get(p_binding);
if (ib != null)
ViewObject vo = ib.getViewObject();
if (vo != null)
vo.setWhereClause('your clause');
}




Tuesday, July 20, 2010

Calling super class method in javascript

In order to call super class's method, do this:
ClassName.prototype.method.call(this);
where "this" is the child object.

Refresh a ADF component programmatically

In order to refresh an ADF component in bean, do the following:
  • Bind that component to some property of bean
  • get reference of AdfFacesContext by AdfFacesContext.getInstance()
  • add that component as a partial target like adfFacesContext.addPartialTarget(comp_binding)

Wednesday, July 14, 2010

Open-jACOB Draw2D selecting a figure

Open-jACOB Draw2D is an excellent javascript drawing api. One of the method of workflow (main canvas in api) is not documented and that is "setCurrentSelection". After using this method, you can use "showResizedHandles" method to show handles like given below:

g_workflow.setCurrentSelection(figure);
g_workflow.showResizeHandles(figure);

Tuesday, July 13, 2010

Use minimal version of javascript to speedup downloading

whenever you develop some javascript code, always convert it to minimal version before deployment. Minimal version removes extra spaces, comments and other stuffs, thus greatly increasing downloading speed by decreasing the javascript file size. One tool is JSMin

Saturday, July 10, 2010

IE CSS Compatibility Model

IE by default does not follow the CSS Standard specification e.g. it includes border and padding in width and height of element but standard threats them separately. In order to use standard definition add following doctype in the page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">