Posts Tagged ‘11g’

JDev & ADF Goodies

In the current JDeveloper version 11.1.1.9.0 and 12.1.3 the af:exportCollectionActionListener got enhanced by options to filter the data to export.
Enhanced options of exportCollectionListener Enhanced options of exportCollectionListener
The option this blog talks about is the one marked, the FilterMethod. The ducumentation for 12.12 Exporting Data from Table, Tree, or Tree Table does not reveal too much about how to use this FilterMethod.
The sample we build in this blog entry shows how the FilterMethod can be used to filter the data to be exported to excel.
In older version of JDev you hadto use a trick to filter the data which was downloaded from a table see Validate Data before Export via af:exportCollectionActionListener or af:fileDownloadActionListener. The new property of the af:exportCollectionActionListener allows to filter the data without using the trick.
The sample just load the employees table from the HR DB schema and shows it in a table on the screen. In…

View original post 352 more words

JDev & ADF Goodies

A question on the JDeveloper and ADF OTN forum asked about how to navigate to a specific page of an af:table in pagination mode. As of JDeveloper 11.1.1.7.0 adf tables can be rendered in scroll mode or in pagination mode where only a specific number of rows are visible in the table.

af:table in pagination mode

To navigate the pages there is a small navigation toolbar below the table which allows to enter a page number or to navigate to the previous, next, first or last page.

The problem to solve is how to navigate the paginated table from within a java bean?

The table doesn’t offer any navigation listeners or methods you can bind bean methods to. Luckily there is the RangeChangeEvent one of the FacesEvents which can e used to notify a component that change in the range has taken place.

All we have to do to navigate the table in pagination…

View original post 440 more words

Oracle ADF

Use Case – There is a use case where User wants to display blank as selected when page loads. But he doesn’t want blank to remain there once user select any value.

Solution – This is a workaround.

Step 1, Create one JSPX with foloowing contents,

<?xml version=’1.0′ encoding=’UTF-8′?>
<jsp:root xmlns:jsp=”http://java.sun.com/JSP/Page” version=”2.1″
xmlns:f=”http://java.sun.com/jsf/core”
xmlns:h=”http://java.sun.com/jsf/html”
xmlns:af=”http://xmlns.oracle.com/adf/faces/rich”>
<jsp:directive.page contentType=”text/html;charset=UTF-8″/>
<f:view>
<af:document id=”d1″ title=”doc1″>
<af:form id=”f1″>
<af:commandButton text=”commandButton 1″ id=”cb1″
action=”#{ForwardBean.process}” partialSubmit=”true”/>
<af:selectOneChoice label=”Label 1″
id=”soc1″ required=”true” binding=”#{ForwardBean.dropdown1}” showRequired=”false”>
<af:selectItem label=”Item1″ value=”one” id=”si1″/>
<af:selectItem label=”Item2″ value=”two” id=”si2″/>
<af:selectItem label=”Item3″ value=”three” id=”si3″/>
</af:selectOneChoice>
<af:outputLabel value=”outputLabel1″ id=”ol1″
binding=”#{ForwardBean.updateState}” visible=”false”/>
</af:form>
</af:document>
</f:view>
</jsp:root>

Step 2. Create one MBean with following contents.

package com.test;

import javax.faces.event.PhaseEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import oracle.adf.view.rich.component.rich.input.RichSelectOneChoice;
import oracle.adf.view.rich.component.rich.output.RichOutputLabel;
import oracle.adf.view.rich.context.AdfFacesContext;

public class ForwardBean {
private RichSelectOneChoice dropdown1;
private RichOutputLabel updateState;

public ForwardBean() {
}

public String process() {
// Add event code here…
return “success”;
}

public void pushSelectedItem(ValueChangeEvent valueChangeEvent)…

View original post 51 more words

Environment (JDeveloper 11.1.1.5.0, ADF BC, hr schema)

Many to many relationship can’t be represented in the physical database (i.e. in the actual database table) because you can’t just associate one key from one table with another key from the other table. However, many to many relationship can be broken down into a series of two or more of one to many relationships through a table called intersection table. Intersection table is simply a table that contains the primary key of each of the table being connected. Consider the followoing cases as examples about many to many relationships:

