Hi guys,
I'm trying to set a default value of a previous disabled input and it is not working, let me show some code:
hidden = componentFactory.createInput("Hidden", Boolean.class)
.setEnabled(false);
length = componentFactory.createInput("Length", Integer.class)
.setEnabled(false);
required = componentFactory.createInput("Required", Boolean.class)
.setEnabled(false);
type = componentFactory.createSelectOne("Type", ComponentTypeEnum.class)
.setValueChoices(Arrays.stream(ComponentTypeEnum.values()).collect(Collectors.toList()))
.setEnabled(false);
those fields are enabled on a valueChangeLIstener:
fieldConfigList.addValueChangeListener((ValueChangeEvent event) -> {
fieldConfig = (FieldConfig) event.getNewValue();
if (fieldConfig != null) {
hidden.setEnabled(true)
.setDescription(String.format("When true the field '%s' will be ignored on AdminFaces scaffold.", fieldConfig.getName()))
.setValue(fieldConfig.getHidden());
hidden.addValueChangeListener((ValueChangeEvent evt) -> {
fieldConfig.setHidden((Boolean) evt.getNewValue());
});
required.setEnabled(true)
.setDescription(String.format("When true the field '%s' will be required on AdminFaces scaffold generated pages.", fieldConfig.getName()))
.setValue(fieldConfig.getRequired());
required.addValueChangeListener((ValueChangeEvent evt) -> {
fieldConfig.setRequired((Boolean) evt.getNewValue());
});
length.setEnabled(true)
.setDescription(String.format("Set field '%s' length to be used on AdminFaces scaffold generated pages.", fieldConfig.getName()))
.setValue(fieldConfig.getLength());
length.addValueChangeListener((ValueChangeEvent evt) -> {
fieldConfig.setLength((Integer) evt.getNewValue());
});
type.setEnabled(true)
.setDescription(String.format("Set field '%s' component type to be used on AdminFaces scaffold generated pages.", fieldConfig.getName()))
.setValue(fieldConfig.getType());
type.addValueChangeListener((ValueChangeEvent evt) -> {
fieldConfig.setType((ComponentTypeEnum) evt.getNewValue());
});
} else {
hidden.setEnabled(false)
.setNote("");
length.setEnabled(false)
.setNote("");
required.setEnabled(false)
.setNote("");
type.setEnabled(false)
.setNote("");
}
});
Whenever I change "fieldConfigList" I want to change "type", "length", "required" and "hidden" defaultValues. It only works for "type" field which is a selectOne or if I go back and forth on the wizard as shown on the video below:
Also it is working for the "description" attribute because it is changing accordingly with selected fieldConfig as you can see on the video.
Any hints? (I also tried to use "setValue"instead of defaultValue but also did not worked)
Thanks in advance!
--