Skip to main content

Integrating servlet in ADF application

Follow the following steps :


1. Create servlet in your viewcontroller(i.e required package).

2.When you create the servlet it gives you the url of your servlet.
  ex. if name of your servlet is TempServlet.java then the url would be /tempServlet.

3.You can use this url wherever you want.That will be required in jsff inside the inlineframe

4.If you want to use it on popup then use inflineframe component .
  ex. <af:inlineFrame id="if1" source="/tempServlet"/>

5. Use the doGet method of servlet to show the values from the servlet to the page or do the functionality what you want.
  
    ex.

     public void doGet(HttpServletRequest request,HttpServletResponse response)
                                throws  ServletException,IOException
{
        String caseId = request.getSession().getAttribute("allocationCaseId").toString();
        CaseMgmtBean bean=new CaseMgmtBean();       
        ArrayList bboutPutArray = (ArrayList)bean.getBlackBoxoutput(caseId);       // get bboutput
        PrintWriter out = response.getWriter();
        if(bboutPutArray.size()>0){
            HashMap partyNames =bean.getPartyDetails(caseId);    // get party all names      
            ArrayList partyIds=bean.getPartyIds(caseId);              // get all party ids
                                  
            ArrayList billCode=new ArrayList();
            billCode.add("Bill Code");
            ArrayList billDesc=new ArrayList();
            billDesc.add("Bill Description");
            ArrayList expAmt=new ArrayList();
            expAmt.add("Expected Amount");
            ArrayList totalAmount=new ArrayList();
            totalAmount.add("Total");
            Iterator itr= bboutPutArray.iterator();
            while(itr.hasNext()){
                HashMap map = (HashMap)itr.next();
                map.get("0");      // get billcode
                billCode.add(map.get("0"));
                billDesc.add(map.get("1"));
                expAmt.add(map.get("2"));
                totalAmount.add(map.get("2"));
               
            }
            out.println("<html>");
            out.println("<head> <script type='text/javascript'>"+            // this is java script i used
            "    function changeAmount(oObject){ " +
            "    var id=oObject.id ; " +
            "   var oldId='hid'+'_'+id;"+
            "   var oldAmount=document.getElementById(oldId).value;"+       
            "   var newAmount=document.getElementById(id).value;"+
            "   var arr=id.split('_');" +
            "   var bid=arr[1];"+
            "   var oldTotal=document.getElementById(bid).value;"+
            "   var newTotal=(parseFloat(oldTotal)-parseFloat(oldAmount)+parseFloat(newAmount));"+           
            "   document.getElementById(oldId).value=newAmount;"+
            "   document.getElementById(bid).value=newTotal;"+
//            "   alert(document.getElementById(bid).value);"+   
            " }");
            out.println("</script>");
            out.println("<title>ProposedBillingServlet</title>");
            out.println("</head>");
           
            out.println("<body><form method='post'>");
            out.println("<table id='t1' border='1' cellpadding='1' cellspacing='' style='width:100%;'>");
            out.println("<tr>");
            for(int i=0;i<billCode.size();i++){
                out.println("<td>");
                out.println(billCode.get(i));
                out.println("</td>");
            }
            out.println("</tr>");
            out.println("<tr>");
            for(int i=0;i<billDesc.size();i++){
                out.println("<td>");
                out.println(billDesc.get(i));
                out.println("</td>");
            }
            out.println("</tr>");
           
            out.println("<tr>");
            for(int i=0;i<expAmt.size();i++){
                out.println("<td>");
                out.println(expAmt.get(i));
                out.println("</td>");
            }
            out.println("</tr>");
           
            // set part amount
            Iterator partyItr = partyIds.iterator();
            while(partyItr.hasNext()){
                String party_id = (String)partyItr.next();
                String partyName = (String)partyNames.get(party_id);
                Iterator bItr = bboutPutArray.iterator();
                out.println("<tr>");
                out.println("<td>");
                out.println(partyName);
                out.println("</td>");
                while(bItr.hasNext()){
                          
                 HashMap map = (HashMap)bItr.next();
                 out.println("<td>");
                 out.println("<input type=\"text\" value='"+map.get(party_id)+"' id='"+party_id+"_"+map.get("0")+"' name='"+party_id+"_"+map.get("0")+"' onblur='changeAmount(this)'>");  //set party amount  and id of the component and read the  component  value through this id
                        out.println("<input type='Hidden' value='"+map.get(party_id)+"' id='hid_"+party_id+"_"+map.get("0")+"'>");  //used to get older amount 
                        out.println("</td>");
                       
                    }
                out.println("</tr>");
            }
            out.println("<tr>");
            for(int i=0;i<totalAmount.size();i++){
                out.println("<td>");
                out.println("<input type=\"text\" name=\"totalAmount\" value='"+totalAmount.get(i)+"' id='"+billCode.get(i)+"' readonly>");
                out.println("</td>");
            }
            out.println("</tr>");
            out.println("</table>");
            out.println("<table id='t2' cellpadding='1' cellspacing='' style='width:100%;'>");
            out.println("<tr>");
            out.println("<td>");
            out.println("<input type=\"submit\" name=\"usrname\" value=\"Generate BillLine\">");
            out.println("</td>");
            out.println("</tr>");
            out.println("</table>");
            out.println("</form></body></html>");
            out.close();
        }
        else{
            out.println("<p>The fee schedule selected for this case does not have any proposed billing.</p>");
            out.println("<p>You will need to manually create any bills that are required at this time. Thank you.</p>");
            out.close();
           
        }
       
    }

6.CaseMgmtBean bean is a bean in your ADF application that may be Managed or Backing
   and i am using some methods from that bean.

7.Through this you can have the handle of the components which you are creating through the html-servlet.

8.in doPost method you can capture the values of the components by their ids and use those values
  for your functionalites.
 ex.
  
       public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        String caseId = request.getSession().getAttribute("allocationCaseId").toString();
        CaseMgmtBean bean=new CaseMgmtBean();       
        ArrayList bboutPutArray = (ArrayList)bean.getBlackBoxoutput(caseId);       // get bboutput
        if(bboutPutArray.size()>0){
            ArrayList partyIds=bean.getPartyIds(caseId);              // get all party ids
            Iterator partyItr = partyIds.iterator();
            while(partyItr.hasNext()){
                String party_id = (String)partyItr.next();
                Iterator bItr = bboutPutArray.iterator();
                while(bItr.hasNext()){
                        HashMap map = (HashMap)bItr.next();
                        String amount=request.getParameter(party_id+"_"+map.get("0"));
                        map.remove(party_id);
                        map.put(party_id, amount);
                    }
              }
          }
       System.out.println(bboutPutArray);
       String rs=bean.genBillLine(bboutPutArray,caseId);
       out.println(rs);
    }

9.You need to register the servlet
   i.If you are using one common ViewController for your project then register in web.xml of that VC.
   ii.If you are creating the servlet in the same ViewController then no need to register jdev does this  work for you.


Comments

Popular posts from this blog

Passivation and Activation in ADF (Application Module )

1. For performance reasons, ADF keeps a pool of application modules in memory. It tries to give each session the same application module as the session used during the last request; however, this might not be possible during peak load of your application. 2. In this case, ADF saves the application modules state in a database table so the application module can be used by another session. This is called passivation . 3. When the first session needs the application module again, its state is retrieved from the database process known as activation . 4. If you have made an error in your code and depend on some variable that is not persisted correctly when your application module state is stored, you will experience mysterious errors under high load.   Enable/Disable Application Module Pooling : Right-click on your application module, choose Configurations.By default, each application module has two configurations. Ensure that the one ending in …Local is selected and then click

Get modified rows from Entitiy Cache

To get the modified rows from entity cache we have getEntityState() method at EntityImpl class. Refer to my previous blog  Accessing EO impl methods from VO impl  where i am overriding the getEntityState() in EOimpl and calling it in VOImpl. We can use methods written or overridden in VOImpl class to AMImpl class. There are different states associated with an entity object. STATUS_UNMODIFIED STATUS_MODIFIED STATUS_NEW STATUS_DELETED STATUS_DEAD We have to check the state or row in our AmImpl class by using the VOImpl method and through this we can distinguish the rows present at vo. Add below code in AMImpl class along with my previous post. public void geCachedRowsCount(){         JobsVOImpl jobsVo = (JobsVOImpl)this.getJobsVO();         RowSetIterator iter = jobsVo.createRowSetIterator(null);             while(iter.hasNext()){             Row row = iter.next();             byte state = jobsVo.getEntityState(row);             System.out.println("Job_id -&

The file store "WLS_DIAGNOSTICS" could not be opened

WLS_DIAGNOSTIC ERROR weblogic.store.PersistentStoreException: [Store:280073]The file store "WLS_DIAGNOSTICS" could not be opened because it contained a file with the invalid version 1. A file of version 2 was expected. When you get this error while running your application on internal weblogic server delete the following file WLS_DIAGNOSTICS000000.DAT search the file in following path C:\jdev_work\system11.1.1.5.37.60.13\DefaultDomain this file is in DefaultDomain folder of your jdev. and delete the WLS_DIAGNOSTICS000000.DAT file . and run your applicatuon