How to execute method on page load method call in ADF Faces

1. Open the page definition of your JSF Page – TestOnPageLoad.jspx

2. Add the controllerlclass in the <PageDefinition> tag as given below

<pageDefinition xmlns=”http://xmlns.oracle.com/adfm/uimodel”
version=”11.1.1.60.13″ id=”TestOnPageLoadPageDef”
Package=”view.pageDefs”
ControllerClass=”com.test.bean.PageLoadBackingBean”>
3. Create the class – executeOnPageLoadMethod which implements PagePhaseListener and override the beforePhase method.

import oracle.adf.controller.faces.context.FacesPageLifecycleContext;
import oracle.adf.controller.v2.lifecycle.Lifecycle;
import oracle.adf.controller.v2.lifecycle.PagePhaseEvent;
import oracle.adf.controller.v2.lifecycle.PagePhaseListener;

import oracle.binding.BindingContainer;

public class executeOnPageLoadMethod implements PagePhaseListener {
private BindingContainer bc = null;

public void beforePhase(PagePhaseEvent event) {
FacesPageLifecycleContext ctx =
(FacesPageLifecycleContext)event.getLifecycleContext();
if (event.getPhaseId() == Lifecycle.PREPARE_MODEL_ID) {
bc = ctx.getBindingContainer();
onPageLoad();
bc = null;
}
}

public void afterPhase(PagePhaseEvent event) {
}

public void onPageLoad() {

}

}

3. Open the Class PageLoadBackingBean and extend the class – executeOnPageLoadMethod
public class PageLoadBackingBean extends executeOnPageLoadMethod {

4. Implement the method onPageLoad in the class – PageLoadBackingBean which is defined in the class – executeOnPageLoadMethod

/**
* Method to override the onPageLoad method of the executeOnPageLoadMethod
* which implements the PagePhaseListener Class
*/
public void onPageLoad() {
if (!AdfFacesContext.getCurrentInstance().isPostback()) {
executeSomeMethod();
}
}

5. public void executeSomeMethod() {

// execute some logic here
}

How ADF client authentication can be defined or set in the web.xml

<security-constraint>

<web-resource-collection>
<web-resource-name>allPages</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>valid-users</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>adfAuthentication</web-resource-name>
<url-pattern>/adfAuthentication</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>valid-users</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>CLIENT-CERT</auth-method>
</login-config>
<security-role>
<role-name>valid-users</role-name>
</security-role>

mime types to be defined in web.xml for pdf, css, images,javascript in the mime-mapping tag

If you are using the PDF or JavaScript or images with differnt extensions png, jpeg, gif then that should be defined

in the mime-mapping tag in the web.xml . Example is given below.
<mime-mapping>
<extension>pdf</extension>
<mime-type>application/pdf</mime-type>
</mime-mapping>
<mime-mapping>
<extension>javascript</extension>
<mime-type>application/x-javascript</mime-type>
</mime-mapping>
<mime-mapping>
<extension>css</extension>
<mime-type>text/css</mime-type>
</mime-mapping>
<mime-mapping>
<extension>swf</extension>
<mime-type>application/x-shockwave-flash</mime-type>
</mime-mapping>
<mime-mapping>
<extension>txt</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
<mime-mapping>
<extension>png</extension>
<mime-type>image/png</mime-type>
</mime-mapping>

How to identify the different user agent values for browsers in ADF Faces

Place the below sample code in your application to receive the user agent values for browsers like safari, chrome ,IE , Mozilla

public String getUserAgentValue() {
FacesContext facesCtx = FacesContext.getCurrentInstance().getCurrentInstance();
ExternalContext externalctx = facesCtx.getExternalContext();
HttpServletRequest request = (HttpServletRequest)externalctx.getRequest();
String userAgentVal = null;
userAgentVal=request.getHeader(“User-Agent”);
userAgentVal=userAgentVal.toLowerCase();

if (userAgentVal != null && userAgentVal.indexOf(“iphone”) > -1) {
userAgentVal = “iPhone”;
}

else if (userAgentVal != null && userAgentVal.indexOf(“android”) > -1) {
if (userAgentVal.indexOf(“mobile”) > -1)
userAgentVal = “Android Phone”;
else
userAgentVal = “Android Tablet”;
}

else if (userAgentVal != null && userAgentVal.indexOf(“ipad”) > -1) {
userAgentVal = “iPad”;
}

else if (userAgentVal != null && userAgentVal.indexOf(“macintosh”) > -1) {
userAgentVal = “Macbook”;
}

else if (userAgentVal != null && userAgentVal.indexOf(“windows”) > -1) {
userAgentVal = “Windows”;
}

else
{
userAgentVal=”Could not identify…”;
}

return userAgentVal;
}

How to remove default value “ALL” from the and

If you see the below given value in the SelectItem it does not show the value for “ALL” but still the option “ALL” will be shown
in the mutiple selection.

<af:selectManyChoice label=”SelectManyChoiceExp”
binding=”#{backingBeanScope.backing_sample.smc1}”
id=”smc1″>
<af:selectItem label=”One” value=”One”
binding=”#{backingBeanScope.backing_sample.si1}”
id=”si1″/>
<af:selectItem label=”Two” value=”Two”
binding=”#{backingBeanScope.backing_sample.si2}”
id=”si2″/>
</af:selectManyChoice>

<af:selectManyListbox label=”SelectManyListBoxExp”
binding=”#{backingBeanScope.backing_sample.sml1}”
id=”sml1″>
<af:selectItem label=”One” value=”One”
binding=”#{backingBeanScope.backing_sample.si3}”
id=”si3″/>
<af:selectItem label=”Two” value=”Two”
binding=”#{backingBeanScope.backing_sample.si4}”
id=”si4″/>
<af:selectItem label=”Three” value=”Three”
binding=”#{backingBeanScope.backing_sample.si5}”
id=”si5″/>
</af:selectManyListbox>

To remove this, select the component af:selectManyListbox or af:selectManyChoice and open the Apperance Tab in the Property Inspector
Search for the property field: SelectAllVisible and set it to FALSE.

How to display the data in the Line Graph using ADF Faces Line Graph Component

1) Select the Line Graph component from the ADF Data Visualizations Core Pallette
2) Drag it on the jspx page
3) Add the binding for the tabulardata instead of the default binding variable.

