public static HtmlSelectBooleanCheckbox addUnsetControl(UIComponent parent, boolean isRequired, boolean isReadOnly, PropertySimple propertySimple, Integer listIndex, UIInput valueInput, boolean isGroupConfig, boolean configReadOnly, boolean configFullyEditable) { HtmlSelectBooleanCheckbox unsetCheckbox = FacesComponentUtility.createComponent( HtmlSelectBooleanCheckbox.class, null); if (propertySimple != null) { String unsetCheckboxId = PropertyIdGeneratorUtility.getIdentifier(propertySimple, listIndex, "Unset"); unsetCheckbox.setId(unsetCheckboxId); } parent.getChildren().add(unsetCheckbox); unsetCheckbox.setValue(isUnset(isRequired, propertySimple, isGroupConfig)); if (isReadOnly(isReadOnly, isRequired, propertySimple, configReadOnly, configFullyEditable) || isGroupConfigWithDifferingValues(propertySimple, isGroupConfig)) { FacesComponentUtility.setDisabled(unsetCheckbox, true); } else { // Add JavaScript that will disable/enable the corresponding input element when the unset checkbox is // checked/unchecked. // IMPORTANT: We must use document.formName.inputName, rather than document.getElementById('inputId'), // to reference the HTML DOM element, because the id of the HTML DOM input element is not the same as the // id of the corresponding JSF input component in some cases (e.g. radio buttons). However, the // name property that JSF renders on the HTML DOM input element does always match the JSF // component id. (ips, 05/31/07) StringBuilder onclick = new StringBuilder(); for (String htmlDomReference : getHtmlDomReferences(valueInput)) { onclick.append("setInputUnset(").append(htmlDomReference).append(", this.checked);"); } unsetCheckbox.setOnclick(onclick.toString()); } return unsetCheckbox; }
@Override public void processEvent(ComponentSystemEvent postAddToViewEvent) throws AbortProcessingException { FacesContext facesContext = FacesContext.getCurrentInstance(); Example example = (Example) postAddToViewEvent.getComponent(); List<UIComponent> exampleChildren = example.getChildren(); Boolean renderedCheckbox = example.isRenderedCheckbox(); if ((renderedCheckbox != null) && renderedCheckbox && !facesContext.isProjectStage(ProjectStage.Production)) { Application application = facesContext.getApplication(); HtmlSelectBooleanCheckbox htmlSelectBooleanCheckbox = createHtmlBooleanCheckbox(application, facesContext, "#{showcaseModelBean.selectedComponent.rendered}"); AjaxBehavior ajaxBehavior = (AjaxBehavior) application.createBehavior(AjaxBehavior.BEHAVIOR_ID); List<String> renderIds = Arrays.asList(new String[] { "@form" }); ajaxBehavior.setRender(renderIds); htmlSelectBooleanCheckbox.addClientBehavior("valueChange", ajaxBehavior); htmlSelectBooleanCheckbox.setId("renderedCheckbox"); exampleChildren.add(htmlSelectBooleanCheckbox); addFacesAjaxResourceDependency(facesContext); } Boolean requiredCheckbox = example.isRequiredCheckbox(); if ((requiredCheckbox != null) && requiredCheckbox) { Application application = facesContext.getApplication(); HtmlSelectBooleanCheckbox htmlSelectBooleanCheckbox = createHtmlBooleanCheckbox(application, facesContext, "#{showcaseModelBean.selectedComponent.required}"); AjaxBehavior ajaxBehavior = (AjaxBehavior) application.createBehavior(AjaxBehavior.BEHAVIOR_ID); htmlSelectBooleanCheckbox.addClientBehavior("valueChange", ajaxBehavior); htmlSelectBooleanCheckbox.setId("requiredCheckbox"); exampleChildren.add(htmlSelectBooleanCheckbox); addFacesAjaxResourceDependency(facesContext); } }
@NotNull private HtmlSelectBooleanCheckbox createInputOverrideForSimpleProperty( PropertyDefinitionSimple propertyDefinitionSimple) { HtmlSelectBooleanCheckbox input = FacesComponentUtility.createComponent(HtmlSelectBooleanCheckbox.class, this.config); // Find the actual property corresponding to this property def, and use that to create the component id. Property property = this.propertyMap.get(propertyDefinitionSimple.getName()); if (property != null) { // add suffix to prevent collision with value input identifier for property String propertyId = PropertyIdGeneratorUtility.getIdentifier(property, getListIndex(), "override"); input.setId(propertyId); Boolean shouldOverride = ((PropertySimple) property).getOverride(); FacesComponentUtility.setOverride(input, (shouldOverride != null && shouldOverride)); } setInputOverrideExpression(input, propertyDefinitionSimple.getName()); return input; }