I have this SOAP based webservice implemented in Java where the client has a list of checkboxes which after he selects will be stored in the DB.For example for a checkbox of Sex(maschio,femmina) he can select both of them or one of them i implemented it like this but the issue is that the array has fixed size in this case 2 so if the user selects only one of them sexarra[0] will contain it but sexarra[1] will be null so if i pass it to the server it can create problems and the other checkboxes are much larger in size is there any better way to handle this situation? Thank you all in advance your help is really appreciated! i should add that System.out are for testing only:
private void femminaActionPerformed(java.awt.event.ActionEvent evt) {
if (femmina.isSelected()) {
if (sexint == 0) {
sexint++;
sexarra[sexint] = femmina.getText();
} else {
sexarra[sexint] = femmina.getText();
}
}
System.out.println(sexarra[0]);
System.out.println(sexarra[1]);
}
private void maschioActionPerformed(java.awt.event.ActionEvent evt) {
if (maschio.isSelected()) {
if (sexint == 0) {
sexarra[sexint] = maschio.getText();
sexint++;
} else {
sexarra[sexint] = maschio.getText();
}
}
System.out.println(sexarra[0]);
System.out.println(sexarra[1]);
}
Ok i resolved the problem i had, i introduced an integer sexint which gets updated whenever one of the checkboxes is selected thus determining the size of the array here is the code:
private void femminaActionPerformed(java.awt.event.ActionEvent evt) {
if(femmina.isSelected()){
if(sexint==0){
sexint++;
sexone=femmina.getText();
}
else if(sexint==1){
sexint++;
sextwo=femmina.getText();
}
else
sexint--;
System.out.println(sexint);
}
}
private void maschioActionPerformed(java.awt.event.ActionEvent evt) {
if(maschio.isSelected()){
if(sexint==0){
sexint++;
sexone=maschio.getText();
}
else if(sexint==1){
sexint++;
sextwo=maschio.getText();
}
else
sexint--;
System.out.println(sexint);
}
}
after which i take sexint and use it to instantiate the array sexarra Thanks everybody for having taken their time in looking at my problem