Month: January 2011

How to capture the Task programmatically through Managed Bean (Adf – Soa Suite – Human Task)

Hi,

This is another useful code that lets you to capture the task with full attributes from your Java Class (Managed Bean).


import oracle.bpel.services.workflow.WorkflowException;
import oracle.bpel.services.workflow.client.IWorkflowServiceClient;
import oracle.bpel.services.workflow.datacontrol.WorkflowService;
import oracle.bpel.services.workflow.query.ITaskQueryService;
import oracle.bpel.services.workflow.task.model.TaskImpl;
import oracle.bpel.services.workflow.verification.IWorkflowContext;

public TaskImpl getCurrentTaskFromWorkflow() throws WorkflowException {
    TaskImpl task = null;
    Map parameters=AdfFacesContext.getCurrentInstance().getPageFlowScope();
    IWorkflowServiceClient wfSvcClient = WorkflowService.getWorkflowServiceClient();
    ITaskQueryService queryService = wfSvcClient.getTaskQueryService();
    String contextId = (String)parameters.get("bpmWorklistContext");
    IWorkflowContext context = queryService.getWorkflowContext(contextId);
    String taskId = (String)parameters.get("bpmWorklistTaskId");
    String strTaskVersion = (String)parameters.get("bpmWorklistTaskVersion");
    if(taskId != null){
        int taskVersion = 0;
        if(strTaskVersion != null && !strTaskVersion.trim().equals("")){
            try{
                taskVersion = Integer.parseInt(strTaskVersion);
            } catch(NumberFormatException exc){
                taskVersion = 1;
            }
        }
        if(taskVersion == 0){
            task = (TaskImpl)queryService.getTaskDetailsById(context, taskId);
        }else{
            task = (TaskImpl)queryService.getTaskVersionDetails(context, taskId, taskVersion);
        }
    }
    return task;
}

How to capture programmatically (Java – Adf Faces) an attribute from payload task (Human Task Form)

Hi Guys,

This is an useful code that capture the value of an attribute inside of payload from Human Task generated automatically from bpel.

Here is a list of attributes that exists in your human task form.

With this code, you can capture the value of any attribute.

You can to call this method this way: getValueAttributeFromHumanTask(“numeroPedido”)


import oracle.adf.model.BindingContext;
import oracle.adf.view.rich.context.AdfFacesContext;
import oracle.binding.AttributeBinding;
import oracle.binding.BindingContainer;
import oracle.bpel.services.datacontrol.data.DataObject;

public String getValueAttributeFromHumanTask(String attributeName){
    String response = "";
    BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
    AttributeBinding attr = (AttributeBinding)bindings.getControlBinding(attributeName);
    DataObject data = null;
    if(attr != null){
        data = (DataObject)attr.getInputValue();
    }
    if(data != null){
        response = data.getValue();
    }
    return response;
}

How to set recursively component properties using Java Server Faces (JSF)

Hello,

I am using a piece of code that setting disabled=true and readonly=true to all components inside of a Form, but you can use this in other situations:

In your .jspx File:

<f:view beforePhase="#{someController.makeFormReadOnly}">

In your .java File:


import javax.faces.application.Application;
import javax.faces.context.FacesContext;
import javax.faces.component.UIComponent;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import java.lang.reflect.Method;

public void makeFormReadOnly(FacesContext facesContext, UIComponent component) {
    try {
        Method[] methods = component.getClass().getMethods();
        for (Method method : methods) {
            if (method.getName().equals("getChildren")) {
                List<UIComponent> listaComp = (List<UIComponent>)method.invoke(component);
                for (UIComponent comp : listaComp) {
                    makeFormReadOnly(facesContext, comp);
                }
            }
        }
        component.setValueExpression("readOnly", getValueExpression(facesContext, "#{true}"));
        component.setValueExpression("disabled", getValueExpression(facesContext, "#{true}"));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

private ValueExpression getValueExpression(FacesContext facesContext, String name) {
    Application app = facesContext.getApplication();
    ExpressionFactory elFactory = app.getExpressionFactory();
    ELContext elContext = facesContext.getELContext();
    return elFactory.createValueExpression(elContext, name, Object.class);
}