Set language label programmatically

I have problems setting labels with language specifications programmatically after the component has been rendered. I have the following:



public class DateFilterWidget extends Div implements IdSpace {
private static final long serialVersionUID = 1L;

@Wire
Datebox startDate, endDate;

@Wire
Button filterButton;

@Wire
Label datefilterLabel;

String field;

public DateFilterWidget(String name, String filterField) {
Executions.createComponents("widgets/datefilter.zul", this, null);
Selectors.wireComponents(this, this, false);
Selectors.wireEventListeners(this, this);
datefilterLabel.setValue("${labels.data.dateFilterButton.label}");

this.field = filterField;
}
}


And the datefilter.zul



<hbox sclass="filterWidgetBox" align="center">
<label id="datefilterLabel" />
<datebox id="startDate" format="yyyy-MM-dd"
weekOfYear="true" width="105px"/>
<label value="-" />
<datebox id="endDate" format="yyyy-MM-dd"
weekOfYear="true" width="105px"/>
<button id="filterButtonc"
label="${labels.data.dateFilterButton.label}" />
</hbox>


I the above case the same label has been used for both the button and the label. The button language reference works fine, but the label that got a value programmatically don't work.



I know that I can use the Labels.getLabel("data.dateFilterButton.label"), but this solution removes the possibility to update language unless the whole application is rerendered with the new language.



Answers

label="${labels...}" is a static EL and will only get evaluated once the zul file is parsed, and has the same effect as calling setLabel(Labels.get(Labels.getLabel(...))).




The button language reference works fine




I don't really understand what you mean by that. When I run your example using Labels.getLabel(...) it works as expected, setting both labels in the current locale. When changing the locale during runtime e.g. from EN -> DE none of the labels update automatically, and both components need to be re-rendered and then update correctly.



To provide a solution, can you please give details on what you expect to happen? Or what you are trying to achieve regarding:




this solution removes the possibility to update language unless the whole application is re-rendered with the new language




"Update" can have several meanings, it's just not clear yet.



Robert



Answers

To set the value programmatically you should used the class Labels of the zk api.
You can see the javadoc clicking here:
Labels



And use the method getLabel.
Example:



datefilterLabel.setValue(Labels.getLabel("data.dateFilterButton.label");


If that is the right label key.