Text
The j:outputMultiText Facelet-Tag can be used as a replacement for h:outputText for multi-language text fields provided by Map<String,IoLang> . If no translation is available for the current localeCode of the user, the fallbackLocale will be used. If this happens, the fallback is marked with a flag.
- <h:outputText value="#{entity.name[localeCode].lang}"/>
- <j:outputMultiText value="#{entity.name}"/>
The tag supports three attributes:
- value points to a Map<String,IoLang>
- userLocaleCode (e.g. de/en/fr) which defaults to #{localeCode}
- fallbackLocale which defaults to #{appLabelBean.fallbackLocale}
<p:dataTable styleClass="jeesl-datatable"
var="l1" value="#{appLabelBean.locales}" rowKey="#{l1.id}">
<f:facet name="header"><j:dtHeader entity="IoLocale" code="listOf"/></f:facet>
<p:column>
<jtp:symbolizer value="#{l1}"/>
</p:column>
<p:columns var="l2" value="#{outputTextBean.locales}" styleClass="jeeslRight">
<f:facet name="header">
<h:outputText value="#{l2.code}" />
</f:facet>
<h:outputText value="#{l1.name[l2.code].lang}"/>
</p:columns>
</p:dataTable>
<p:dataTable styleClass="jeesl-datatable"
var="l1" value="#{appLabelBean.locales}" rowKey="#{l1.id}">
<f:facet name="header"><j:dtHeader entity="IoLocale" code="listOf"/></f:facet>
<p:column>
<jtp:symbolizer value="#{l1}"/>
</p:column>
<p:columns var="l2" value="#{outputTextBean.locales}" styleClass="jeeslRight">
<f:facet name="header">
<h:outputText value="#{l2.code}" />
</f:facet>
<j2:outputMultiText value="#{l1.name}" userLocaleCode="#{l2.code}"/>
</p:columns>
</p:dataTable>
@Named @ViewScoped
public class OutputTextBean extends AbstractJeeBean implements Serializable
{
final static Logger logger = LoggerFactory.getLogger(OutputTextBean.class);
private static final long serialVersionUID = 1L;
private final List<IoLocale> locales; public List<IoLocale> getLocales() {return locales;}
public OutputTextBean()
{
locales = new ArrayList<>();
}
@PostConstruct
public void init()
{
super.initSecurity();
locales.add(fUtils.fByEnum(IoLocale.class,JeeFacade.LocaleCode.en));
locales.add(fUtils.fByEnum(IoLocale.class,JeeFacade.LocaleCode.de));
locales.add(fUtils.fByEnum(IoLocale.class,JeeFacade.LocaleCode.fr));
}
public void validate()
{
validated = true;
}
private String field; public String getField() {return field;}
public void setField(String field) {this.field = field;}
private boolean validated; public boolean getValidated() {return validated;}
}