setLocale(getLocaleFromString(attr.get("locale")));
/** * Sets the locale of this component. * * <pre> * // Component for which the locale is meaningful * InlineDateField date = new InlineDateField("Datum"); * * // German language specified with ISO 639-1 language * // code and ISO 3166-1 alpha-2 country code. * date.setLocale(new Locale("de", "DE")); * * date.setResolution(DateField.RESOLUTION_DAY); * layout.addComponent(date); * </pre> * * @param locale * the locale to become this component's locale. * @return this (for method chaining) * @see AbstractComponent#setLocale(java.util.Locale) */ public default S withLocale(Locale locale) { ((AbstractComponent) this).setLocale(locale); return (S) this; }
private void recursiveSetLocale() { Stack<Component> stack = new Stack<>(); stack.addAll(VaadinSession.getCurrent().getUIs()); while (!stack.isEmpty()) { Component component = stack.pop(); if (component instanceof HasComponents) { for (Iterator<Component> i = ((HasComponents) component) .iterator(); i.hasNext();) { stack.add(i.next()); } } if (component instanceof AbstractComponent) { AbstractComponent abstractComponent = (AbstractComponent) component; abstractComponent.setLocale(UI.getCurrent().getLocale()); } } }
/** * Applies annotation values to {@code component} * * @param component the component to be updated * @param annotationValues the annotation values to apply * @param annotationInfo used primarily to identify the Field, and therefore its name */ private void applyAnnotationValues(AbstractComponent component, AnnotationValues annotationValues, AnnotationInfo annotationInfo) { // set locale first Locale locale = annotationValues.locale.isPresent() ? annotationValues.locale.get() : currentLocale.getLocale(); component.setLocale(locale); // set caption, description & value if available if (annotationValues.captionKey.isPresent()) { component.setCaption(translate.from(annotationValues.captionKey.get(), locale)); } if (annotationValues.descriptionKey.isPresent()) { component.setDescription(translate.from(annotationValues.descriptionKey.get(), locale)); } if (annotationValues.valueKey.isPresent()) { if (component instanceof HasValue) { ((HasValue) component).setValue(translate.from(annotationValues.valueKey.get(), locale)); return; } else { log.warn("Field {} has a value annotation but does not implement HasValue. Annotation ignored", annotationInfo.getField() .getName()); } } }
component.setLocale(locale);
@Override public F createField() { // Create the Vaadin field F field = createFieldComponent(); if (AbstractComponent.class.isAssignableFrom(field.getClass())) { AbstractComponent abstractComponent = (AbstractComponent) field; abstractComponent.setLocale(locale); if (StringUtils.isNotBlank(getDefinition().getStyleName())) { field.addStyleName(getDefinition().getStyleName()); } field.setWidth(100, Sizeable.Unit.PERCENTAGE); setFieldCaption(field); } field.setRequiredIndicatorVisible(getDefinition().isRequired()); field.setReadOnly(getDefinition().isReadOnly()); return field; }