Sunday, December 9, 2012

Active Data Service With Active Image andActive Output text

Hi

In my last post i have explained about active data with bar graph component that was little bit tricky but for implementing active data service with active image and  active output text are easy to implements.

Implementation of Active Data Service with Active Image :

Step 1:Extends BaseActiveDataModel class and override method.Code is following

package com.blog.example.image.model;

import java.util.ArrayList;
import java.util.Collection;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import java.util.concurrent.atomic.AtomicInteger;

import oracle.adf.view.rich.activedata.ActiveModelContext;
import oracle.adf.view.rich.activedata.BaseActiveDataModel;
import oracle.adf.view.rich.event.ActiveDataEntry;
import oracle.adf.view.rich.event.ActiveDataUpdateEvent;

import oracle.adfinternal.view.faces.activedata.ActiveDataEventUtil;

public class ImageActiveModelClass extends BaseActiveDataModel
{
    private final AtomicInteger changeCounter = new AtomicInteger();
    private static final Timer timer = new Timer();
    private final AtomicInteger counter = new AtomicInteger(0);
    List<String> list = new ArrayList<String>();
    private String image = "/image/graphPage.png";
    static int j = 0;

    public ImageActiveModelClass() {
        super();
        list.add("/image/inde1x.jpg");
        list.add("/image/index.jpg");
        list.add("/image/index2.jpg");
        list.add("/image/index3.jpg");
        list.add("/image/index4.jpg");
        list.add("/image/index7.jpg");
        list.add("/image/index8.jpg");
        list.add("/image/index9.jpg");
        list.add("/image/index10.jpg");
        list.add("/image/index11.jpg");
        ActiveModelContext context =
            ActiveModelContext.getActiveModelContext();
        Object[] keyPath = new String[0];
        context.addActiveModelInfo(this, keyPath, "image");
        timer.schedule(new UpdateTask(), 2000, 2000);
    }

    protected void startActiveData(Collection<Object> collection, int i) {
    }

    protected void stopActiveData(Collection<Object> collection) {
    }

    @Override
    public int getCurrentChangeCount() {
        return changeCounter.get();
    }


    public void setImage(String image) {
        this.image = image;
    }

    public String getImage() {
        return image;
    }

    protected class UpdateTask extends TimerTask {
        public void run() {
            counter.incrementAndGet();
            ActiveDataUpdateEvent event =
                ActiveDataEventUtil.buildActiveDataUpdateEvent(ActiveDataEntry.ChangeType.UPDATE,
                                                               counter.get(),
                                                               new String[0],
                                                               null,
                                                               new String[] { "image" },
                                                               new Object[] { list.get(j) });
            fireActiveDataUpdate(event);
            j = j + 1;
            if (j == 10) {
                j = 0;
            }
        }
    }

}

Step2: For register active image with ads i have written following code

        ActiveModelContext context =
            ActiveModelContext.getActiveModelContext();
        Object[] keyPath = new String[0];
        context.addActiveModelInfo(this, keyPath, "image");

Step3:Register ImageActiveModelClass class in adfc-config.xml with session scope

<?xml version="1.0" encoding="windows-1252" ?>
<adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2">
  <managed-bean id="__2">
    <managed-bean-name id="__4">imageActive</managed-bean-name>
    <managed-bean-class id="__3">com.blog.example.image.model.ImageActiveModelClass</managed-bean-class>
    <managed-bean-scope id="__1">session</managed-bean-scope>
  </managed-bean>
  <managed-bean id="__6">
    <managed-bean-name id="__8">outPutActive</managed-bean-name>
    <managed-bean-class id="__5">com.blog.example.output.model.OutPutActiveDataModel</managed-bean-class>
    <managed-bean-scope id="__7">session</managed-bean-scope>
  </managed-bean>
</adfc-config>

Step 4:jspx code is following

<?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">
      <af:form id="f1">
        <af:activeImage source="#{imageActive.image}" id="ai1"/>
        <af:activeOutputText id="aot1" value="#{outPutActive.outPut}"/>
      </af:form>
    </af:document>
  </f:view>
</jsp:root>


Same step i have implemented for active out put text also.you can find code at following link.

Link is

https://docs.google.com/open?id=0B8cP4jZuxLlXN2pQYzN6Ql91Vlk


Thank,
Prateek


No comments:

Post a Comment