JSF to use selectoneradio button
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   atanu_m
Posted On:   Wednesday, February 15, 2012 02:46 AM

Insert title here I am trying to make a online exam application.There 5 questions with three options will come at a time.For options I used radiobutton.and everytime questions will change.But when I am trying to store the responses into the database it is not storing.But if the questions are same then responses are storing. Please use html tags to format code blocks. ***************This is My jsf page************* <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@ taglib prefix="h" uri="http://java.sun.c   More>>
Insert title here

I am trying to make a online exam application.There 5 questions with three options will come at a time.For options I used radiobutton.and everytime questions will change.But when I am trying to store the responses into the database it is not storing.But if the questions are same then responses are storing.

Please use html tags to format code blocks.
***************This is My jsf page*************




<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


















<%=session.getAttribute("abc1") %> <%=session.getAttribute("abc8") %>






















































































*********This is my FetchQuestion class*********





package DAO;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import Connection.*;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import javax.swing.text.StyledEditorKit.BoldAction;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Restrictions;
import org.hibernate.mapping.Array;

import com.sun.org.apache.bcel.internal.generic.NEW;

import Model.*;

public class FetchQuestion
{
Question1Bean questionBean=new Question1Bean();
//Session sess=null;
public String response;
int serialNo=0;


public int getSerialNo() {
return serialNo;
}

public void setSerialNo(int serialNo) {
this.serialNo = serialNo;
}


public void setResponse(String response) {
this.response = response;
}

public Question1Bean getQuestionBean() {
return questionBean;
}

public void setQuestionBean(Question1Bean questionBean) {
this.questionBean = questionBean;
}


ArrayList qbean=new ArrayList ();
ArrayList qbean2=new ArrayList ();
ArrayList qbean3=new ArrayList ();
ArrayList qbean4=new ArrayList ();
ArrayList qbean5=new ArrayList ();
ArrayList obean1= new ArrayList ();
ArrayList obean2= new ArrayList ();
ArrayList obean3= new ArrayList ();
ArrayList obean4= new ArrayList ();
ArrayList obean5= new ArrayList ();
ArrayList arr= new ArrayList ();
ArrayList ques=new ArrayList ();

//------------------------
static int size;
public ArrayList qid1=new ArrayList();
public ArrayList qid2=new ArrayList();
public ArrayList qid3=new ArrayList();
public ArrayList qid4=new ArrayList();
public ArrayList qid5=new ArrayList();
@SuppressWarnings("unchecked")
static ArrayList qids=new ArrayList();
static ArrayList nqid=new ArrayList();
@SuppressWarnings("unchecked")
ArrayList spliteddi=new ArrayList();
ArrayList sdi=(ArrayList )spiltDi(0.3f);

@SuppressWarnings("unchecked")
ArrayList listofQids=new ArrayList();
@SuppressWarnings("unchecked")
ArrayList listofQids1=fetchQids(0.1f);
@SuppressWarnings({ "unchecked" })
ArrayList listofQids2=fetchQids(0.2f);
ArrayList listofQids3=fetchQids(0.3f);
ArrayList listofQids4=fetchQids(0.4f);
ArrayList listofQids5=fetchQids(0.5f);
ArrayList listofQids6=fetchQids(0.6f);
ArrayList listofQids7=fetchQids(0.7f);
ArrayList listofQids8=fetchQids(0.8f);
ArrayList listofQids9=fetchQids(0.9f);
ArrayList listofQids10=fetchQids(1.0f);
int p=0;
ArrayList fetchQids(float di)
{
SessionFactory factory=new Configuration().configure().buildSessionFactory();
Session session =factory.openSession();
String str="select q.qid from Question1Bean q where di="+di+"";
Query q=session.createQuery(str);
listofQids=(ArrayList) q.list();

return listofQids;

}
@SuppressWarnings("unchecked")
public ArrayList spiltDi(float rdi)
{
float di1,di2,di3,di4,di5;
di1=rdi-0.2f;
di2=rdi-0.1f;
di3=rdi;
di4=rdi+0.1f;
di5=rdi+0.2f;
if(di1 <0.1)
di1=0.1f;
if(di1>1)
di1=1;
if(di2 <0.1)
di2=0.1f;
if(di2>1)
di2=1;
if(di3 <0.1)
di3=0.1f;
if(di3>1)
di3=1;
if(di4 <0.1)
di4=0.1f;
if(di4>1)
di4=1;
if(di5 <0.1)
di5=0.1f;
if(di5>1)
di5=1;
spliteddi.add(di1);
spliteddi.add(di2);
spliteddi.add(di3);
spliteddi.add(di4);
spliteddi.add(di5);
System.out.println("spliteddi"+spliteddi.get(0));
return spliteddi;

}


@SuppressWarnings("unchecked")
ArrayList randomGen(float di)
{

ArrayList arr=new ArrayList();
/*SessionFactory factory=new Configuration().configure().buildSessionFactory();
Session session =factory.openSession();
String str="select q.qid from Question1Bean q";
Query q=session.createQuery(str);
ArrayList arr=(ArrayList) q.list();*/
arr.clear();
if(di==0.1f)
{
arr=listofQids1;

}
if(di==0.2f)
{
arr=listofQids2;
}
if(di==0.3f)
{

arr=listofQids3;

}
if(di==0.4f)
{
arr=listofQids4;
}
if(di==0.5f)
{
arr=listofQids5;
}
if(di==0.6f)
{
arr=listofQids6;
}
if(di==0.7f)
{
arr=listofQids7;
}
if(di==0.8f)
{
arr=listofQids8;
}
if(di==0.9f)
{
arr=listofQids9;
}
if(di==1.0f)
{
arr=listofQids10;
}


boolean flag1=false;
while(flag1==false)
{
Collections.shuffle(arr);
System.out.println("NA"+arr.get(0));
System.out.println("NB"+qids.size());
for(int i=0;i
{

if(arr.get(0).equals(qids.get(i)))
{
System.out.println("Already present");
flag1=false;
break;
}
else
flag1=true;
}
if(qids.size()==0)
flag1=true;

}

nqid.clear();
nqid.add(arr.get(0));
qids.add(arr.get(0));
for(int i=0;i
System.out.println("QID:="+qids.get(i));
for(int i=0;i
System.out.println("NQID:="+nqid.get(i));

/*

size=qids.size()-1;
System.out.println("SIZE"+size);
for(int i=0;i
{
System.out.println("qidsSS"+qids.get(i));
}*/

return nqid;

}
//------------------------------
public ArrayList getQues() {
return ques;
}

public void setQues(ArrayList ques) {
this.ques = ques;
}

public void setArr(ArrayList arr) {
this.arr = arr;
}
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session1 = (HttpSession) facesContext.getExternalContext().getSession(true);
public ArrayList getQbean()
{
Session sess=null;
try
{
System.out.println("PP****"+p);

String di;
float di2 = 0;
if(p%3==0)
{
di= sdi.get(0).toString();
di2=java.lang.Float.valueOf(di);
di2=Math.round(di2*10f);
di2=di2/10;

System.out.println("DI1:="+di2);
qid1=randomGen(di2);
}
System.out.println("qid***&&&"+qid1.get(0));
sess=Connection.getSession();
String sql="from Question1Bean where qid="+qid1.get(0)+"";
Double di1=0.1;
//HttpSession session1 = (HttpSession) facesContext.getExternalContext().getSession(true);
//session1.setAttribute("abc","2");
arr.add("2");

System.out.println("++++++++++ QID ++++++++++"+(Integer.parseInt(qid1.get(0).toString())));
//System.out.println("++++++++++ di ++++++++++"+di2);

QuestionId_DI_bean quest1=new QuestionId_DI_bean();
quest1.setQid(Integer.parseInt(qid1.get(0).toString()));
quest1.setDi(di2);
ques.add(quest1);
System.out.println("qbean ------------------------------");

Query qr=sess.createQuery(sql);

System.out.println("arraylist----qbean");
qbean=(ArrayList )qr.list();



System.out.println("list "+qbean.size());


for(int i=0;i
{
System.out.println("list "+qbean.get(i).getQuestion());
}

}

catch(Exception e)
{
System.out.println("Exception in MEDao and fetch question");
e.printStackTrace();
}
finally
{
sess.flush();
sess.close();
}
return qbean;
}

public ArrayList getObean1()
{
Session sess1=null;
ArrayList op1=new ArrayList();

try
{
sess1=Connection.getSession();
System.out.println("Obean1--1------------");
String sql="from Question1Bean where qid="+qid1.get(0)+"";
System.out.println("Obean1--2------------");
Query qr=sess1.createQuery(sql);

obean1=(ArrayList )qr.list();
if(obean1.get(0).getOption1()!=null)
{
System.out.println("Obean1------------1");
op1.add(obean1.get(0).getOption1());
}
if(obean1.get(0).getOption2()!=null)
{System.out.println("Obean1------------2");
op1.add(obean1.get(0).getOption2());
}
if(obean1.get(0).getOption3()!=null)
{ System.out.println("Obean1------------3");
op1.add(obean1.get(0).getOption3());
}
if(obean1.get(0).getOption4()!=null)
{
op1.add(obean1.get(0).getOption4());
}
if(obean1.get(0).getOption5()!=null)
{
op1.add(obean1.get(0).getOption5());
}
if(obean1.get(0).getOption6()!=null)
{
op1.add(obean1.get(0).getOption6());
}

System.out.println("list "+obean1.size());
System.out.println("list "+obean1.get(0).getOption1()+"jkjkj"+obean1.get(0).getOption2()+"jkkjkjk"+obean1.get(0).getOption1());

for(int i=0;i
{
System.out.println("list "+obean1.get(i).getQuestion());
}




}

catch(Exception e)
{
System.out.println("Exception in MEDao and fetch question");
e.printStackTrace();
}
finally
{
sess1.flush();
sess1.close();

}
/*ArrayList arr=new ArrayList ();
arr.add("OPtion1");
arr.add("OPtion2");
arr.add("OPtion3");*/
return op1;
}

public void setObean1(ArrayList obean1) {
this.obean1 = obean1;
}
public ArrayList getQbean2()
{
Session sess2=null;
try
{
System.out.println("PP****"+p);

String di;
float di1=0;
if(p%3==0)
{
di= sdi.get(1).toString();
di1=Float.parseFloat(di);
qid2.clear();

di1=Math.round(di1*10f);
di1=di1/10;
System.out.println("DI2"+di1);
qid2=randomGen(di1);
}
System.out.println("qid***&&&"+qid2.get(0));
sess2=Connection.getSession();
System.out.println("qbean2-------------");
String sql1="from Question1Bean where qid="+qid2.get(0)+"";

Query qr=sess2.createQuery(sql1);
System.out.println("arraylist----qbean2");
//HttpSession session2 = (HttpSession) facesContext.getExternalContext().getSession(true);
//session1.setAttribute("abc3","3");
arr.add("3");
qbean2=(ArrayList )qr.list();
double di2=0.2;

QuestionId_DI_bean quest2=new QuestionId_DI_bean();
System.out.println("++++++++++ QID ++++++++++"+(Integer.parseInt(qid2.get(0).toString())));
System.out.println("++++++++++ di ++++++++++"+di1);
quest2.setQid(Integer.parseInt(qid2.get(0).toString()));
quest2.setDi(di1);
ques.add(quest2);


System.out.println("list "+qbean.size());


for(int i=0;i
{
System.out.println("list "+qbean.get(i).getQuestion());
}

}

catch(Exception e)
{
System.out.println("Exception in MEDao and fetch question");
e.printStackTrace();
}
finally
{
sess2.flush();
sess2.close();
}
return qbean2;
}
public ArrayList getObean2()
{
Session sess3=null;
ArrayList op2=new ArrayList();
try
{
sess3=Connection.getSession();
System.out.println("Obean2--1------------");
String sql="from Question1Bean where qid="+qid2.get(0)+"";
System.out.println("Obean2--2------------");
Query qr=sess3.createQuery(sql);

obean2=(ArrayList )qr.list();
if(obean2.get(0).getOption1()!=null)
{
System.out.println("Obean2------------1");
op2.add(obean2.get(0).getOption1());
}
if(obean2.get(0).getOption2()!=null)
{System.out.println("Obean2------------2");
op2.add(obean2.get(0).getOption2());
}
if(obean2.get(0).getOption3()!=null)
{ System.out.println("Obean2------------3");
op2.add(obean2.get(0).getOption3());
}
if(obean2.get(0).getOption4()!=null)
{
op2.add(obean2.get(0).getOption4());
}
if(obean2.get(0).getOption5()!=null)
{
op2.add(obean2.get(0).getOption5());
}
if(obean2.get(0).getOption6()!=null)
{
op2.add(obean2.get(0).getOption6());
}



}

catch(Exception e)
{
System.out.println("Exception in MEDao and fetch question");
e.printStackTrace();
}
finally
{
sess3.flush();
sess3.close();
}

return op2;

/*ArrayList arr=new ArrayList ();
arr.add("OPtionere");
arr.add("OPtioneer");
arr.add("OPtionere");
return arr;*/

}

public void setObean2(ArrayList obean2) {
this.obean2 = obean2;
}

public ArrayList getObean3()
{
Session sess4=null;
ArrayList op3=new ArrayList();
try
{
sess4=Connection.getSession();
System.out.println("Obean3---1------------");
String sql="from Question1Bean where qid="+qid3.get(0)+"";
System.out.println("Obean3---2------------");
Query qr=sess4.createQuery(sql);

obean3=(ArrayList )qr.list();
if(obean3.get(0).getOption1()!=null)
{System.out.println("Obean3------------1");
op3.add(obean3.get(0).getOption1());
}
if(obean3.get(0).getOption2()!=null)
{System.out.println("Obean3------------2");
op3.add(obean3.get(0).getOption2());
}
if(obean3.get(0).getOption3()!=null)
{ System.out.println("Obean3------------3");
op3.add(obean3.get(0).getOption3());
}
if(obean3.get(0).getOption4()!=null)
{
op3.add(obean3.get(0).getOption4());
}
if(obean3.get(0).getOption5()!=null)
{
op3.add(obean3.get(0).getOption5());
}
if(obean3.get(0).getOption6()!=null)
{
op3.add(obean3.get(0).getOption6());
}



}

catch(Exception e)
{
System.out.println("Exception in MEDao and fetch question");
e.printStackTrace();
}
finally
{
sess4.flush();
sess4.close();
}

return op3;
/*ArrayList arr=new ArrayList ();
arr.add("OPtionioi");
arr.add("OPtionio");
arr.add("OPtionio");
return arr;*/
}

public void setObean3(ArrayList obean3) {
this.obean3 = obean3;
}

public ArrayList getObean4()
{
Session sess5=null;
ArrayList op4=new ArrayList();
try
{
sess5=Connection.getSession();
System.out.println("option4");
System.out.println("Obean4--1-----------1");
String sql="from Question1Bean where qid="+qid4.get(0)+"";
System.out.println("Obean4--2-----------2");
Query qr=sess5.createQuery(sql);

obean4=(ArrayList )qr.list();
if(obean4.get(0).getOption1()!=null)
{System.out.println("Obean4------------1");
op4.add(obean4.get(0).getOption1());
}
if(obean4.get(0).getOption2()!=null)
{System.out.println("Obean4------------2");
op4.add(obean4.get(0).getOption2());
}
if(obean4.get(0).getOption3()!=null)
{ System.out.println("option4------------3");
op4.add(obean4.get(0).getOption3());
}
if(obean4.get(0).getOption4()!=null)
{
op4.add(obean4.get(0).getOption4());
}
if(obean4.get(0).getOption5()!=null)
{
op4.add(obean4.get(0).getOption5());
}
if(obean4.get(0).getOption6()!=null)
{
op4.add(obean4.get(0).getOption6());
}



}

catch(Exception e)
{
System.out.println("Exception in MEDao and fetch question");
e.printStackTrace();
}
finally
{
sess5.flush();
sess5.close();
}
return op4;
/*ArrayList arr=new ArrayList ();
arr.add("OPtionyu");
arr.add("OPtionyu");
arr.add("OPtionyuy");
return arr;*/
}

public void setObean4(ArrayList obean4) {
this.obean4 = obean4;
}

public ArrayList getObean5()
{
Session sess6=null;
ArrayList op5=new ArrayList();
try
{
sess6=Connection.getSession();
String sql="from Question1Bean where qid="+qid5.get(0)+"";
System.out.println("option5");
Query qr=sess6.createQuery(sql);

obean5=(ArrayList )qr.list();
if(obean5.get(0).getOption1()!=null)
{ System.out.println("option5----------1");
op5.add(obean5.get(0).getOption1());
}
if(obean5.get(0).getOption2()!=null)
{
System.out.println("option5----------2");
op5.add(obean5.get(0).getOption2());
}
if(obean5.get(0).getOption3()!=null)
{
System.out.println("option5---------------3");
op5.add(obean5.get(0).getOption3());
}
if(obean5.get(0).getOption4()!=null)
{
op5.add(obean5.get(0).getOption4());
}
if(obean5.get(0).getOption5()!=null)
{
op5.add(obean5.get(0).getOption5());
}
if(obean5.get(0).getOption6()!=null)
{
op5.add(obean5.get(0).getOption6());
}



}

catch(Exception e)
{
System.out.println("Exception in MEDao and fetch question");
e.printStackTrace();
}
finally
{
sess6.flush();
sess6.close();
}
return op5;
/*ArrayList arr=new ArrayList ();
arr.add("OPtionyuyu");
arr.add("OPtionyu");
arr.add("OPtionyuy");
return arr;*/
}

public void setObean5(ArrayList obean5) {
this.obean5 = obean5;
}



public int showSerialNumber()
{
return serialNo=serialNo+1;
}

public ArrayList getQbean3()
{
Session sess7=null;
try
{
System.out.println("PP****"+p);

String di;
float di1=0;
if(p%3==0)
{
di=sdi.get(2).toString();
di1=Float.parseFloat(di);

di1=Math.round(di1*10f);
di1=di1/10;

qid3=randomGen(di1);
}
System.out.println("qid***&&&"+qid3.get(0));
sess7=Connection.getSession();
System.out.println("qbean----------3");
String sql2="from Question1Bean where qid="+qid3.get(0)+"";

Query qr=sess7.createQuery(sql2);
System.out.println("arraylist----qbean3");
//HttpSession session3 = (HttpSession) facesContext.getExternalContext().getSession(true);
//session1.setAttribute("abc4","4");
arr.add("4");
qbean3=(ArrayList )qr.list();
double di3=0.3;

QuestionId_DI_bean quest3=new QuestionId_DI_bean();
System.out.println("++++++++++ QID ++++++++++"+(Integer.parseInt(qid3.get(0).toString())));
System.out.println("++++++++++ di ++++++++++"+di1);

quest3.setQid(Integer.parseInt(qid3.get(0).toString()));
quest3.setDi(di1);
ques.add(quest3);


System.out.println("list "+qbean.size());


for(int i=0;i
{
System.out.println("list "+qbean.get(i).getQuestion());
}

}

catch(Exception e)
{
System.out.println("Exception in MEDao and fetch question");
e.printStackTrace();
}
finally
{
sess7.flush();
sess7.close();
}
return qbean3;
}



public ArrayList getQbean4()
{
Session sess8=null;
try
{
System.out.println("PP****"+p);

String di;
float di1=0;
if(p%3==0)
{
di= sdi.get(3).toString();
di1=Float.parseFloat(di);
di1=Math.round(di1*10f);
di1=di1/10;
qid4=randomGen(di1);
}
System.out.println("qid***&&&"+qid4.get(0));
sess8=Connection.getSession();
System.out.println("qbean4---------");
String sql3="from Question1Bean where qid="+qid4.get(0)+"";

Query qr=sess8.createQuery(sql3);
System.out.println("arraylist----qbean4");
//HttpSession session4 = (HttpSession) facesContext.getExternalContext().getSession(true);
//session1.setAttribute("abc5","5");
arr.add("5");
qbean4=(ArrayList )qr.list();

double di4=0.4;

QuestionId_DI_bean quest4=new QuestionId_DI_bean();
System.out.println("++++++++++ QID ++++++++++"+(Integer.parseInt(qid4.get(0).toString())));
System.out.println("++++++++++ di ++++++++++"+di1);
quest4.setQid(Integer.parseInt(qid4.get(0).toString()));
quest4.setDi(di1);
ques.add(quest4);

System.out.println("list "+qbean.size());


for(int i=0;i
{
System.out.println("list "+qbean.get(i).getQuestion());
}

}

catch(Exception e)
{
System.out.println("Exception in MEDao and fetch question");
e.printStackTrace();
}
finally
{
sess8.flush();
sess8.close();
}
return qbean4;
}



public ArrayList getQbean5()
{
Session sess9=null;
try
{
String di;
float di1=0;
System.out.println("PP****"+p);

if(p%3==0)
{

di= sdi.get(4).toString();
di1=Float.parseFloat(di);

di1=Math.round(di1*10f);
di1=di1/10;
System.out.println("AAAAA"+sdi.get(4).toString());
qid5=randomGen(di1);
}
p++;
System.out.println("qid***&&&"+qid5.get(0));
sess9=Connection.getSession();
System.out.println("qbean5");
String sql4="from Question1Bean where qid="+qid5.get(0)+"";

Query qr=sess9.createQuery(sql4);
System.out.println("qbean5--------------arrayList");

arr.add("8");

/*System.out.println("iddddddddddddd-----------------------------"+arr.size());
for(int i=0;i
{
System.out.println("iddddddd---"+arr.get(i));
}*/
//HttpSession session5 = (HttpSession) facesContext.getExternalContext().getSession(true);
//session1.setAttribute("abc6",8);
session1.setAttribute("abc6",arr);
System.out.println("list "+arr.size());
qbean5=(ArrayList )qr.list();

double di5=0.5;

QuestionId_DI_bean quest5=new QuestionId_DI_bean();
System.out.println("++++++++++ QID ++++++++++"+(Integer.parseInt(qid5.get(0).toString())));
System.out.println("++++++++++ di ++++++++++"+di1);
quest5.setQid((Integer.parseInt(qid5.get(0).toString())));
quest5.setDi(di1);
ques.add(quest5);

session1.setAttribute("abc8",ques);
System.out.println("list "+qbean.size());
System.out.println("idddddddddddd &&&&&&&&&& diiiiiiii-----------------------------"+arr.size());
for(int i=0;i
{
System.out.println("ques-----------id----------"+ques.get(i).getQid());
System.out.println("ques-----------di----------"+ques.get(i).getDi());
}

for(int i=0;i
{
System.out.println("list "+qbean.get(i).getQuestion());
}

}

catch(Exception e)
{
System.out.println("Exception in MEDao and fetch question");
e.printStackTrace();
}
finally
{
sess9.flush();
sess9.close();
}
return qbean5;
}


public void setQbean2(ArrayList qbean2) {
this.qbean2 = qbean2;
}
public void setQbean3(ArrayList qbean3) {
this.qbean3 = qbean3;
}
public void setQbean(ArrayList qbean) {
this.qbean = qbean;
}
public void setQbean5(ArrayList qbean5) {
this.qbean5 = qbean5;
}
public void setQbean4(ArrayList qbean4) {
this.qbean4 = qbean4;
}

//ArrayList intex=new ArrayList ();
//ArrayList intex=new ArrayList ();
ArrayList intex1=new ArrayList ();
public void setIntex1(ArrayList intex1) {
this.intex1 = intex1;
}

public ArrayList getIntex1()
{
Session sess11=null;
try
{
sess11=Connection.getSession();
System.out.println("qidddddddddddd");
String sql11="select q.qid from Question1Bean q where q.di=0.1";
System.out.println("qidddddddddddd 1");
Query qr=sess11.createQuery(sql11);
intex1=(ArrayList )qr.list();
System.out.println("qidddddddddddd 2"+intex1.size());
for(int i=0;i
{
System.out.println("list "+intex1.get(i));
intex1.get(i);
/*intex1.add(intex.get(i).getQid());
System.out.println("list "+intex.get(i).getQid());*/
}

}
catch(Exception e)
{
e.printStackTrace();
System.out.println("print arraylist of question ids");
}
return intex1;
}

public ArrayList getArr() {
return arr;
}

public String getResponse()
{
getQbean() ;
getQbean2() ;
getQbean3() ;
getQbean4() ;
getQbean5() ;
return response;
}





*************This is my response class************






package DAO;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import Connection.*;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import javax.swing.text.StyledEditorKit.BoldAction;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Restrictions;
import org.hibernate.mapping.Array;

import com.sun.org.apache.bcel.internal.generic.NEW;

import Model.*;

public class Response {


//HtmlDataTable myDataTable=new HtmlDataTable();

response_save response_save=new response_save();


public response_save getResponse_save() {
return response_save;
}
public void setResponse_save(response_save responseSave) {
response_save = responseSave;
}

private String response1;
private String response2;
private String response3;
private String response4;
private String response5;

public String OptionResponse() {
System.out.println("hello"+getResponse1());
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session1 = (HttpSession) facesContext.getExternalContext().getSession(true);

String name=(String)session1.getAttribute("abc1");
String name1=(String)session1.getAttribute("abc2");

ArrayList arr12=new ArrayList ();
ArrayList question=new ArrayList ();


arr12=(ArrayList )session1.getAttribute("abc6");
question=(ArrayList )session1.getAttribute("abc8");

System.out.println("Question___Di----Qid-----*****************"+question.size());

for(int i=0;i
{
System.out.println("++++++********DI****************++++++++++"+question.get(i).getDi());
System.out.println("+++++********QID****************++++++++"+question.get(i).getQid());
}

System.out.println("hello"+getResponse2()+" arrayList "+arr12.size());
System.out.println("hello"+getResponse2()+" arrayList "+arr12);
System.out.println("hello"+getResponse3()+" name "+name+" password "+name1);


System.out.println("hello"+getResponse4());
System.out.println("hello"+getResponse5());
System.out.println("list "+arr12.get(1).toString());
for(int i=0;i <(arr12.size()-5);i++)
{
System.out.println("+++++++++++++++ list ++++++++++++++++++++++ "+arr12.get(i).toString());
}
ArrayList arr=new ArrayList ();
ArrayList arr1=new ArrayList ();
arr1.add(getResponse1());
arr1.add(getResponse2());
arr1.add(getResponse3());
arr1.add(getResponse4());
arr1.add(getResponse5());
System.out.println("response by session ________________-- "+arr1.size());
for(int i=0;i
{
System.out.println("response by session ________________-- "+arr1.get(i));
}
int j=0;
Session sess=null;
//org.hibernate.Transaction tx=sess.beginTransaction();
ArrayList resultDI=new ArrayList ();
float DI=0,DI_total=0,DI_perc=0,next_set_DI=0,DI_avg=0;
try
{
for(int i=0;i
{
System.out.println("++++++111111********DI****************++++++++++"+question.get(i).getDi());
System.out.println("+++++222222222********QID****************++++++++"+question.get(i).getQid());
}
sess=Connection.getSession();
String sql="select q.answer from Question1Bean q where (q.qid="+question.get(0).getQid()+" or q.qid="+question.get(1).getQid()+" or q.qid="+question.get(2).getQid()+" or q.qid="+question.get(3).getQid()+" or q.qid="+question.get(4).getQid()+")";
Query qr=sess.createQuery(sql);
System.out.println("query----------------");

arr=(ArrayList )qr.list();
for(int i=0;i
{
if(arr.get(i).equals(arr1.get(i)))
{
j=1;
resultDI.add(question.get(i).getDi());

}
else
{
j=0;
}

DI_total=DI_total+question.get(i).getDi();
org.hibernate.Transaction tx=sess.beginTransaction();
System.out.println("responses________________________________"+j);
response_save.setResponse(j);
response_save.setQid(Integer.parseInt(arr12.get(i).toString()));
response_save.setExaminee_id(name);
response_save.setExam_id(name1);
sess.save(response_save);
tx.commit();
sess.flush();
sess.clear();
System.out.println("list "+arr.get(i));
}
System.out.println("################ TOTAL_DI #SIZE#####"+DI_total);

System.out.println("################ RESULTANT_DI #SIZE#####"+resultDI.size());

for(int i=0;i
{
System.out.println("&&&&&&&&&& Di &&&&&&&&&&&&&&"+resultDI.get(i));
DI=DI+resultDI.get(i);
}
System.out.println("^^^^^^^^^^^^ RESULTANT DI FINAL^^^^^^^^"+DI);

if(DI_total != 0)
{
DI_avg=(DI/DI_total);
DI_perc=(DI/DI_total)*100;
System.out.println("(((((((((((( DI_PERCENTAGE )))))))))"+DI_perc);
System.out.println("^^^^^^^^^^^^ RESULTANT DI FINAL AVERAGE^^^^^^^^"+DI_avg);
}
else
{
System.out.println("(((((((((((( TOTAL_DI=ZERO )))))))))");
}
// || ((DI_perc>20) && (DI_perc <=40)) || ((DI_perc>40) && (DI_perc <=60)) || ((DI_perc>60) && (DI_perc <=80)) || ((DI_perc>80) && (DI_perc <=100))
if((DI_perc>=0) && (DI_perc <=20))
{
//next_set_DI=DI-0.2;
if((DI_avg>=0.0) && (DI_avg <0.2))
{
next_set_DI=DI_avg;
}
else
{
next_set_DI=DI_avg-0.2f;
}
}
else if((DI_perc>20) && (DI_perc <=40))
{
//next_set_DI=DI-0.1;
if((DI_avg>=0.0) && (DI_avg <0.1))
{
next_set_DI=DI_avg;
}
else
{
next_set_DI=DI_avg-0.1f;
}
}
else if((DI_perc>40) && (DI_perc <=60))
{
next_set_DI=DI_avg;
}
else if((DI_perc>60) && (DI_perc <=80))
{
//next_set_DI=DI+0.1;
if((DI_avg>0.9) && (DI_avg <=1.0))
{
next_set_DI=DI_avg;
}
else
{
next_set_DI=DI_avg+0.1f;
}
}
else if((DI_perc>80) && (DI_perc <=100))
{
//next_set_DI=DI+0.2;
if((DI_avg>0.8) && (DI_avg <=1.0))
{
next_set_DI=DI_avg;
}
else
{
next_set_DI=DI_avg+0.2f;
}
}

System.out.println("@@@@@@@@@@ NEXT SET DI @@@@@@@@@@@@@"+next_set_DI);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("in response class");
}


return "hh";
}

private ArrayList arr=new ArrayList ();
public ArrayList getArr() {
return arr;
}
public void setArr(ArrayList arr) {
this.arr = arr;
}
public String getResponse1() {
return response1;
}
public void setResponse1(String response1) {
this.response1 = response1;
}
public String getResponse2() {
return response2;
}
public void setResponse2(String response2) {
this.response2 = response2;
}
public String getResponse3() {
return response3;
}
public void setResponse3(String response3) {
this.response3 = response3;
}
public String getResponse4() {
return response4;
}
public void setResponse4(String response4) {
this.response4 = response4;
}
public String getResponse5() {
return response5;
}
public void setResponse5(String response5) {
this.response5 = response5;
}

//generated by nirjhar
/*public HtmlDataTable getMyDataTable() {
return myDataTable;
}
public void setMyDataTable(HtmlDataTable myDataTable) {
this.myDataTable = myDataTable;
}*/









/*public String getOptionResponse()
{
//edited by nirjhar

int n=myDataTable.getChildCount();


for(int i=0;i
{
ArrayList chilelist= (ArrayList) myDataTable.getChildren();

for(int j=0;j
{
System.out.println(chilelist.get(i).getClass());
}

}




return "success";

}*/
}

Please help me to find out a solution...........

}

   <<Less
About | Sitemap | Contact