private void checkCheckBox(MainDocumentPart pMainDocumentPart, int pIndex)
throws JAXBException, XPathBinderAssociationIsPartialException {
final CTFFCheckBox checkBox = findCheckBoxWithIndex(pMainDocumentPart, pIndex);
if (checkBox.getChecked() == null) {
checkBox.setChecked(new BooleanDefaultTrue());
}
final BooleanDefaultTrue checked = checkBox.getChecked();
checked.setVal(true);
}
private CTFFCheckBox findCheckBoxWithIndex(MainDocumentPart pMainDocumentPart, int pIndex)
throws XPathBinderAssociationIsPartialException, JAXBException {
final List<Object> checkBoxElements = pMainDocumentPart.getJAXBNodesViaXPath("//w:checkBox", false);
for (int i = 0; i < checkBoxElements.size(); i++) {
if (i == pIndex) {
@SuppressWarnings("unchecked")
final JAXBElement<CTFFCheckBox> checkBoxElement = (JAXBElement<CTFFCheckBox>) checkBoxElements.get(i);
return checkBoxElement.getValue();
}
}
throw new IllegalArgumentException(String.format("There is no check box with index %d.", pIndex));
}
Discussed w/ msc
Snippet (for the impl idea)