Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHPAM-461: Two different radiogroups with the same name have the same id. #1786

Merged
merged 1 commit into from
May 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

public abstract class AbstractFormRenderingContext<T> implements FormRenderingContext<T> {

protected String namespace;

protected Map<String, FormDefinition> availableForms = new HashMap<String, FormDefinition>();

protected String rootFormId;
Expand All @@ -33,6 +35,10 @@ public abstract class AbstractFormRenderingContext<T> implements FormRenderingCo

protected RenderMode renderMode = RenderMode.EDIT_MODE;

public AbstractFormRenderingContext(String namespace) {
this.namespace = namespace;
}

@Override
public FormDefinition getRootForm() {
return availableForms.get(rootFormId);
Expand All @@ -45,6 +51,11 @@ public void setRootForm(FormDefinition rootForm) {
rootForm);
}

@Override
public String getNamespace() {
return namespace;
}

@Override
public void setModel(T model) {
this.model = model;
Expand Down Expand Up @@ -80,15 +91,14 @@ public Map<String, FormDefinition> getAvailableForms() {
return availableForms;
}

protected abstract AbstractFormRenderingContext<T> getNewInstance();
protected abstract AbstractFormRenderingContext<T> getNewInstance(String namespace);

@Override
public FormRenderingContext getCopyFor(String formKey,
T model) {
public FormRenderingContext getCopyFor(String namespace, String formKey, T model) {
if (formKey == null || formKey.isEmpty()) {
return null;
}
AbstractFormRenderingContext copy = getNewInstance();
AbstractFormRenderingContext copy = getNewInstance(namespace);
copy.setRenderMode(renderMode);
copy.setRootForm(availableForms.get(formKey));
copy.setModel(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

public interface FormRenderingContext<T> {

String NAMESPACE_SEPARATOR = ".";

String getNamespace();

FormDefinition getRootForm();

void setRootForm(FormDefinition rootForm);
Expand All @@ -40,6 +44,5 @@ public interface FormRenderingContext<T> {

Map<String, FormDefinition> getAvailableForms();

FormRenderingContext getCopyFor(String formKey,
T model);
FormRenderingContext getCopyFor(String namespace, String formKey, T model);
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public StaticModelFormRenderingContext getContextForModel(Object model, FormElem
return null;
}

StaticModelFormRenderingContext context = new StaticModelFormRenderingContext();
StaticModelFormRenderingContext context = new StaticModelFormRenderingContext(String.valueOf(System.currentTimeMillis()));

context.setModel(model);
context.setRootForm(formDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.HashMap;
import java.util.Map;

import org.jboss.errai.common.client.api.annotations.MapsTo;
import org.jboss.errai.common.client.api.annotations.Portable;
import org.kie.workbench.common.forms.dynamic.service.shared.AbstractFormRenderingContext;
import org.kie.workbench.common.forms.dynamic.service.shared.impl.validation.DynamicModelConstraints;
Expand All @@ -34,9 +35,13 @@ public class MapModelRenderingContext extends AbstractFormRenderingContext<Map<S

public Map<String, DynamicModelConstraints> modelValidations = new HashMap<>();

public MapModelRenderingContext(@MapsTo("namespace") String namespace) {
super(namespace);
}

@Override
protected MapModelRenderingContext getNewInstance() {
MapModelRenderingContext copy = new MapModelRenderingContext();
protected AbstractFormRenderingContext<Map<String, Object>> getNewInstance(String namespace) {
MapModelRenderingContext copy = new MapModelRenderingContext(namespace);
copy.setModelValidations(modelValidations);
return copy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@

package org.kie.workbench.common.forms.dynamic.service.shared.impl;

import org.jboss.errai.common.client.api.annotations.MapsTo;
import org.jboss.errai.common.client.api.annotations.Portable;
import org.kie.workbench.common.forms.dynamic.service.shared.AbstractFormRenderingContext;

@Portable
public class StaticModelFormRenderingContext extends AbstractFormRenderingContext<Object> {

public StaticModelFormRenderingContext(@MapsTo("namespace") String namespace) {
super(namespace);
}

@Override
protected AbstractFormRenderingContext getNewInstance() {
return new StaticModelFormRenderingContext();
protected StaticModelFormRenderingContext getNewInstance(String namespace) {
return new StaticModelFormRenderingContext(namespace);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class TestFormGenerator {

public static StaticModelFormRenderingContext getContextForEmployee(Employee employee) {
FormDefinition form = getEmployeeForm();
StaticModelFormRenderingContext context = new StaticModelFormRenderingContext();
StaticModelFormRenderingContext context = new StaticModelFormRenderingContext("");
context.setRootForm(form);
context.setModel(employee);
context.getAvailableForms().put(form.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@

public class TestFormRenderingContext extends AbstractFormRenderingContext {

public TestFormRenderingContext(String namespace) {
super(namespace);
}

@Override
protected AbstractFormRenderingContext getNewInstance() {
return new TestFormRenderingContext();
protected AbstractFormRenderingContext getNewInstance(String namespace) {
return new TestFormRenderingContext(namespace);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public BackendFormRenderingContext registerContext(FormDefinition rootForm,
Map<String, String> params,
FormDefinition... nestedForms) {

MapModelRenderingContext clientRenderingContext = new MapModelRenderingContext();
MapModelRenderingContext clientRenderingContext = new MapModelRenderingContext(String.valueOf(System.currentTimeMillis()));

clientRenderingContext.setRootForm(rootForm);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
public abstract class FieldRenderer<F extends FieldDefinition, FORM_GROUP extends FormGroup> {

protected FormRenderingContext renderingContext;
protected String fieldNS;
protected F field;
protected FormFieldImpl formField = null;
protected List<FieldChangeListener> fieldChangeListeners = new ArrayList<>();
Expand All @@ -48,10 +49,10 @@ public abstract class FieldRenderer<F extends FieldDefinition, FORM_GROUP extend
@Inject
private ConfigErrorDisplayer errorDisplayer;

public void init(FormRenderingContext renderingContext,
F field) {
public void init(FormRenderingContext renderingContext, F field) {
this.renderingContext = renderingContext;
this.field = field;
this.fieldNS = renderingContext.getNamespace() + FormRenderingContext.NAMESPACE_SEPARATOR + field.getName();
fieldChangeListeners.clear();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public String getName() {
@Override
protected FormGroup getFormGroup(RenderMode renderMode) {
checkbox = new SimpleCheckBox();
checkbox.setName(fieldNS);
checkbox.setEnabled(!field.getReadOnly() && renderingContext.getRenderMode().equals(RenderMode.EDIT_MODE));

CheckBoxFormGroup formGroup = formGroupsInstance.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ protected FormGroup getFormGroup(RenderMode renderMode) {

textArea = new TextArea();
textArea.setId(inputId);
textArea.setName(fieldNS);
textArea.setPlaceholder(field.getPlaceHolder());
textArea.setVisibleLines(field.getRows());
textArea.setEnabled(!field.getReadOnly());
textArea.setVisibleLines(field.getRows());
formGroup.render(inputId,
textArea,
field);

formGroup.render(inputId, textArea, field);
}

return formGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ protected FormGroup getFormGroup(RenderMode renderMode) {
} else {
String inputId = generateUniqueId();
textBox = new TextBox();
textBox.setName(fieldNS);
textBox.setId(inputId);
textBox.setPlaceholder(field.getPlaceHolder());
textBox.setMaxLength(field.getMaxLength());
textBox.setEnabled(!field.getReadOnly());
formGroup.render(inputId,
textBox,
field);

formGroup.render(inputId, textBox, field);
}

return formGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private Widget getDateWidget(String inputId) {
if (field.getShowTime()) {
DateTimePicker box = new DateTimePicker();
box.setId(inputId);
box.setName(fieldNS);
box.setPlaceholder(field.getPlaceHolder());
box.setEnabled(!field.getReadOnly());
box.setAutoClose(true);
Expand All @@ -75,6 +76,7 @@ private Widget getDateWidget(String inputId) {

DatePicker box = new DatePicker();
box.setId(inputId);
box.setName(fieldNS);
box.setPlaceholder(field.getPlaceHolder());
box.setEnabled(!field.getReadOnly());
box.setAutoClose(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
public class MultipleSubFormWidget extends Composite implements TakesValue<List<Object>>,
IsNestedModel {

public static final String CREATION_NAMESPACE = "#create";
public static final String EDITION_NAMESPACE = "#edit";

public static final int PAGE_SIZE = 5;

@Inject
Expand Down Expand Up @@ -189,8 +192,10 @@ public IsFormView<Object> getCreateInstanceForm() {

BindableProxy<?> proxy = bindingHelper.getNewProxy();

formRenderer.render(renderingContext.getCopyFor(field.getCreationForm(),
proxy));
String namespace = renderingContext.getNamespace() + FormRenderingContext.NAMESPACE_SEPARATOR + CREATION_NAMESPACE;

formRenderer.render(renderingContext.getCopyFor(namespace, field.getCreationForm(), proxy));

return formRenderer;
}

Expand All @@ -203,8 +208,9 @@ public IsFormView<Object> getEditInstanceForm(int position) {

BindableProxy editionProxy = bindingHelper.getProxyForModel(instanceProxy.deepUnwrap());

formRenderer.render(renderingContext.getCopyFor(field.getEditionForm(),
editionProxy));
String namespace = renderingContext.getNamespace() + FormRenderingContext.NAMESPACE_SEPARATOR + EDITION_NAMESPACE;

formRenderer.render(renderingContext.getCopyFor(namespace, field.getEditionForm(), editionProxy));
return formRenderer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ public class SubFormFieldRenderer extends FieldRenderer<SubFormFieldDefinition,
@Override
protected FormGroup getFormGroup(RenderMode renderMode) {

FormRenderingContext nestedContext = renderingContext.getCopyFor(field.getNestedForm(),
null);
String nestedNS = renderingContext.getNamespace() + FormRenderingContext.NAMESPACE_SEPARATOR + field.getName();

FormRenderingContext nestedContext = renderingContext.getCopyFor(nestedNS, field.getNestedForm(), null);

if (field.getReadOnly()) {
nestedContext.setRenderMode(RenderMode.READ_ONLY_MODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ protected FormGroup getFormGroup(RenderMode renderMode) {
} else {
String inputId = generateUniqueId();
widgetList.setId(inputId);
widgetList.setName(fieldNS);
widgetList.setEnabled(!field.getReadOnly());
refreshSelectorOptions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Class<CharacterRadioGroupFieldDefinition> getSupportedFieldDefinition() {

@Override
protected RadioGroupBase<Character> getRadioGroup() {
return new CharacterRadioGroup(field.getName());
return new CharacterRadioGroup(fieldNS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public Class<DecimalRadioGroupFieldDefinition> getSupportedFieldDefinition() {

@Override
protected RadioGroupBase<Double> getRadioGroup() {
return new DecimalRadioGroup(field.getName());
return new DecimalRadioGroup(fieldNS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public Class<IntegerRadioGroupFieldDefinition> getSupportedFieldDefinition() {

@Override
protected RadioGroupBase<Long> getRadioGroup() {
return new IntegerRadioGroup(field.getName());
return new IntegerRadioGroup(fieldNS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public Class<StringRadioGroupFieldDefinition> getSupportedFieldDefinition() {

@Override
protected RadioGroupBase<String> getRadioGroup() {
return new StringRadioGroup(field.getName());
return new StringRadioGroup(fieldNS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected void lookupPropertyGenerators() {

helper.initialize();

context = new MapModelRenderingContext();
context = new MapModelRenderingContext("");

context.setRootForm(employeeForm);
context.getAvailableForms().put(addressForm.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class FormEditorRenderingContext extends AbstractFormRenderingContext<Fie

private Path formPath;

public FormEditorRenderingContext(@MapsTo("formPath") Path formPath) {
super();
public FormEditorRenderingContext(@MapsTo("namespace") String namespace, @MapsTo("formPath") Path formPath) {
super(namespace);
this.formPath = formPath;
}

Expand All @@ -41,7 +41,7 @@ public Path getFormPath() {
}

@Override
protected AbstractFormRenderingContext getNewInstance() {
return new FormEditorRenderingContext(formPath);
protected FormEditorRenderingContext getNewInstance(String namespace) {
return new FormEditorRenderingContext(namespace, formPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ protected FormModelerContent constructContent(Path path, Overview overview) {
return formModelConent;
}

protected FormEditorRenderingContext createRenderingContext(FormDefinition form,
Path formPath) {
FormEditorRenderingContext context = new FormEditorRenderingContext(formPath);
protected FormEditorRenderingContext createRenderingContext(FormDefinition form, Path formPath) {

FormEditorRenderingContext context = new FormEditorRenderingContext("edition", formPath);
context.setRootForm(form);

List<FormDefinition> allForms = vfsFormFinderService.findAllForms(formPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public PreviewFormPresenter(PreviewFormPresenterView view) {

public void preview(FormRenderingContext context) {

MapModelRenderingContext mapContext = new MapModelRenderingContext();
MapModelRenderingContext mapContext = new MapModelRenderingContext("edit");
mapContext.getAvailableForms().putAll(context.getAvailableForms());
mapContext.setRootForm(context.getRootForm());
mapContext.setModel(new HashMap<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void render(final FieldPropertiesRendererHelper helper) {
protected void render() {
FormRenderingContext context = dynamicFormModelGenerator.getContextForModel(fieldCopy);
if (context != null) {
FormEditorRenderingContext renderingContext = new FormEditorRenderingContext(helper.getPath());
FormEditorRenderingContext renderingContext = new FormEditorRenderingContext("properties", helper.getPath());
renderingContext.setRootForm(context.getRootForm());
renderingContext.getAvailableForms().putAll(context.getAvailableForms());
renderingContext.setModel(fieldCopy);
Expand Down