Advanced Search

Results 1 to 4 of 4

Thread: Checkbox pagination

  1. #1
    Join Date
    Nov 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Checkbox pagination

    I have pagination in the page. The problem I have is, I will loose the status of the checkbox when I go to second page. If I select some of the checkboxes in page 1 and go to page 2 to select some more and if I come back, I loose all the selected checkboxes in page 1.
    Is there a way where I could save my check boxes in session and its checked while I browse across pages and gets submitted all at once? Could you please help me?

  2. #2
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    Please include your code so that we can take a look at it, we can't do much without it. When you do post your code remember to use [code] tags. That includes [ html ], [ code ], and [ php ].

    Please post a link to the site you found this script at.

    Please post a link to the page on your site that contains the problematic script so we can check it out.

    Please do the above before further help.

    Also - are you using ajax to load the pages or is it within a div?
    Jeremy | jfein.net

  3. #3
    Join Date
    Nov 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Checkbox pagination problem and maintain status of checked checkboxes

    please i have send this my code...pleae help me out

    Domain.java
    Code:
    package com.web.abc.integration.model;   
    import java.util.HashMap;   
      
    public class Domain {   
        private int domainId;   
        private String domainName;   
        private int categoryId;   
           
           
        public Domain() {   
           
        }   
        public Domain(int domainId, String domainName, int categoryId ) {   
            super();   
            this.domainId = domainId;   
            this.domainName = domainName;   
            this.categoryId = categoryId;   
               
        }   
           
        public int getDomainId() {   
            return domainId;   
        }   
        public void setDomainId(int domainId) {   
            this.domainId = domainId;   
        }   
        public String getDomainName() {   
            return domainName;   
        }   
        public void setDomainName(String domainName) {   
            this.domainName = domainName;   
        }   
        public int getCategoryId() {   
            return categoryId;   
        }   
        public void setCategoryId(int categoryId) {   
            this.categoryId = categoryId;   
        }   
      
        public String toString() {   
            return "Domain [categoryId=" + categoryId + ", domainId=" + domainId   
                    + ", domainName=" + domainName + "]";   
        }   
      
           
    }
    Category.java

    Code:
    package com.web.abc.integration.model;   
      
      
    public class Category {   
        private int categoryId;   
        private String categoryName;   
        public Category() {   
            super();   
            // TODO Auto-generated constructor stub   
        }   
        public Category(int categoryId, String categoryName) {   
            super();   
            this.categoryId = categoryId;   
            this.categoryName = categoryName;   
        }   
        public int getCategoryId() {   
            return categoryId;   
        }   
        public void setCategoryId(int categoryId) {   
            this.categoryId = categoryId;   
        }   
        public String getCategoryName() {   
            return categoryName;   
        }   
        public void setCategoryName(String categoryName) {   
            this.categoryName = categoryName;   
        }   
        @Override  
        public String toString() {   
            return "[ "+this.categoryId+" : "+this.categoryName+" ]";   
        }   
           
    }
    DomainDAO.java
    Code:
    package com.web.abc.integration.dao;   
      
    import java.sql.Connection;   
    import java.sql.DriverManager;   
    import java.sql.ResultSet;   
    import java.sql.SQLException;   
    import java.sql.Statement;   
    import java.util.Collection;   
    import java.util.HashMap;   
      
    import com.web.abc.integration.model.Domain;   
      
    public class DomainDAO {   
        private Connection connection;   
        private Statement statement;   
        private ResultSet resultset;   
           
        private HashMap<Integer, Domain>domainmap;   
        String dbUrl = "jdbc:mysql://localhost:3306/entity?user=root;password=rahul";   
        String dbClass = "com.mysql.jdbc.Driver";   
               
        public HashMap<Integer, Domain> getDomainmap() {   
            return domainmap;   
        }   
        public void setDomainmap(HashMap<Integer, Domain> domainmap) {   
            this.domainmap = domainmap;   
        }   
        public DomainDAO() {   
           
        }   
        public HashMap<Integer,Domain> getDomains(int categoryId){   
            domainmap=new HashMap<Integer,Domain>();   
            try {   
                resultset=statement.executeQuery("select * from domain where categoryId="+categoryId);   
                while(resultset.next()){   
                    domainmap.put(resultset.getInt(1), new Domain (resultset.getInt(1),resultset.getString(2),resultset.getInt(3)));   
                       
                }   
            } catch (SQLException e) {   
                // TODO Auto-generated catch block   
                e.printStackTrace();   
            }   
            return domainmap;   
        }   
        public Domain getdomain(String name){   
            Domain domain=null;   
            //System.out.println("name :::"+name);   
            Collection<Domain>col=domainmap.values();   
            for(Domain b :col){   
                if(b.getDomainName().equalsIgnoreCase(name)){   
                    domain=b;   
                }   
            }   
            return domain;   
        }   
           
        public void getDBAcccess(){   
            try {   
                Class.forName("com.mysql.jdbc.Driver");   
                connection = DriverManager.getConnection (dbUrl);   
                statement = connection.createStatement();   
            } catch (ClassNotFoundException e) {   
                // TODO Auto-generated catch block   
                e.printStackTrace();   
            } catch (SQLException e) {   
                // TODO Auto-generated catch block   
                e.printStackTrace();   
            }   
               
        }   
           
           
           
    }
    test1.jsp
    Code:
    <%@page import="java.sql.*"%>    
    <%@taglib prefix="c" uri="/WEB-INF/c-rt.tld" %>   
      
    <%@page import="java.util.HashMap"%>   
    <%@page import="com.web.abc.integration.model.Domain"%>   
    <%@page import="com.web.abc.integration.model.Category"%>   
    <%@page import="com.web.abc.integration.dao.DomainDAO"%><head>      
        
     </head>    
     <body>   
     <%! HashMap<Integer,Domain>domainmap;   
    HashMap<Integer,Category>categorymap;   
    DomainDAO bdao;   
    Domain d;%>   
      
      
    <%   
     bdao=new DomainDAO();   
    bdao.getDBAcccess();   
    domainmap=bdao.getDomains(2);   
    session.setAttribute("domainmap",domainmap);   
      
    %>   
      <div id="top1"  style="width:500px;">   
      <form action="test2.jsp">   
    <table border="1"> <th>Table Containts</th>    
    <c:forEach var="domain" items="${domainmap}">   
    <tr><td>   
    <input type=checkbox name=selecteddomains value="${domain.value.domainName}">   
    <c:out value="${domain.value.domainName}" ></c:out>   
    </td></tr>   
    </c:forEach>   
     </table>    
     <input type="submit" value=">>">    
     </form>   
    </div>   
      
              <div id="top2">   
       <center>   
      
    <table border=1 ><th>Total Selected Domains</th>   
      
    <c:forEach var="domain" items="${domainlist}">   
      
    <tr><td>   
      
    <input id="<c:out value="${domain.domainName}"/>" type=checkbox value="${domain.domainName}">   
    <c:out value="${domain.domainName}"></c:out>   
    </td></tr>   
    </c:forEach>   
      
    </table>   
    </center>   
    </div>   
    </body>
    test2.jsp
    Code:
    <%@page import="java.sql.*"%>    
    <%@taglib prefix="c" uri="/WEB-INF/c-rt.tld" %>   
      
    <%@page import="java.util.HashMap"%>   
    <%@page import="com.web.abc.integration.model.Domain"%>   
    <%@page import="com.web.abc.integration.model.Category"%>   
    <%@page import="com.web.abc.integration.dao.DomainDAO"%>   
    <%@page import="java.util.ArrayList"%><head>      
        
     </head>    
     <body>   
     <%! HashMap<Integer,Domain>domainmap;   
    HashMap<Integer,Category>categorymap;   
    DomainDAO bdao;   
    Domain d;   
      
    ArrayList<Domain>domainlist;   
    %>   
      
      
    <%   
     bdao=new DomainDAO();   
    bdao.getDBAcccess();   
    domainmap=bdao.getDomains(2);   
    session.setAttribute("domainmap",domainmap);   
      
    String domainnames[]=request.getParameterValues("selecteddomains");   
      
    domainmap=(HashMap<Integer,Domain>)session.getAttribute("domainmap");   
    domainlist=(ArrayList<Domain>)session.getAttribute("domainlist");   
      
    if(domainlist==null){   
        domainlist=new ArrayList<Domain>();   
    }   
      
    DomainDAO dDao=new DomainDAO();   
    dDao.setDomainmap(domainmap);   
    for(String domainname:domainnames){   
        domainlist.add(dDao.getdomain(domainname));   
    //domainlist.remove(dDao.getdomain(domainname));   
      
    }   
    session.setAttribute("domainlist",domainlist);   
      
    %>   
      <div id="top1" >   
      <form action="test2.jsp">   
    <table border="1"> <th>Table Containts</th>    
    <c:forEach var="domain" items="${domainmap}">   
    <tr><td>   
    <input type=checkbox name=selecteddomains value="${domain.value.domainName}">   
    <c:out value="${domain.value.domainName}" ></c:out>   
    </td></tr>   
    </c:forEach>   
     </table>    
     <input type="submit" value=">>">    
     </form>   
    </div>   
      
              <div id="top2">   
       <center>   
      
    <table border=1 ><th>Total Selected Domains</th>   
      
    <c:forEach var="domain" items="${domainlist}">   
      
    <tr><td>   
      
      
    <c:out value="${domain.domainName}"></c:out>   
    </td></tr>   
    </c:forEach>   
      
    </table>   
    </center>   
    </div>   
    </body>
    My actual proble is as follows:
    Above code is working, but i want some modifications in it. And i am not getting it.

    when i click on some checkbox of table"Table Containts" and submit ">>" button, then in "Total Selected Domains" table , it is displaying checked checkboxes. But at same time , whatever the displaying in "Total selected Domains", only that checkboxes should be checked in "Table Containts" simultaneously., So basically i want to avoid duplicate selection of same checkboxes.
    waiting for your reply.
    Thank you for yor help in advance

  4. #4
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    I'm sorry, I didnt look where this thread was posted - I thought you were using html/javascript. I can't help you with java, sorry again.
    Jeremy | jfein.net

Bookmarks

Posting Permissions

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