setRequired(value) on the fly

I have a form with two dependent field.
If one field changes, it can change the required state of the other.
I try to change state setRequired(value) in the ValueChangeListener, the red asterisk does not appear / disappear above the field. If I change the style, it changes the view, but setRequired does not. Why?

What kind of field components do you use? And can you share your code?

Hi Anastasia,

It seems my problem related to CustomLayout I use in my form.
If I use VerticalLayout etc. the required mark visible.
With CustomLayout only when I refresh the whole page, changes the view state.
When I set a style to my field, the style is added immediately to the view.

Here is my test code:

final ComboBox cb1 = new ComboBox("C1", Arrays.asList("A","AA"));
final ComboBox cb2 =  new ComboBox("C2", Arrays.asList("B","BB"));
CustomLayout layout = new CustomLayout();
layout.setTemplateContents("<div location=\"cb1\"></div><div location=\"cb2\"></div>");
layout.addComponent(cb1, "cb1");
layout.addComponent(cb2, "cb2");
final Window w = new Window("Required state change test", layout);
cb1.addValueChangeListener(new Property.ValueChangeListener() {

    public void valueChange(Property.ValueChangeEvent event) {

This seems to be reason:
Hard to validate fields in a CustomLayout, if the caption doesn’t updating.
Can anybody suggest a workaround to update caption in a CustomLayout?