This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Validate at least one checkbox in a Modal Window. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Validate at least one checkbox in a Modal Window." Watch "Validate at least one checkbox in a Modal Window." New topic
Author

Validate at least one checkbox in a Modal Window.

c york
Greenhorn

Joined: Mar 16, 2006
Posts: 28
I have created a Modal Window with several checkboxes. How do I validate at least one was checked?


public class ServicesModalPage extends AuthModalPage {
private AjaxButton commitBtn;
private AjaxButton cancelBtn;
final EntityTO selectedEntity = new EntityTO();

//boolean editFormHasData=false;

//public void setEditFormHasData(boolean editFormHasData) {
// this.editFormHasData = editFormHasData;

//}

ServicesModalPage(final ModalWindow parentModalWindow, final EntityTO selectedEntity) throws VechsDatabaseException {
Form<EntityTO> form = new Form<EntityTO>("mainForm", new CompoundPropertyModel<EntityTO>(selectedEntity));
//ServicesModalPage(mainForm);

add(form);
//Form<EmptyFormTO> form = new Form<EmptyFormTO>("mainForm");
//add(form);


form.add(new CheckBox("cCr"));
form.add(new CheckBox("eCr"));
form.add(new CheckBox("dCr"));
form.add(new CheckBox("cEd"));
form.add(new CheckBox("eEd"));
form.add(new CheckBox("dEd"));
form.add(new CheckBox("cSup"));
form.add(new CheckBox("eSup"));
form.add(new CheckBox("dSup"));
form.add(new CheckBox("cPla"));
form.add(new CheckBox("ePla"));
form.add(new CheckBox("dPla"));
form.add(new CheckBox("cRec"));
form.add(new CheckBox("eRec"));
form.add(new CheckBox("dRec"));
// setEditFormHasData(false);

commitBtn = new AjaxButton("commit") {
private static final long serialVersionUID = 1L;

@Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
parentModalWindow.close(target);
}

@Override
public boolean isVisible() {
return true;
}
};
form.add(commitBtn);


cancelBtn = new AjaxButton("cancel") {
private static final long serialVersionUID = 1L;

@Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
parentModalWindow.close(target);
}
};
cancelBtn.setDefaultFormProcessing(false);
form.add(cancelBtn);
}
}

Jeff Friesen
author
Ranch Hand

Joined: Sep 19, 2010
Posts: 41
Hi C,

You might want to create an array of Checkbox labels and, for each label, add a new Checkbox object with the label to the form:
Assuming that your Form class has a method such as getComponents(), you might do something like this to determine if at least one Checkbox object is selected:
I hope this helps.

Jeff


http://javajeff.mb.ca
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

And you may want to UseCodeTags; see how much easier Jeff's post is to read.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validate at least one checkbox in a Modal Window.
 
Similar Threads
About Wicket's DatePicker
how to update OneToMany
Session in HTTPServlet
Getting 404 when i forward request using request dispetcher