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.