JSF in Action
I got this book 3 years years ago and I am reviewing these days. In this book, old version of JSF is used. (I can't find the exact version is using in the book) During the time, something has changed. So, when I tried to execute sample Project Track project in the book, it caused errors. I was struggling the errors and searched API to soleve them. Finally I could see inbox page after I fixed some code.
Origianally, the source code in login() method in AuthenticationBean was like following:
Visit visit = new Visit();
visit.setUser(newUser);
visit.setAuthenticationBean(this);
setVisit(visit);
//Constants.VISIT_KEY_SCOPE => sessionScope.
//Constants.VISIT_KEY => visit
getApplication().createValueBinding("#{" + Constants.VISIT_KEY_SCOPE +
Constants.VISIT_KEY + "}").setValue(facesContext, visit);
The createValueBinding() method comes from Java EE API and it is deprecated now. Refferring Java EE API, it is recommended to call getExpressionFactory() method and then use createValueExpression() method. (see http://download.oracle.com/javaee/5/api/javax/el/ExpressionFactory.html#createValueExpression(javax.el.ELContext, java.lang.String, java.lang.Class)
Visit visit = new Visit();
visit.setUser(newUser);
visit.setAuthenticationBean(this);
setVisit(visit);
ValueExpression vExpr = getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(),
"#{" + Constants.VISIT_KEY_SCOPE + Constants.VISIT_KEY + "}",
Object.class);
vExpr.setValue(getFacesContext().getELContext(), visit);
The createMethodBinding() method in the old version also changed to createMethodBinding() method.
Through this code, JSF register Visit Class as a bean named visit into the bean management facility at a runtime. In the above, VISIT_KEY_SCOPE constant is sessionScope, so you can refer Visit instance with name 'visit' in any page.
I got this book 3 years years ago and I am reviewing these days. In this book, old version of JSF is used. (I can't find the exact version is using in the book) During the time, something has changed. So, when I tried to execute sample Project Track project in the book, it caused errors. I was struggling the errors and searched API to soleve them. Finally I could see inbox page after I fixed some code.
Origianally, the source code in login() method in AuthenticationBean was like following:
Visit visit = new Visit();
visit.setUser(newUser);
visit.setAuthenticationBean(this);
setVisit(visit);
//Constants.VISIT_KEY_SCOPE => sessionScope.
//Constants.VISIT_KEY => visit
getApplication().createValueBinding("#{" + Constants.VISIT_KEY_SCOPE +
Constants.VISIT_KEY + "}").setValue(facesContext, visit);
The createValueBinding() method comes from Java EE API and it is deprecated now. Refferring Java EE API, it is recommended to call getExpressionFactory() method and then use createValueExpression() method. (see http://download.oracle.com/javaee/5/api/javax/el/ExpressionFactory.html#createValueExpression(javax.el.ELContext, java.lang.String, java.lang.Class)
Visit visit = new Visit();
visit.setUser(newUser);
visit.setAuthenticationBean(this);
setVisit(visit);
ValueExpression vExpr = getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(),
"#{" + Constants.VISIT_KEY_SCOPE + Constants.VISIT_KEY + "}",
Object.class);
vExpr.setValue(getFacesContext().getELContext(), visit);
The createMethodBinding() method in the old version also changed to createMethodBinding() method.
Through this code, JSF register Visit Class as a bean named visit into the bean management facility at a runtime. In the above, VISIT_KEY_SCOPE constant is sessionScope, so you can refer Visit instance with name 'visit' in any page.
Comments
Post a Comment