<dvt:lineGraph id=”lineGraph1″ subType=”LINE_VERT_ABS”
emptyText=”No Data To Display”
tabularData =”#{backingBeanScope.backing_sample.getLineGraphTabularData}”
contentDelivery=”immediate” >
<dvt:background>
<dvt:specialEffects/>
</dvt:background>
<dvt:graphPlotArea/>
<dvt:seriesSet>
<dvt:series/>
</dvt:seriesSet>
<dvt:o1Axis/>
<dvt:y1Axis/>
<dvt:legendArea automaticPlacement=”AP_NEVER”/>
</dvt:lineGraph>
</af:form>
</af:document>
</f:view>

How to pass value on the click of af:commandLink in ADF Faces using

<af:commandLink text=”#{TestBundle.CUST_LOC_NAME}” id=”we7″
action=”#{pageFlowScope.testBean.executeTestMethod}”
binding=”#{pageFlowScope.testBean.setBeanValueVar}”
disabled=”#{pageFlowScope.varCheckValue==null || pageFlowScope.varCheckValue==’true’}”>
<af:setActionListener from=”true”
to=”#{pageFlowScope.varTemp1}”/>
<af:setActionListener from=”false”
to=”#{pageFlowScope.varTemp2}”/>
<af:setActionListener from=”false”
to=”#{pageFlowScope.varTemp3}”/>
</af:commandLink>

How to set the label or output text value retrieve from the property file field value in JSF Page

1) Define the Property Bundle file in the ViewController Project.
2) In the Page, add the below given line to load the property bundle file
<f:loadBundle basename=”com.test.bundle.TestPropeertyBundle” var=”TestBundle”/>
3) Define the output text on the Page
<af:outputText value=”#{TestBundle.CUST_LOC_NAME}” id=”ot1″ />

define mutiple selection content delivery rangeSize value in ADF Faces af:table component

Drag and drop method from the availabled Data Control tab in source tab to create ADF Read-only Table and make the below given changes

1) single row selection in af:table : For the Single Row selection , rowSelection=”single” should be defined

<af:table value=”#{bindings.OrderStatusVO1.collectionModel}”
var=”row” rows=”#{bindings.OrderStatusVO1.rangeSize}”
emptyText=”#{bindings.OrderStatusVO1.viewable ? ‘No data to display.’ : ‘Access Denied.’}”
fetchSize=”#{bindings.OrderStatusVO1.rangeSize}”
rowBandingInterval=”0″ id=”t2″
rowSelection=”single”
selectedRowKeys=”#{bindings.OrderStatusVO1.collectionModel.selectedRow}”
selectionListener=”#{bindings.OrderStatusVO1.collectionModel.makeCurrent}”>
2) mutiple row selection in af:table : For the multiple row selection, rowSelection=”multiple” and remove the property selectedRowKeys from the table to make multiple row selection
work .

<af:table value=”#{bindings.OrderStatusVO1.collectionModel}”
var=”row” rows=”#{bindings.OrderStatusVO1.rangeSize}”
emptyText=”#{bindings.OrderStatusVO1.viewable ? ‘No data to display.’ : ‘Access Denied.’}”
fetchSize=”#{bindings.OrderStatusVO1.rangeSize}”
rowBandingInterval=”0″ id=”t2″
rowSelection=”multiple”
selectionListener=”#{bindings.OrderStatusVO1.collectionModel.makeCurrent}”>

3)change the rangeSize value : To make the change in the rangeSize value, either set the value for rangeSize instead of the expression value in the property rows
or make the change in the View Object where RangeSize is defined

Oracle ADF property file field value retrieval from the backing bean

The blog provides the steps for retrieving the property field value from the backing bean class.

1) Select the path for the properties file created in the View Controller Project

2) Open faces-config.xml placed in the WEB-INF folder of your application
3) Select Overview tab
4) Select the Application option
5) Select the path for properties file created in the ViewController Project Message Bundle field.
6) Open the Backing Bean file where value to be retrieved from the properties file

String customerLocationName = JSFUtils.getStringFromBundle(“CUST_LOC_NAME”);