Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checkboxes from a query , How to ?????

 
majid nakit
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to do this :
when a user login he will be presented with a form that has his skills (he already submited in this form), now he can change his skilles by checking or unchecking the checkboxes and when submit all are saved in a table in a database.

table : user_table (userID, username).
table : const_skills (skilID , value).
table : lookup_skills (lkupID, userID, skilID).

My problem here is how to populate checked and unchecked checkboxes from database.

Problem 1 ::
Let say a user login for the first time (now we have his userID in a session), then he has a form that lists :

Please check your skills :
checkbox1 JSP
checkbox2 JAVA
checkbox3 HTML

the when he submit the form, only the skills with checkboxes he checked are inserted in the lookup_skills table.
My question here is how to construct the checkboxes in the form using the query : select * from const_skills ? in an other word :
<input type="checkbox" value= the first skilID from the query,
how to test the checked if it's false or true, />
<input type="checkbox" value= the 2nd skilID from the query,
how to test the checked if it's false or true, />
....



Problem 2 ::
Next time the user will login he will see in the form all the skills and his skills are checkec.

Please help me.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ September 22, 2005: Message edited by: Ben Souther ]
 
majid nakit
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben, thank you,
Could you please show me how to do it from ResultSet that we get from the join query until the construction of the checkboxex.
thank you, your help is appreciated.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't put database code directly into a servlet.
I would perform the DB operation in a plain old Java object (POJO) and return the data to the servlet as a list of beans or a 2D array.

I also wouldn't build HTML strings directly in a servlet. I would do that from a JSP.

That being said:
Assign the value to a boolean variable by testing the data returned in your result set.

 
majid nakit
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take a look to the tables, I don't have a column has_java .
thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you looking for help with checkboxes or do you not know how to query a database to get the needed values?
 
majid nakit
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I know how to query the database, to get the result I have only to join this two tables :
table : const_skills (skilID , value).
table : lookup_skills (lkupID, userID, skilID).

using userID = userid from the session after login, so what to do after getting all the pairs (skillID, value) from the resultSet to show all the element in the table const_skills and all matching values are checkec.
thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know how to query the database to the the table of data,
and you know how to build the checkbox by comparing the skill.value from each row, what are you stuck on.

I assume the skill.id is a texual description of the skill since there are only two columns.



If that's not what you mean, you'll need to describe what is that you're stuck on in a little more detail.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic