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
Post a Comment