Mittwoch, Dezember 22, 2004
Write your own JSP EL-Functions to secure your web app
Frank has a very good description to use the J2EE security model to secure your web pages fine granular (ADF UIX: Enabling and disabling page compression in UIX). However I have an extention to this: Within the ADF UIX Framework you can easily extend EL and write your own EL methode like ${isUserInRole('GuestRole')}. As you know UIX was the initial idea to specify JavaServer Faces. So with UIX you can write for each component your own renderer. This means you can write your own Java methodes and call it within the EL renderer like this:
<submitButton disabled="${ctrl:isUserInRole(uix, 'GuestUserRole')}" text="Save" >
To accomplish this you must write the following code:
public final class ELFunctions{
public static Boolean isUserInRole(Object uix, String role) throws Exception{
ControllerImplicitObject uixObj = (ControllerImplicitObject)uix;
boolean isInRole = uixObj.getBajaContext().getServletRequest().isUserInRole(role);
return new Boolean(isInRole);
}
}
After writing your static Java EL Function you must write a framework factory class. This is accomplished by usage of the UIExtention Framework:
public class ELFunctionExtension implements UIExtension {
static Class funcClass = com.bm.ui.common.ELFunctions.class;
static Class getFuncClass(String className){
try {
Class clazz = Class.forName(className);
return clazz;
}
catch(ClassNotFoundException classnotfoundexception) {
throw new NoClassDefFoundError(classnotfoundexception.getMessage());
}
}
public void registerSelf(ParserManager parserManager) {
XMLUtils.registerFunctions(parserManager, "http://xmlns.oracle.com/uix/controller",
funcClass != null ? funcClass : (funcClass = getFuncClass ("com.bm.ui.common.ELFunctions")));
}
public void registerSelf(LookAndFeel lookandfeel) { }
}
Additional you must register the UIExtention in the WEB-INF/uix-config.xml file:
<ui-extensions>
<extension-class> com.bm.ui.common.ELFunctionExtension </extension-class>
</ui-extensions>
Now you can access the isUserInRole() method directly from the uiXML code:
<submitButton disabled="${!ctrl:isUserInRole(uix,'PowerUserRole')}" text="Save" >
or
<submitButton disabled="${not ctrl:isUserInRole(uix,'PowerUserRole')}" text="Save" >
or
<submitButton disabled="${ctrl:isUserInRole(uix,'GuestUserRole')}" text="Save" >
<submitButton disabled="${ctrl:isUserInRole(uix, 'GuestUserRole')}" text="Save" >
To accomplish this you must write the following code:
public final class ELFunctions{
public static Boolean isUserInRole(Object uix, String role) throws Exception{
ControllerImplicitObject uixObj = (ControllerImplicitObject)uix;
boolean isInRole = uixObj.getBajaContext().getServletRequest().isUserInRole(role);
return new Boolean(isInRole);
}
}
After writing your static Java EL Function you must write a framework factory class. This is accomplished by usage of the UIExtention Framework:
public class ELFunctionExtension implements UIExtension {
static Class funcClass = com.bm.ui.common.ELFunctions.class;
static Class getFuncClass(String className){
try {
Class clazz = Class.forName(className);
return clazz;
}
catch(ClassNotFoundException classnotfoundexception) {
throw new NoClassDefFoundError(classnotfoundexception.getMessage());
}
}
public void registerSelf(ParserManager parserManager) {
XMLUtils.registerFunctions(parserManager, "http://xmlns.oracle.com/uix/controller",
funcClass != null ? funcClass : (funcClass = getFuncClass ("com.bm.ui.common.ELFunctions")));
}
public void registerSelf(LookAndFeel lookandfeel) { }
}
Additional you must register the UIExtention in the WEB-INF/uix-config.xml file:
<ui-extensions>
<extension-class> com.bm.ui.common.ELFunctionExtension </extension-class>
</ui-extensions>
Now you can access the isUserInRole() method directly from the uiXML code:
<submitButton disabled="${!ctrl:isUserInRole(uix,'PowerUserRole')}" text="Save" >
or
<submitButton disabled="${not ctrl:isUserInRole(uix,'PowerUserRole')}" text="Save" >
or
<submitButton disabled="${ctrl:isUserInRole(uix,'GuestUserRole')}" text="Save" >
Sonntag, Dezember 19, 2004
ADF: How to edit the current selected row
There are may possibilities to edit the current selecte row in usage of ADF-Bindings, ADF- BC4J and uiXML .
- First you can do the task with a table and input fields into the same page . This approach is very simple and also used within Jdev generated sample code. The underling bindingModel associate to the identical page name and so the bounded edit fileds associate always the same model.
- Next to edit the current row into an other page without hidding only the table or edit elements, you must change the associated BindingModel in the new page to the calling page. This is done in five steps: create a new ADF Struts DataAction, change the requested modelName in the getBindingContainerName() methode of your overwritten oracle.cabo.adf.rt.InitModelListener. Additional you should copy all bindingControls from the original UIModel to the underling Model. Into the uiXML page you should call the associated struts action after setting the current row:
<singleSelection model="${bindings.EmployeesViewIterator}" text="Select and "> <primaryClientAction> <fireAction source="EmployeesView0" event="select"> </fireAction>
</primaryClientAction>
....
<event name="select">
<compound>
<set target="${bindings.EmployeesViewIterator}" property="currentRowIndexInRange" value="${ui:tableSelectedIndex(uix, 'EmployeesView0')}"/>
<struts:action path="/selectEmp.do">
</struts:action>
</compound>
</event>
The rest is automatically done by ADF. - A other way is to write our own DataAction for the current user selection. Remove the single selection element from uiXML table and add a column with the following selection link:
<column>
<columnFormat columnDataFormat="numberFormat"/>
<columnHeader>
<sortableHeader model="${ctrl:createSortableHeaderModel(bindings.EmployeesView,'EmployeeId')}"/>
</columnHeader>
<contents>
<link text="${uix.current.EmployeeId.attributeValue}">
<boundAttribute name="destination">
<concat> <contextProperty select="ui:contextURI"/>
<fixed text="/selectEmp.do?id="/>
<dataObject source="${uix.current.EmployeeId.attributeValue}"/>
<fixed text="&event=select"/>
</concat>
</boundAttribute>
</link>
</contents>
</column>
Afterward the associated adf struts action should set the current row and navigate to the edit page with the struts action forward tag:
public void onSelect(DataActionContext ctx){
String id = (String)evalEL("${param.id}",ctx);
JUIteratorBinding iter = (JUIteratorBinding)evalEL("${bindings.EmployeesViewIterator}", ctx);
Key key = new Key(new Object[] {id});
Row[] rows = iter.getViewObject().findByKey(key,1);
iter.setCurrentRowWithKey(key.toStringFormat(true));
}
Samstag, Dezember 18, 2004
How to evaluate any parameter in ADF-Actions
You can easiely evaluate any parameter including servlet, request or ADF binding parameters with the Expression Language Syntax (EL).
/** Evaluate an EL (expression language) Expression and return the result
* @param expression EL Expression to evaluate
* @param ctx The DataAction context.
* @return The object identified by the EL expression
*/
public Object evalEL(String expression, DataActionContext ctx) {
Evaluator eval = Evaluator.getEvaluator(ctx);
return eval.getValue(expression); }
An example to retrive a request parameter into an adf action:
...
String myImputParam = (String)evalEL(ctx, "${param.myInputParam}");
/** Evaluate an EL (expression language) Expression and return the result
* @param expression EL Expression to evaluate
* @param ctx The DataAction context.
* @return The object identified by the EL expression
*/
public Object evalEL(String expression, DataActionContext ctx) {
Evaluator eval = Evaluator.getEvaluator(ctx);
return eval.getValue(expression); }
An example to retrive a request parameter into an adf action:
...
String myImputParam = (String)evalEL(ctx, "${param.myInputParam}");
Donnerstag, Dezember 09, 2004
Spring Toplink Integration
I am very happy to annonce Oracle's Springframwork support. The integration includes the Toplink Persistence Framework like Hibernate. http://www.oracle.com/technology/products/ias/toplink/preview/spring/index.html
... numerous thanks Jim Clark!
... numerous thanks Jim Clark!