waffel’s Weblog

September 27, 2007

Replacing deprecated ValueBindung stuff from JSF with ELResolver

Gespeichert unter: JSF, software — Thomas Wabner @ 11:21

I have searched for a solution to replace the as deprecated marked ValutBinding stuff with a better solution.

For example if you have a method to retrieve a JSF Bean from the faces context:


public static Object accessBeanFromFacesContext(final String theBeanName, final FacesContext theFacesContext) {
final StringBuffer valueBinding = new StringBuffer();
valueBinding.append('#');
valueBinding.append('{');
valueBinding.append(theBeanName);
valueBinding.append('}');
final Object returnObject = theFacesContext.getApplication().
createValueBinding(valueBinding.toString()).getValue(theFacesContext);
if (returnObject == null) {
LOG
.error("Bean with name " + theBeanName + " was not found. Check the faces-config.xml file if the given bean name is ok."); //$NON-NLS-1$ //$NON-NLS-2$
}
return returnObject;
}

You can replace this now with following code:

public static Object accessBeanFromFacesContext(final String theBeanName, final FacesContext theFacesContext) {
final Object returnObject = theFacesContext.getELContext().getELResolver().getValue(theFacesContext.getELContext(), null, theBeanName);
if (returnObject == null) {
LOG
.error("Bean with name " + theBeanName + " was not found. Check the faces-config.xml file if the given bean name is ok."); //$NON-NLS-1$ //$NON-NLS-2$
}
return returnObject;
}

This retrieves a bean from the faces context. You can use the method for example to retrieve a TestBean form the faces context like

TestBean testBean = (TestBean)JSFUtils.accessBeanFromFacesContext("testBean", FacesContext.getCurrentInstance());

The TestBean object have to be added to the faces-config.xml as a managed bean. If the bean was not created at the point where you ask for it, the default constructor is called and the bean is created for you from the JSF framework.

September 24, 2007

log4cpp release 1.0

Gespeichert unter: cpp, software — Thomas Wabner @ 3:11

A little bit late but hopefully for your interest.

I have pushed out the 1.0 release of the nice log4cpp package.

This release contains many small bug fixes and some new features. Currently we have problems under some windows environments with the building. But hey … I don’t have any platform, we support in this project to test it. Because my main focus is on linux, I have only created and tested it under the cool gentoo environment.

Today my friend ahöhma has created his own blogg (in german only).

Bloggen Sie auf WordPress.com.