• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Setting checkbox from database.

 
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Folks,
Im trying to fetch data from database and set the value inn my fields which includes a checkbox.
Im able to successfully retreive values from the database and also able to populate my text boxes.
But cant seem to check a checkbox if its been set .


Any help on how I could set the checkbox value ?
 
Ranch Hand
Posts: 62
Hibernate Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For String comparisons use the equals method
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Joy!
Yup!
Missed that !my bad!.
but checkbox is still not being checked at the front end. What value should I be setting it to so that at the front end I can see it as checked when active is "1" ?
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

if(rs.getString("isactive")=="1".trim()){//checkbox value in database is set to 1 if checked.
domain.setstatusActive("checked");

}



If you are using isActive column as boolean then use appropriate datatype(use Boolean for Oracle and Bit for Sqlserver) rather than String which consumes more memory and might lead to invalid boolean check. Modify your IF condition to getBoolean("columnName") which checks the returned value as either true or false.

In regards to your query on "not being checked at the front end", please run it in debug mode and check the IF condition?, if it satisfies then check if any ther control overriddes your checkbox condition?

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the tip ! Arun . Solved the issue , added a c:if to my jsp to set checked = true when '1'.
 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Vic for sharing your results
 
reply
    Bookmark Topic Watch Topic
  • New Topic