  1. A student can take many different courses, and each course can be taken from many different students.
  2. An employee can change his job several times during his career life, and each job can be held by several employees.

In this example I will explain how to implement a many to many association based…

View original post 477 more words

JDev & ADF Goodies

A question on the OTN JDeveloper and ADF ‘Space’ asked for a sample and/or tutorial on how to navigate after a bounded task flow, based on pages, returns from its work.
I setup a sample application to show how this works. The application is built using JDeveloper 11.1.1.7.0 and uses the HR DB schema. The sample can be loaded using the link provided at the end of the post.
Before we start let’s take a look at the running application:

Now that we have seen how the application works let’s check out how it’s implemented.

We start with an unbounded task flow (adfc-config.xml) which look like
Unbounded Task Flow: adfc-config.xml Unbounded Task Flow: adfc-config.xml
We see that the application is built from two pages, a ‘Start’ page and an ‘End’ page. The ‘Start’ page can call a bounded task flow employee-btf. The start page holds one button ‘Start’ which calls the bounded task flow…

View original post 168 more words

Environment (JDeveloper 11.1.2.3.0,ADF Faces)

The inputDate component creates a text field for entering dates and (optionally) a glyph which opens a popup for picking dates from a calendar. However  in some cases we need to prevent the user from picking a specific days from the calender. In this post I will explain how to do this use case.

1- Create a simple JSF page and drag and drop af:inputDate component from the component palette into the newly created page.

2- Create a java class which implements org.apache.myfaces.trinidad.model.DateListProvider interface. This interface is used for providing a list of  individual dates within a given range.

3- Override the getDateList method, This method will generate a List of individual Date objects which will be rendered as disabled in a datePicker component.  An example is shown below.

import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.List; import javax.faces.context.FacesContext; import org.apache.myfaces.trinidad.model.DateListProvider; public class DaysBean implements…

View original post 172 more words

JDev & ADF Goodies

Since JDeveloper 12.1.2 Oracle added a feature called ‘File Templates’. Only there was absolutely no documentation for this. We only had the ‘File Templates’ node in the preferences. I filed a bug (ADFEMG-150) for this.
In the current JDeveloper 12.1.3 release the ‘inital’ documentation for the ‘File Templated’ has been added.
To get to the ‘File Templates’ via the Tools->Preferences->’File Tempalates’ and see the below image.
File Templates in Preferences File Templates in Preferences
Loading the extension you get
FileT emplates Inital Dialog File Templates Inital Dialog
The only help I found can be reached by clicking the Help button in the dialog which will get you
File Templates Help File Templates Help
This is not much to work with. I you find more help on using this feature, drop me a note, please. All I present in this blog was found out using try and error. There seams to be a difference if you use a Windows or…

View original post 832 more words

It is possible to disable each component one by one but the easiest method is getting the list of all the components within the af:panelGroupLayout on page load and setting the properties to the desired status for each one. The same solution can be performed also for other surrounding element.

First bind your component (af:panelGroupLayout in this case) in your managed bean:


RichPanelGroupLayout yourPanelGroupBind;
public void setYourPanelGroupBind(RichPanelGroupLayout yourPanelGroupBind) {
this.yourPanelGroupBind = yourPanelGroupBind;
}
public RichPanelGroupLayout getYourPanelGroupBind() {
return yourPanelGroupBind;
}

Then within a method do this:


List outer = yourPanelGroupBind.getChildren();
for (UIComponent outerComponent : outer) {
if (outerComponent instanceof RichPanelFormLayout) {
List uiComponentList = outerComponent.getChildren();
for (UIComponent uiComponent : uiComponentList) {
if (uiComponent instanceof RichPanelLabelAndMessage) {
List uiComponentList2 = uiComponent.getChildren();
for (UIComponent uiComponent2 : uiComponentList2) {
if (uiComponent2 instanceof RichInputText) {
((RichInputText)uiComponent2).setDisabled(true);
} else if (uiComponent2 instanceof RichSelectBooleanCheckbox) {
((RichSelectBooleanCheckbox)uiComponent2).setDisabled(true);
} else if (uiComponent2 instanceof RichInputDate) {
((RichInputDate)uiComponent2).setDisabled(true);
} else if (uiComponent2 instanceof RichSelectOneChoice) {
((RichSelectOneChoice)uiComponent2).setDisabled(true);
} else if (uiComponent2 instanceof RichPanelGroupLayout) {
List uiComponentList3 = uiComponent2.getChildren();
for (UIComponent uiComponent3 : uiComponentList3) {
if (uiComponent3 instanceof RichInputText) {
((RichInputText)uiComponent3).setDisabled(true);
} else if (uiComponent3 instanceof RichSelectBooleanCheckbox) {
((RichSelectBooleanCheckbox)uiComponent3).setDisabled(true);
} else if (uiComponent3 instanceof RichInputDate) {
((RichInputDate)uiComponent3).setDisabled(true);
} else if (uiComponent3 instanceof RichSelectOneChoice) {
((RichSelectOneChoice)uiComponent3).setDisabled(true);
}}}}}}}

The code above checks for a wide variety of components that might be located within the af:panelGroupLayout.

You should create a folder within your Web Content. Then copy your file manually there (go to c:/Oracle/MiddleWare/Jdeveloper/Jdev/myWork/YourApp/ViewController…). Back in JDeveloper refresh your application and you should see the new file inside your new folder. Then you refer to it simply as “/MyFolder/myfile.txt” or anything else.

In managed bean you can get this file as:

public ServletContext getContext() {
return (ServletContext)getFacesContext().getExternalContext().getContext();
}
ServletContext context = getContext();
InputStream fs = context.getResourceAsStream(“/Folder/file”);

It is common in an application, that some bindings from random pages are needed when navigating through the application. For this an utility class should be used called JSFUtils. The code is this:

BindingContainer bindings =
(BindingContainer)JSFUtils.resolveExpression(“#{data.mypage_view_bindingsContainerPageDef}”);

DCBindingContainer bindings2 = (DCBindingContainer)bindings;

The part “mypage_view_bindingsContainerPageDef” is the name of the bindings page usage id that corresponds to your page. The usage id can be found in DataBindings.cpx file.

 

JSFUtils class:

package adfgok.wordpress.eg;

import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.ValueExpression;

import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

import javax.servlet.http.HttpServletRequest;
public class JSFUtils {

private static final String NO_RESOURCE_FOUND = “Missing resource: “;

/**
* Method for taking a reference to a JSF binding expression and returning
* the matching object (or creating it).
* @param expression EL expression
* @return Managed object
*/
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);
}

/**
* @return
*/
public static String resolveRemoteUser() {
FacesContext facesContext = getFacesContext();
ExternalContext ectx = facesContext.getExternalContext();
return ectx.getRemoteUser();
}

/**
* @return
*/
public static String resolveUserPrincipal() {
FacesContext facesContext = getFacesContext();
ExternalContext ectx = facesContext.getExternalContext();
HttpServletRequest request = (HttpServletRequest)ectx.getRequest();
return request.getUserPrincipal().getName();
}

/**
* @param expression
* @param returnType
* @param argTypes
* @param argValues
* @return
*/
public static Object resolveMethodExpression(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);
}
//*****************************************************************

public static Object invokeMethodExpression(String expr, Class returnType,

Class argType, Object argument) {

return invokeMethodExpression(expr, returnType, new Class[] { argType }, new Object[] { argument });

}
public static Object invokeMethodExpression(String expr, Class returnType,

Class[] argTypes, Object[] args) {

FacesContext fc = FacesContext.getCurrentInstance();

ELContext elctx = fc.getELContext();

ExpressionFactory elFactory =

fc.getApplication().getExpressionFactory();

MethodExpression methodExpr =

elFactory.createMethodExpression(elctx, expr, returnType, argTypes);

return methodExpr.invoke(elctx, args);

}

//*********************************************************************

 
/**
* Method for taking a reference to a JSF binding expression and returning
* the matching Boolean.
* @param expression EL expression
* @return Managed object
*/
public static Boolean resolveExpressionAsBoolean(String expression) {
return (Boolean)resolveExpression(expression);
}

/**
* Method for taking a reference to a JSF binding expression and returning
* the matching String (or creating it).
* @param expression EL expression
* @return Managed object
*/
public static String resolveExpressionAsString(String expression) {
return (String)resolveExpression(expression);
}

/**
* Convenience method for resolving a reference to a managed bean by name
* rather than by expression.
* @param beanName name of managed bean
* @return Managed object
*/
public static Object getManagedBeanValue(String beanName) {
StringBuffer buff = new StringBuffer(“#{“);
buff.append(beanName);
buff.append(“}”);
return resolveExpression(buff.toString());
}

/**
* Method for setting a new object into a JSF managed bean
* Note: will fail silently if the supplied object does
* not match the type of the managed bean.
* @param expression EL expression
* @param newValue new value to set
*/
public static void setExpressionValue(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.
//If the managed Bean expects a primitive we rely on Auto-Unboxing
Class bindClass = valueExp.getType(elContext);
if (bindClass.isPrimitive() || bindClass.isInstance(newValue)) {
valueExp.setValue(elContext, newValue);
}
}

/**
* Convenience method for setting the value of a managed bean by name
* rather than by expression.
* @param beanName name of managed bean
* @param newValue new value to set
*/
public static void setManagedBeanValue(String beanName, Object newValue) {
StringBuffer buff = new StringBuffer(“#{“);
buff.append(beanName);
buff.append(“}”);
setExpressionValue(buff.toString(), newValue);
}
/**
* Convenience method for setting Session variables.
* @param key object key
* @param object value to store
*/

public static void storeOnSession(String key, Object object) {
FacesContext ctx = getFacesContext();
Map sessionState = ctx.getExternalContext().getSessionMap();
sessionState.put(key, object);
}

/**
* Convenience method for getting Session variables.
* @param key object key
* @return session object for key
*/
public static Object getFromSession(String key) {
FacesContext ctx = getFacesContext();
Map sessionState = ctx.getExternalContext().getSessionMap();
return sessionState.get(key);
}

/**
* @param key
* @return
*/
public static String getFromHeader(String key) {
FacesContext ctx = getFacesContext();
ExternalContext ectx = ctx.getExternalContext();
return ectx.getRequestHeaderMap().get(key);
}

/**
* Convenience method for getting Request variables.
* @param key object key
* @return session object for key
*/
public static Object getFromRequest(String key) {
FacesContext ctx = getFacesContext();
Map sessionState = ctx.getExternalContext().getRequestMap();
return sessionState.get(key);
}

/**
* Pulls a String resource from the property bundle that
* is defined under the application &lt;message-bundle&gt; element in
* the faces config. Respects Locale
* @param key string message key
* @return Resource value or placeholder error String
*/
public static String getStringFromBundle(String key) {
ResourceBundle bundle = getBundle();
return getStringSafely(bundle, key, null);
}
/**
* Convenience method to construct a <code>FacesMesssage</code>
* from a defined error key and severity
* This assumes that the error keys follow the convention of
* using <b>_detail</b> for the detailed part of the
* message, otherwise the main message is returned for the
* detail as well.
* @param key for the error message in the resource bundle
* @param severity severity of message
* @return Faces Message object
*/
public static FacesMessage getMessageFromBundle(String key,
FacesMessage.Severity severity) {
ResourceBundle bundle = getBundle();
String summary = getStringSafely(bundle, key, null);
String detail = getStringSafely(bundle, key + “_detail”, summary);
FacesMessage message = new FacesMessage(summary, detail);
message.setSeverity(severity);
return message;
}

/**
* Add JSF info message.
* @param msg info message string
*/
public static void addFacesInformationMessage(String msg) {
FacesContext ctx = getFacesContext();
FacesMessage fm =
new FacesMessage(FacesMessage.SEVERITY_INFO, msg, “”);
ctx.addMessage(getRootViewComponentId(), fm);
}

/**
* Add JSF error message.
* @param msg error message string
*/
public static void addFacesErrorMessage(String msg) {
FacesContext ctx = getFacesContext();
FacesMessage fm =
new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, “”);
ctx.addMessage(getRootViewComponentId(), fm);
}

/**
* Add JSF error message for a specific attribute.
* @param attrName name of attribute
* @param msg error message string
*/
public static void addFacesErrorMessage(String attrName, String msg) {
FacesContext ctx = getFacesContext();
FacesMessage fm =
new FacesMessage(FacesMessage.SEVERITY_ERROR, attrName, msg);
ctx.addMessage(getRootViewComponentId(), fm);
}

// Informational getters

/**
* Get view id of the view root.
* @return view id of the view root
*/
public static String getRootViewId() {
return getFacesContext().getViewRoot().getViewId();
}

/**
* Get component id of the view root.
* @return component id of the view root
*/
public static String getRootViewComponentId() {
return getFacesContext().getViewRoot().getId();
}

/**
* Get FacesContext.
* @return FacesContext
*/
public static FacesContext getFacesContext() {
return FacesContext.getCurrentInstance();
}
/*
* Internal method to pull out the correct local
* message bundle
*/

private static ResourceBundle getBundle() {
FacesContext ctx = getFacesContext();
UIViewRoot uiRoot = ctx.getViewRoot();
Locale locale = uiRoot.getLocale();
ClassLoader ldr = Thread.currentThread().getContextClassLoader();
return ResourceBundle.getBundle(ctx.getApplication().getMessageBundle(),
locale, ldr);
}

