Results 1 to 12 of 12
  1. #1
    PinkRose is offline Member
    Join Date
    Feb 2014
    Posts
    17
    Rep Power
    0

    Default how to access getter/setter of bean class,where it defined as member in anotherclass

    Class UserAssessBean{
    private String username;
    private int userid;
    private ArrayList<ModuleBean> module;
    --{get/set}--
    }

    Class ModuleBean{
    private String modulename;
    private int moduleid;
    --{get/set}--
    }

    How can i access the getters/setters of module bean, when it was returned as array list in UserAssessBean?

  2. #2
    ankurt is offline Member
    Join Date
    Feb 2014
    Posts
    11
    Rep Power
    0

    Default Re: how to access getter/setter of bean class,where it defined as member in anotherc

    You can create a reference of ModuleBean and then make it refer to a single element of the ArrayList returned and then access the setters/getters normally using that reference variable.

    Does it solve the purpose?

  3. #3
    PinkRose is offline Member
    Join Date
    Feb 2014
    Posts
    17
    Rep Power
    0

    Default Re: how to access getter/setter of bean class,where it defined as member in anotherc

    Thank you......

    i solved it..........

    But i retrieve those value and put it in hashmap with key/value pair and added it(hashmap) to arraylist to generate json response......

    i got a same set of values repeatedly instead of retreiving all values...........

  4. #4
    ankurt is offline Member
    Join Date
    Feb 2014
    Posts
    11
    Rep Power
    0

    Default Re: how to access getter/setter of bean class,where it defined as member in anotherc

    You must put your code so that it is more clear.

  5. #5
    PinkRose is offline Member
    Join Date
    Feb 2014
    Posts
    17
    Rep Power
    0

    Default Re: how to access getter/setter of bean class,where it defined as member in anotherc

    This is the part of my coding............
    public static String getUserDetails(UserAssessBean bean) throws SQLException{
    JSONObject jsonObject = new JSONObject();
    String result= bean.toString();
    try{
    connection= UserAssesmentDBUtility.getConnection();
    ArrayList<ModuleBean> ambean =SampleDao.getUserModule();
    String sql = " select * from groupview where userid='"+bean.getUserID() +"' ";
    pst = connection.prepareStatement(sql);
    rs = pst.executeQuery();
    while(rs.next()){
    bean.setUserID(rs.getLong("userid"));
    bean.setGroupID(rs.getLong("groupid"));
    bean.setGroupName(rs.getString("groupname"));
    bean.setModules(ambean);
    jsonObject.put("Authentication", bean.getAuthentication());
    jsonObject.put("UserID", bean.getUserID());
    jsonObject.put("GroupID", bean.getGroupID());
    jsonObject.put("GroupName", bean.getGroupName());

    ArrayList<ModuleBean> mbean =SampleDao.getUserModule();
    int modulesize=mbean.size();
    HashMap<Object,Object> jsonModuleObject = new HashMap<Object,Object>();
    ArrayList<Object> object = new ArrayList<Object>();
    for(int i=0;i<modulesize;i++)
    {
    ModuleBean mbeanobj = mbean.get(i);
    jsonModuleObject.put("ModuleID",mbeanobj.getModule ID() );
    jsonModuleObject.put("ModuleName",mbeanobj.getModu leName() );
    jsonModuleObject.put("ModuleSeq",mbeanobj.getModul eSeq() );
    jsonModuleObject.put("ModuleExpDate",mbeanobj.getM oduleExpDate() );
    ArrayList<SubModuleBean> sbean =SampleDao.getUserSubModule();
    int size=sbean.size();
    HashMap<Object,Object> jsonSubModuleObject = new HashMap<Object,Object>();
    ArrayList<Object> subobject = new ArrayList<Object>();
    for(int j=0;j<size;j++)
    {
    SubModuleBean sbeanobj = sbean.get(j);
    jsonSubModuleObject.put("SubModuleID",sbeanobj.get SubModuleID());
    jsonSubModuleObject.put("SubModuleName",sbeanobj.g etSubModuleName());
    jsonSubModuleObject.put("SubModuleSeq",sbeanobj.ge tSubModuleSeq());
    jsonSubModuleObject.put("SubModuleExpDate",sbeanob j.getSubModuleExpDate());
    subobject.add(jsonSubModuleObject);
    }
    JSONArray jsonSubArray = new JSONArray(subobject);
    jsonModuleObject.put("SubModules",jsonSubArray);
    object.add(jsonModuleObject);
    }
    JSONArray jsonArray = new JSONArray(object);
    jsonObject.put("Modules",jsonArray);
    }
    result=jsonObject.toString();
    }catch(Exception e){
    e.printStackTrace();

    }
    return result;
    }

  6. #6
    PinkRose is offline Member
    Join Date
    Feb 2014
    Posts
    17
    Rep Power
    0

    Default Re: how to access getter/setter of bean class,where it defined as member in anotherc

    Hi,

    its retreiving properly when i print it in console, but Json respone produces only the last value from db ..........

  7. #7
    ankurt is offline Member
    Join Date
    Feb 2014
    Posts
    11
    Rep Power
    0

    Default Re: how to access getter/setter of bean class,where it defined as member in anotherc

    Can you debug it by printing the value in Json everytime the data is entered.

  8. #8
    PinkRose is offline Member
    Join Date
    Feb 2014
    Posts
    17
    Rep Power
    0

    Default Re: how to access getter/setter of bean class,where it defined as member in anotherc

    i am not clear......... what did u say?

  9. #9
    ankurt is offline Member
    Join Date
    Feb 2014
    Posts
    11
    Rep Power
    0

    Default Re: how to access getter/setter of bean class,where it defined as member in anotherc

    Can you put your code in a better format , have it enclosed with opening and closing "Code" tags and also put some comments.

  10. #10
    PinkRose is offline Member
    Join Date
    Feb 2014
    Posts
    17
    Rep Power
    0

    Default Re: how to access getter/setter of bean class,where it defined as member in anotherc

    Hi,

    i solved it..........
    i got the output..............
    Thank u very much for u comments.............

  11. #11
    ankurt is offline Member
    Join Date
    Feb 2014
    Posts
    11
    Rep Power
    0

    Default Re: how to access getter/setter of bean class,where it defined as member in anotherc

    can you share, what was the problem?

  12. #12
    PinkRose is offline Member
    Join Date
    Feb 2014
    Posts
    17
    Rep Power
    0

    Default Re: how to access getter/setter of bean class,where it defined as member in anotherc

    The problem was with JSONArray.............

    I did following changes.......... The Changes in coding are highlight with red color.............

    public static String getUserDetails(UserAssessBean bean) throws SQLException{
    JSONObject jsonObject = new JSONObject();
    String result= bean.toString();
    try{
    connection= UserAssesmentDBUtility.getConnection();
    ArrayList<ModuleBean> ambean =SampleDao.getUserModule();
    String sql = " select * from groupview where userid='"+bean.getUserID() +"' ";
    pst = connection.prepareStatement(sql);
    rs = pst.executeQuery();
    while(rs.next()){
    bean.setUserID(rs.getLong("userid"));
    bean.setGroupID(rs.getLong("groupid"));
    bean.setGroupName(rs.getString("groupname"));
    bean.setModules(ambean);
    jsonObject.put("Authentication", bean.getAuthentication());
    jsonObject.put("UserID", bean.getUserID());
    jsonObject.put("GroupID", bean.getGroupID());
    jsonObject.put("GroupName", bean.getGroupName());

    ArrayList<ModuleBean> mbean =SampleDao.getUserModule();
    int modulesize=mbean.size();
    HashMap<Object,Object> jsonModuleObject = new HashMap<Object,Object>();
    JSONArray jsonArray = new JSONArray();
    for(int i=0;i<modulesize;i++)
    {
    ModuleBean mbeanobj = mbean.get(i);
    jsonModuleObject.put("ModuleID",mbeanobj.getModule ID() );
    jsonModuleObject.put("ModuleName",mbeanobj.getModu leName() );
    jsonModuleObject.put("ModuleSeq",mbeanobj.getModul eSeq() );
    jsonModuleObject.put("ModuleExpDate",mbeanobj.getM oduleExpDate() );
    ArrayList<SubModuleBean> sbean =SampleDao.getUserSubModule();
    int size=sbean.size();
    HashMap<Object,Object> jsonSubModuleObject = new HashMap<Object,Object>();
    JSONArray jsonSubArray = new JSONArray();
    for(int j=0;j<size;j++)
    {
    SubModuleBean sbeanobj = sbean.get(j);
    jsonSubModuleObject.put("SubModuleID",sbeanobj.get SubModuleID());
    jsonSubModuleObject.put("SubModuleName",sbeanobj.g etSubModuleName());
    jsonSubModuleObject.put("SubModuleSeq",sbeanobj.ge tSubModuleSeq());
    jsonSubModuleObject.put("SubModuleExpDate",sbeanob j.getSubModuleExpDate());
    jsonSubArray.put(jsonSubModuleObject);
    }
    jsonModuleObject.put("SubModules",jsonSubArray);
    ;jsonArray.put(jsonModuleObject)
    }
    jsonObject.put("Modules",jsonArray);
    }
    result=jsonObject.toString();
    }catch(Exception e){
    e.printStackTrace();

    }
    return result;
    }

Similar Threads

  1. setter and getter
    By rajeev in forum New To Java
    Replies: 2
    Last Post: 08-18-2013, 03:59 AM
  2. Call remote getter/setter
    By rcbandit in forum Advanced Java
    Replies: 1
    Last Post: 06-26-2013, 04:46 PM
  3. getter and setter method help please!
    By merdzins in forum New To Java
    Replies: 2
    Last Post: 12-06-2010, 06:06 AM
  4. use of private in getter and setter
    By katturv in forum New To Java
    Replies: 1
    Last Post: 12-03-2010, 08:17 PM
  5. Creating a Defined Class with Member Functions
    By New2Java in forum New To Java
    Replies: 6
    Last Post: 08-05-2009, 10:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •