github-advanced-security[bot] commented on code in PR #1580: URL: https://github.com/apache/syncope/pull/1580#discussion_r4328233935
########## client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/markup/html/form/AjaxTripleStateButtonPanel.java: ########## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.ui.commons.markup.html.form; + +import java.io.Serializable; +import java.util.List; +import java.util.Optional; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.syncope.client.ui.commons.ajax.form.IndicatorAjaxFormChoiceComponentUpdatingBehavior; +import org.apache.syncope.common.lib.Attr; +import org.apache.syncope.common.lib.to.AttributableTO; +import org.apache.wicket.AttributeModifier; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.form.Radio; +import org.apache.wicket.markup.html.form.RadioGroup; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.ResourceModel; + +public class AjaxTripleStateButtonPanel extends FieldPanel<Boolean> { Review Comment: ## CodeQL / No clone method No clone method, yet implements Cloneable. [Show more details](https://github.com/apache/syncope/security/code-scanning/2681) ########## client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/markup/html/form/AjaxTripleStateButtonPanel.java: ########## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.ui.commons.markup.html.form; + +import java.io.Serializable; +import java.util.List; +import java.util.Optional; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.syncope.client.ui.commons.ajax.form.IndicatorAjaxFormChoiceComponentUpdatingBehavior; +import org.apache.syncope.common.lib.Attr; +import org.apache.syncope.common.lib.to.AttributableTO; +import org.apache.wicket.AttributeModifier; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.form.Radio; +import org.apache.wicket.markup.html.form.RadioGroup; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.ResourceModel; + +public class AjaxTripleStateButtonPanel extends FieldPanel<Boolean> { + + private static final long serialVersionUID = 5433965057104106773L; + + protected final WebMarkupContainer unsetContainer; + + protected final Radio<Boolean> unsetOption; + + private final boolean convertValuesToString; + + public AjaxTripleStateButtonPanel(final String id, final String name, final IModel<Boolean> model) { + this(id, name, model, true); + } + + public AjaxTripleStateButtonPanel( + final String id, + final String name, + final IModel<Boolean> model, + final boolean enableOnChange) { + + this(id, name, model, enableOnChange, true); + } + + private AjaxTripleStateButtonPanel( + final String id, + final String name, + final IModel<Boolean> model, + final boolean enableOnChange, + final boolean convertValuesToString) { + + super(id, name, model); + + this.convertValuesToString = convertValuesToString; + + field = new RadioGroup<>("tripleStateField", model); + add(field.setLabel(new ResourceModel(name, name)).setOutputMarkupId(true)); + field.add(AttributeModifier.replace("aria-label", field.getLabel())); + field.add(AttributeModifier.replace("aria-required", (IModel<String>) () -> Boolean.toString(isRequired()))); + + Radio<Boolean> trueOption = new Radio<>("trueOption", Model.of(Boolean.TRUE)); + Radio<Boolean> falseOption = new Radio<>("falseOption", Model.of(Boolean.FALSE)); + field.add(trueOption.setOutputMarkupId(true), falseOption.setOutputMarkupId(true)); + + WebMarkupContainer trueLabel = new WebMarkupContainer("trueLabel"); + trueLabel.add(AttributeModifier.replace("for", (IModel<String>) trueOption::getMarkupId)); + trueLabel.add(AttributeModifier.replace("title", new ResourceModel("tristate.true"))); + field.add(trueLabel); + + WebMarkupContainer falseLabel = new WebMarkupContainer("falseLabel"); + falseLabel.add(AttributeModifier.replace("for", (IModel<String>) falseOption::getMarkupId)); + falseLabel.add(AttributeModifier.replace("title", new ResourceModel("tristate.false"))); + field.add(falseLabel); + + unsetContainer = new WebMarkupContainer("unsetContainer"); + field.add(unsetContainer); + + unsetOption = new Radio<>("unsetOption", Model.of((Boolean) null)); + unsetContainer.add(unsetOption.setOutputMarkupId(true)); + + WebMarkupContainer unsetLabel = new WebMarkupContainer("unsetLabel"); + unsetLabel.add(AttributeModifier.replace("for", (IModel<String>) unsetOption::getMarkupId)); + unsetLabel.add(AttributeModifier.replace("title", new ResourceModel("tristate.unset"))); + unsetContainer.add(unsetLabel); + + if (enableOnChange && !isReadOnly()) { + field.add(new IndicatorAjaxFormChoiceComponentUpdatingBehavior() { + + private static final long serialVersionUID = -8888833255711609077L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + doUpdate(target); + } + }); + } + } + + protected void doUpdate(final AjaxRequestTarget target) { Review Comment: ## CodeQL / Useless parameter The parameter 'target' is never used. [Show more details](https://github.com/apache/syncope/security/code-scanning/2682) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