/**
* Get an HTTP Request attribute.
* @param name attribute name
* @return attribute value
*/
public static Object getRequestAttribute(String name) {
return getFacesContext().getExternalContext().getRequestMap().get(name);
}

/**
* Set an HTTP Request attribute.
* @param name attribute name
* @param value attribute value
*/
public static void setRequestAttribute(String name, Object value) {
getFacesContext().getExternalContext().getRequestMap().put(name,
value);
}

/*
* Internal method to proxy for resource keys that don’t exist
*/

private static String getStringSafely(ResourceBundle bundle, String key,
String defaultValue) {
String resource = null;
try {
resource = bundle.getString(key);
} catch (MissingResourceException mrex) {
if (defaultValue != null) {
resource = defaultValue;
} else {
resource = NO_RESOURCE_FOUND + key;
}
}
return resource;
}

/**
* Locate an UIComponent in view root with its component id. Use a recursive way to achieve this.
* @param id UIComponent id
* @return UIComponent object
*/
public static UIComponent findComponentInRoot(String id) {
UIComponent component = null;
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext != null) {
UIComponent root = facesContext.getViewRoot();
component = findComponent(root, id);
}
return component;
}

/**
* Locate an UIComponent from its root component.
* Taken from http://www.jroller.com/page/mert?entry=how_to_find_a_uicomponent
* @param base root Component (parent)
* @param id UIComponent id
* @return UIComponent object
*/
public static UIComponent findComponent(UIComponent base, String id) {
if (id.equals(base.getId()))
return base;

UIComponent children = null;
UIComponent result = null;
Iterator childrens = base.getFacetsAndChildren();
while (childrens.hasNext() && (result == null)) {
children = (UIComponent)childrens.next();
if (id.equals(children.getId())) {
result = children;
break;
}
result = findComponent(children, id);
if (result != null) {
break;
}
}
return result;
}

