Saturday, November 24, 2012

ADF : How to Implement Process Indicator ?

ADF : How to Implement Process Indicator ?














public class ProgressIndicatorBean {
    SimpleBoundedRangeModel _simpleBoundedRangeModel;
    private long pollInterval = -1;

    public ProgressIndicatorBean() {
    }

    public SimpleBoundedRangeModel getSimpleBoundedRangeModel() {
        if (_simpleBoundedRangeModel == null)
            _simpleBoundedRangeModel = new SimpleBoundedRangeModel();
        return _simpleBoundedRangeModel;
    }


    public void pollMe(PollEvent pollEvent) {
        if (_simpleBoundedRangeModel != null) {
            BindingContext bcntxt = BindingContext.getCurrent();
            BindingContainer bc = bcntxt.getCurrentBindingsEntry();
            OperationBinding op = bc.getOperationBinding("incrementCount");
            op.getParamsMap().put("input",
                                  _simpleBoundedRangeModel.getValue());
            op.execute();
            long value = (Long)op.getResult();
            if (value <= _simpleBoundedRangeModel.getMaximum()) {
                _simpleBoundedRangeModel.setValue(value);
            } else {
                pollInterval = -1;
                AdfFacesContextImpl.getCurrentInstance().addPartialTarget(pollEvent.getComponent());
            }

        }

    }

    public void setPollInterval(long pollInterval) {
        this.pollInterval = pollInterval;
    }

    public long getPollInterval() {
        return pollInterval;
    }

    public void startAction(ActionEvent actionEvent) {
        pollInterval = 200;
        _simpleBoundedRangeModel.start(actionEvent);
    }

    public void cancelAction(ActionEvent actionEvent) {
        pollInterval = -1;
        _simpleBoundedRangeModel.cancelProcess(actionEvent);
    }
}

---------------------------------------------------------------

public class SimpleBoundedRangeModel extends DefaultBoundedRangeModel {
    public SimpleBoundedRangeModel() {
        super(0, 100);
    }

    public void start(ActionEvent event) {
      setValue(1);
    }

    public void cancelProcess(ActionEvent event) {

        setValue(0);
        setMaximum(100);
    }


}

Friday, November 23, 2012

ADF : How to Upload a File?

How to Upload a File using ADF?
How to store image into database using ADF?





  

    public String commit() throws SQLException, IOException {
        img=(UploadedFile) if1.getValue();
        fileUpload(img,it1.getValue().toString(),it2.getValue().toString());
         return "view";
    }
   
   public String fileUpload(UploadedFile file, String fileId, String FileName) throws SQLException,
                                                     IOException {
       
            FileOperationAmDef = "model.fileOperation.am.FileOperationAM";
            FileOperationConfig = "FileOperationAMLocal";
            AM = Configuration.createRootApplicationModule(FileOperationAmDef,FileOperationConfig);
            ViewObject imgVO=AM.findViewObject("FileStoreView1");
            Row createImgRow = imgVO.createRow();
            imgVO.insertRow(createImgRow);
            createImgRow.setAttribute("FileId", fileId);
                    createImgRow.setAttribute("FileName", FileName);
                    createImgRow.setAttribute("FileContent", newBlobDomainForInputStream(file.getInputStream()));
            BindingContainer bindings = getBindings();
            AM.getTransaction().commit();
           
        return null;
        }
  
    private BlobDomain newBlobDomainForInputStream(InputStream is)
        throws SQLException, IOException{
            BlobDomain blbDmn = new BlobDomain();
            OutputStream os = blbDmn.getBinaryOutputStream();
            writeInputStreamToOutputStream(is, os);
            is.close();
            os.close();              
            return blbDmn;              
    }

    private static void writeInputStreamToOutputStream(InputStream in, OutputStream out)
        throws IOException{
            byte[] buffer = new byte[8192];
            int bytesRead = 0;
            while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
                out.write(buffer, 0, bytesRead);
            }
    }

 public BindingContainer getBindings() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();
    }

Thursday, November 22, 2012

ADF : How to Download a file ?

How to Download a file?
How to fetch the file/images from database?








