Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label HashMap. Show all posts
Showing posts with label HashMap. Show all posts

Wednesday 7 October 2015

ADF Basics: Reorder ADF table column using DisplayIndex property

This post is about a very simple use case that is reordering of af:table column at run time. 
Ordering of columns in af:table is controlled by DisplayIndex property of af:column
Check what docs says-

Default Value: -1

The display order index of the column. Columns can be re-arranged and they are displayed in the table based on the displayIndex. Columns are sorted based on the displayIndex property, columns without displayIndex are displayed at the end, in the order in which they appear. The displayIndex attribute is honored only for top level columns, since it is not possible to rearrange a child column outside of the parent column.
Not supported on the following renderkits: org.apache.myfaces.trinidad.core

We can set DisplayIndex property for all columns in a sequence (1,2,3 etc) that we want to see on page

Monday 17 August 2015

Showing HashMap values in af:table using af:iterator

Previously i have posted about populating af:table programmatically using List Data Structure
Populate af:table programmatically from managead bean using POJO

This post covers same topic but this time requirement is different , we have a HashMap in managed bean and requirement is to show it's values on page in a table view
See Managed Bean code-

    //HashMap and it's accessors
    private HashMap<String, String> valMap = new HashMap<String, String>();

    public void setValMap(HashMap valMap) {
        this.valMap = valMap;

    public HashMap getValMap() {
        return valMap;
    // Object array to store key values of HashMap
    public Object[] getKeySet() {
        return getValMap().keySet().toArray();

Added two inputText on page and a button to add new key and value to HashMap,

<af:panelFormLayout id="pfl1">
                    <af:inputText label="Key" id="it1" contentStyle="width:100px;"
                    <af:inputText label="Value" id="it2" contentStyle="width:100px;"
                    <af:button text="Add" id="b1" actionListener="#{viewScope.ShowHashMapAsTable.addValuesToMap}"/>

Now code on button that get value of both inputText using component binding and add it to HashMap, at run time this form will be used to add new values to HashMap and table

    //Component Binding of inputText to get values
    private RichInputText keyTextBind;
    private RichInputText valueTextBind;

    public void setKeyTextBind(RichInputText keyTextBind) {
        this.keyTextBind = keyTextBind;

    public RichInputText getKeyTextBind() {
        return keyTextBind;

    public void setValueTextBind(RichInputText valueTextBind) {
        this.valueTextBind = valueTextBind;

    public RichInputText getValueTextBind() {
        return valueTextBind;

    /**Add new value to HashMap
     * @param actionEvent
    public void addValuesToMap(ActionEvent actionEvent) {
        if (keyTextBind.getValue() != null && valueTextBind.getValue() != null) {
            valMap.put(keyTextBind.getValue().toString(), valueTextBind.getValue().toString());


Now Bean Part is done , see how to configure af:table to show HashMap values, table is mapped to array of keySet and an iterator is used inside table that derives value using key attribute -

<af:table var="row" rowBandingInterval="0" id="t1" value="#{viewScope.ShowHashMapAsTable.keySet}"
                        <af:iterator id="i1" value="#{viewScope.ShowHashMapAsTable.valMap}" var="cVal">
                            <af:column sortable="false" headerText="Key" id="c2">
                                <af:outputText value="#{row}" id="ot4" inlineStyle="font-weight:bold;color:darkblue;"/>
                            <af:column sortable="false" headerText="Value" id="c1">
                                <af:outputText value="#{cVal[row]}" id="ot3"/>

Now all done , run and check the application
 Add New Value (1)
  Add New Value (2)

Sample Application- Download (Jdev 12.1.3)
Cheers :) Happy Learning

Monday 3 August 2015

Iterate over HashMap to get Key and Value in Java , Add records to HashMap

Iterating over HashMap is not same as other collections , It's a bit tricky than normal iteration ;)
See in this code -
How to add values to HashMap ?
and How to iterate over HashMap to get Key and Values?

package client;

import java.util.HashMap;
import java.util.Iterator;

public class IterateHashMap {
    public IterateHashMap() {

    public static void main(String[] args) {
        HashMap<Integer, String> mapVal = new HashMap<Integer, String>();

        //Add values to Map
        mapVal.put(1, "value 1");
        mapVal.put(2, "value 2");
        mapVal.put(3, "value 3");
        mapVal.put(4, "value 4");

        //Create Iterator from keySet
        Iterator iter = mapVal.keySet().iterator();
        //Iterate over hashmap to get key
        while (iter.hasNext()) {
            int key = (Integer);
            //Use this key to find value
            String value = mapVal.get(key).toString();
            System.out.println("**KEY**  " + key + " AND VALUE**  " + value);


Cheers :) Happy Learning

Monday 20 May 2013

Set and Get Value from Taskflow parameter (pageFlowScope variable) from Managed Bean- ADF

Hello All

This post is about getting and setting value in taskFlow parameter using Java Code so for that we have created a application with bounded taskFlow

Let's see how to do this -

We have bounded taskflow having Input Parameter defined in it named GLBL_PARAM_TEST

Bounded Taskflow Input Parameters

and we have to set its value from managed bean.
this is very simple -see how to do that
  • Get pageFlowScope Map and put parameter 's value in it

  •         Map paramMap = RequestContext.getCurrentInstance().getPageFlowScope();
            paramMap.put("GLBL_PARAM_TEST", "Ashish"); 

  • And get Value from taskFlow parameter in managed bean

  •     public String resolvEl(String data){
                   FacesContext fc = FacesContext.getCurrentInstance();
                   Application app = fc.getApplication();
                   ExpressionFactory elFactory = app.getExpressionFactory();
                   ELContext elContext = fc.getELContext();
                   ValueExpression valueExp = elFactory.createValueExpression(elContext, data, Object.class);
                   String Message=valueExp.getValue(elContext).toString();
                   return Message;
    String param=resolvEl("#{pageFlowScope.GLBL_PARAM_TEST}");