/**
* Method to create a redirect URL. The assumption is that the JSF servlet mapping is
* “faces”, which is the default
*
* @param view the JSP or JSPX page to redirect to
* @return a URL to redirect to
*/
public static String getPageURL(String view) {
FacesContext facesContext = getFacesContext();
ExternalContext externalContext = facesContext.getExternalContext();
String url =
((HttpServletRequest)externalContext.getRequest()).getRequestURL().toString();
StringBuffer newUrlBuffer = new StringBuffer();
newUrlBuffer.append(url.substring(0, url.lastIndexOf(“faces/”)));
newUrlBuffer.append(“faces”);
String targetPageUrl = view.startsWith(“/”) ? view : “/” + view;
newUrlBuffer.append(targetPageUrl);
return newUrlBuffer.toString();
}

/**
* Programmatic evaluation of EL.
*
* @param el EL to evaluate
* @return Result of the evaluation
*/
public static Object evaluateEL(String el) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
ValueExpression exp = expressionFactory.createValueExpression(elContext, el, Object.class);

return exp.getValue(elContext);
}
/**
* Programmatic invocation of a method that an EL evaluates to.
* The method must not take any parameters.
*
* @param el EL of the method to invoke
* @return Object that the method returns
*/
public static Object invokeEL(String el) {
return invokeEL(el, new Class[0], new Object[0]);
}
/**
* Programmatic invocation of a method that an EL evaluates to.
*
* @param el EL of the method to invoke
* @param paramTypes Array of Class defining the types of the parameters
* @param params Array of Object defining the values of the parametrs
* @return Object that the method returns
*/
public static Object invokeEL(String el, Class[] paramTypes, Object[] params) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
MethodExpression exp = expressionFactory.createMethodExpression(elContext, el, Object.class, paramTypes);

return exp.invoke(elContext, params);
}

}