• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting checkbox from database.

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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 ?
 
joy b chakravarty
Ranch Hand
Posts: 62
Hibernate Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For String comparisons use the equals method
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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" ?
 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • 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 Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Vic for sharing your results
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic