You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by wch2001 <wc...@hotmail.com> on 2008/09/03 04:30:23 UTC
help: How to set checkbox with single check?
Dear all,
I have one ListView , inside need to add checkbox for users to select, only
can select one, how can i do? thanks a lot.
the following is the codes:
Java:
ListView fileListView = new ListView("fileList", files) {
@Override
protected void populateItem(final ListItem item) {
final FileObj fileObj = (FileObj) item.getModelObject();
if (fileObj.isMain()) {
setPhotoMainStatus(true);
photoMainStatus = true;
}
CheckBox chkPhotoMain = new CheckBox("chkPhotoMain", new
PropertyModel(getParent(), "photoMainStatus"));
chkPhotoMain.add(new
AjaxFormComponentUpdatingBehavior("onClick")
{
@Override
protected void onUpdate(AjaxRequestTarget target)
{
System.out.println("----------------in the
checkbox, fileObj.getId()" + fileObj.getId());
}
});
item.add(chkPhotoMain);
item.add(new AttributeModifier("class", true, new
AbstractReadOnlyModel() {
@Override
public Object getObject() {
return ((item.getIndex() % 2) == 1) ? "even" :
"odd";
}
}));
}
};
htmL;
<td width="100"><input type="checkbox" wicket:id="chkPhotoMain"/>main</td>
--
View this message in context: http://www.nabble.com/help%3A-How-to-set-checkbox-with-single-check--tp19281898p19281898.html
Sent from the Wicket - Dev mailing list archive at Nabble.com.
Re: help: How to set checkbox with single check?
Posted by Timo Rantalaiho <Ti...@ri.fi>.
Please post messages like this on the users list in the future.
On Tue, 02 Sep 2008, wch2001 wrote:
> I have one ListView , inside need to add checkbox for users to select, only
> can select one, how can i do? thanks a lot.
Shouldn't it be a RadioButton instead of CheckBox, then?
I would try something like
chkPhotoMain.add(newAjaxFormComponentUpdatingBehavior("onClick") {
@Override
protected void onUpdate(final AjaxRequestTarget target) {
ListView fileList = (ListView) findParent(ListView.class);
fileList.visitChildren(CheckBox.class, new IVisitor() {
public Object component(Component checkbox) {
doDisableOrSetModelObjectFalseOrWhatEverYouWantWith(checkbox);
target.addComponent(component);
}
});
}
});
> item.add(new AttributeModifier("class", true, new
> AbstractReadOnlyModel() {
>
> @Override
> public Object getObject() {
> return ((item.getIndex() % 2) == 1) ? "even" :
> "odd";
> }
I think that OddEvenRowItem or something like that provides
this part out of the box.
Best wishes,
Timo
--
Timo Rantalaiho
Reaktor Innovations Oy <URL: http://www.ri.fi/ >