Thursday, December 23, 2010

ADF Fileupload - InputFile with autosubmit & valuechange listener

Issue Description: JSF page have inputFile component to upload file which return uploadFile object.
I have binded this component to backingbeans uploadFile object. Also this component has autosubmit true and value change listener method and this form has submit button at the end. I want the value changelister to validate file type and few other validations and submit button to upload document to specific location on server. The problem is the value changelister is working fine but the submit button action method was returning null for this.uploadFile object (this does not happen when I set autosubmit property to false for inputFile component).

Sol: I created inputFile and a (hidden) textfield. I binded the textfield to the uploadfile object in backing bean instead of the inputFile component. The autosubmit and valuchangelistener remains as its is I just assigned the value to this textfield the upload file object as input which I can typecast in the submit action button. sample code:

package demo.view.backing;

import demo.view.ExcelADF;

import demo.view.UnitSubmission;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import java.util.ArrayList;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import javax.faces.event.ValueChangeEvent;

import oracle.adf.view.rich.component.rich.RichDocument;
import oracle.adf.view.rich.component.rich.RichForm;
import oracle.adf.view.rich.component.rich.input.RichInputFile;
import oracle.adf.view.rich.component.rich.input.RichInputText;
import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
import oracle.adf.view.rich.component.rich.output.RichMessages;

import oracle.adf.view.rich.context.AdfFacesContext;

import org.apache.myfaces.trinidad.context.RequestContext;
import org.apache.myfaces.trinidad.model.UploadedFile;

public class SampleFileUpload {
private RichForm f1;
private RichDocument d1;
private RichInputFile if1;
private RichCommandButton cb1;
private RichMessages m1;
private UploadedFile uploadedFile;
private UploadedFile uploadedFile1;
private String filename;
private long filesize;
private String filecontents;
private String filetype;

ArrayList dataHolder;
private RichInputText it1;


public void setF1(RichForm f1) {
this.f1 = f1;
}

public RichForm getF1() {
return f1;
}

public void setD1(RichDocument d1) {
this.d1 = d1;
}

public RichDocument getD1() {
return d1;
}


public void setIf1(RichInputFile if1) {
this.if1 = if1;
}

public RichInputFile getIf1() {
return if1;
}


public void setCb1(RichCommandButton cb1) {
this.cb1 = cb1;
}

public RichCommandButton getCb1() {
return cb1;
}

public void setM1(RichMessages m1) {
this.m1 = m1;
}

public RichMessages getM1() {
return m1;
}



public UploadedFile getUploadedFile() {
return uploadedFile;
}

public void setFilename(String filename) {
this.filename = filename;
}

public String getFilename() {
return filename;
}

public void setFilesize(long filesize) {
this.filesize = filesize;
}

public long getFilesize() {
return filesize;
}

public void setFilecontents(String filecontents) {
this.filecontents = filecontents;
}

public String getFilecontents() {
return filecontents;
}

public void setFiletype(String filetype) {
this.filetype = filetype;
}

public String getFiletype() {
return filetype;
}


public void setDataHolder(ArrayList dataHolder) {
this.dataHolder = dataHolder;
}

public ArrayList getDataHolder() {
return dataHolder;
}


public void fileUpdate(ValueChangeEvent valueChangeEvent) {
RichInputFile inputFileComponent = (RichInputFile)valueChangeEvent.getComponent();
UploadedFile newFile = (UploadedFile)valueChangeEvent.getNewValue();
newFile = (UploadedFile)valueChangeEvent.getNewValue();
it1.setValue(newFile);
// this.uploadedFile = newFile;
if (!newFile.getFilename().endsWith("xls")) {
FacesContext.getCurrentInstance().addMessage(inputFileComponent.getClientId(FacesContext.getCurrentInstance()),
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Only Excel files are allowed",
"This file (" +
newFile.getFilename() +
") is not allowed; the extension is not allowed."));
inputFileComponent.resetValue();
inputFileComponent.setValid(false);
}



}



public String SubmitAction() {
uploadedFile = (UploadedFile)it1.getValue();
System.out.println("File Name: "+uploadedFile.getFilename());
return null;
}

public void setUploadedFile1(UploadedFile uploadedFile1) {
this.uploadedFile1 = uploadedFile1;
}

public UploadedFile getUploadedFile1() {
return uploadedFile1;
}


public void setIt1(RichInputText it1) {
this.it1 = it1;
}

public RichInputText getIt1() {
return it1;
}
}

Thursday, December 16, 2010

java.lang.ClassNotFoundException: oracle.bpel.services.workflow.WorkflowException

Error during deployment of ADF 11g application server:
In Application Resources Pallette -> weblogic-application.xml add below lines

Thursday, December 2, 2010

ADF SelectOneChoice without base datasource

PageDefinition:
Create Iterator in your executables section.
and create a list binding in your bindings section to this iterator.
Sample page definition code:




















Page:
Drag and drop the selectonechoice component and bind it to above created binding.

Note that selectonechoice will return index, use iterator bind to get the value at selected index below is backing bean code
public void choiceListListener(ValueChangeEvent valueChangeEvent) {
DCIteratorBinding iter=((DCBindingContainer)getBindings()).findIteratorBinding("Departments1View1Iterator");
Row r=iter.getRowAtRangeIndex((Integer)valueChangeEvent.getNewValue());
System.out.println("Attr names"+r.getAttribute("DepartmentId"));
System.out.println("Attr names"+r.getAttribute("DepartmentName"));
System.out.println("atr1");
//set value of your variable equal to "value"
}

Monday, April 12, 2010

Iterator throws java.lang.NullPointerException

1) Go to page defination of JSF page
2) Select the Iterator you are using
3) Right click -> go to properties
4) In porperties change the RangeSize property to -1

Thursday, January 7, 2010

ADF 11g: Execute Operation defined in page defination from backing bean

BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("ExecuteWithParams");
Object result = operationBinding.execute();
if (!operationBinding.getErrors().isEmpty()) {
System.out.println("ERROR");
return null;
}

Thursday, October 29, 2009

Deploy ADF application on weblogic server (10.3)

(prerequisite) Create JNDI on weblogic server
In JDeveloper in
Model-> Rt clk your ApplicationModule file-> Configuration
- Edit both the setting (AppLocal & AppShared)
- Select Connection type to JDBC datasource (default is JDBC URL)
- Give proper DS name e.g java:comp/env/jdbc/MyDS (Note: Same DS name should be thr in weblogic server)
- Follow this for AppShared
- Now, Right clk ur application -> Deploy to EAR file
you can deploy EAR file on WEBLOGIC

Sunday, October 18, 2009

ADF 11g : Failed to lock the record, another user holds the lock.

Change the jbo.lockingmode property to optimistic

Select application module-> rt clik -> Configurations -> Edit -> (Properties tab)
Property: jbo.locking.mode replace pessimistic with optimistic