public void viewImage (FacesContext context, OutputStream os) throws IOException
{
try {



HttpServletRequest request =
(HttpServletRequest)context.getCurrentInstance().getExternalContext().getRequest();
HttpSession session = request.getSession(false);
int imgId =
((Integer)session.getAttribute("imgId")).intValue();
HttpServletResponse response =
(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
os = response.getOutputStream();
String amDef = "com.neel.img.am.ImageAM";
String config = "ImageAMLocal";
ApplicationModule am =
Configuration.createRootApplicationModule(amDef, config);
ViewObjectImpl vo =
(ViewObjectImpl)am.findViewObject("ImageQueryVO1");

vo.setNamedWhereClauseParam("imgId",
(new Integer(imgId)).toString());
vo.setNamedWhereClauseParam("imgDocId", "1");
vo.executeQuery();
Row imgRow = vo.first();



BlobDomain image = (BlobDomain)imgRow .getAttribute("ImgContent");



String fileName = (String)imgRow .getAttribute("FileName");

String fileType = (String)imgRow.getAttribute("FileExt");
response.reset();
response.setContentType("image/jpeg");
response.setHeader("Content-Disposition",
"attachment;filename=" + fileName);
InputStream is = image.getInputStream();
// copy blob to output
byte[] buffer = new byte[10 * 1024];
int nread;
while ((nread = is.read(buffer)) != -1)
os.write(buffer, 0, nread);
os.close();
vo.setWhereClause(null);
Configuration.releaseRootApplicationModule(am, false);



return ;
} catch (Exception e) {
e.printStackTrace();
return ;
}


}


SELECT img_content, file_name, file_ext, img_doc_mast_id FROM ops_img_doc_dtls WHERE claim_id=:imgId AND img_doc_mast_id=:imgDocId

        Name="imgDocId"
      Kind="where"
      Type="java.lang.String"/>
         Name="imgId"
      Kind="where"
      Type="java.lang.String"/>

Monday, November 19, 2012

How to use ProcessScope ?

How to use ProcessScope ?


ADF : How to Convert String into oracle.jbo.domain.Date ?

 How to Convert String into oracle.jbo.domain.Date ?

public oracle.jbo.domain.Date castToJBODate(String aDate){
          DateFormat formatter;
          java.util.Date date;

          if(aDate!=null){

            try {

              formatter = new SimpleDateFormat("dd/MM/yyyy");
              date = formatter.parse(aDate);
              java.sql.Date sqlDate = new java.sql.Date(date.getTime());
              oracle.jbo.domain.Date jboDate = new oracle.jbo.domain.Date(sqlDate);

                return jboDate;
               } catch (ParseException e) {

                        e.printStackTrace();
                }

         }

         return null;
}

How to get Comma Seperated Value ?

How to get Comma Seperated Value ?

Use of  StringTokenizer class.

String str = "neel,mani,jaiswal";
StringTokenizer st = new StringTokenizer(str, ",");
while (st.hasMoreTokens()) {
     System.out.println(st.nextToken());
}
O/P :

neel
mani
jaiswal

Hash Map

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class HashMapTest {
  public static void main(String[] args) {
    Map map = new HashMap();
    map.put(new Integer(1), "MCA");
    map.put(new Integer(2), "MBA");
    map.put(new Integer(3), "BSc");
    map.put(new Integer(4), "MSc");
    map.put(new Integer(5), "MCA");
    System.out.println("Map Values Before: ");
    Set keys = map.keySet();
    for (Iterator i = keys.iterator(); i.hasNext();) {
      Integer key = (Integer) i.next();
      String value = (String) map.get(key);
      System.out.println(key + " = " + value);
    }
    System.out.println("\nRemove element with key 6");
    map.remove(new Integer(6));
    System.out.println("\nMap Values After: ");
    keys = map.keySet();
    for (Iterator i = keys.iterator(); i.hasNext();) {
      Integer key = (Integer) i.next();
      String value = (String) map.get(key);
      System.out.println(key + " = " + value);
    }
  }

Cast String to

Cast String into

int i = Integer.parseInt(str);

double aDouble = Double.parseDouble(aString);

ADF : How to get the Current Date Programatically?

ADF : How to get the Current Date Programatically ?

currDate = (new oracle.jbo.domain.Date()).getCurrentDate();

How to store the encrypted Password into Database?


How to encrypt the Password ?
How to encode the password?


    public static String encryptPassword(String password) {
         
           String encryptPassword = password;//getIt1().getValue().toString();
           byte[] unencodedPassword = encryptPassword.getBytes();
           MessageDigest md = null;
           try {
                md = MessageDigest.getInstance("MD5");
           } catch (Exception e) {
                   e.printStackTrace();
               }
           md.reset();
           md.update(unencodedPassword);
           byte[] encodedPassword = md.digest();
           StringBuffer buf = new StringBuffer();
           for (int i = 0; i < encodedPassword.length; i++) {
               if (((int) encodedPassword[i] & 0xff) < 0x10) {
               buf.append("0");
           }
                buf.append(Long.toString((int) encodedPassword[i] & 0xff, 16));
           }
            String passw=buf.toString();   
        
           return passw;
       }

ADF : How to remove the multiple record from an ADF table ?

ADF : How to remove the multiple record from an ADF table ?