Requirement

Maybe you want to show a text with multi-language support from a resource bundle in an outputtext but you need to fill custom values between the words of the text. You could combine the parts of the text with the values in java and return the final string or you use this cool ADF feature to do so.

Solution

The secret for this is an ADF component for jsf page called “af:format”. This helps to fit parameters to your resource bundle text.

Format

There exist 5 variants of this component. So you have the possibility to fill in up to 4 custom values in your text.

  • af:format(String, Object)   < – with 1 parameter
  • af:format2(String, Object, Object) < – with 2 parameters
  • af:format3(String, Object, Object, Object) < – with 3 parameters
  • af:format4(String, Object, Object, Object, Object) < – with 4 parameters

 

Here we have a sample text with two placeholders:

DRUCK_FORTSCHRITT={0} von {1} Druckaufträgen sind gedruckt.

To use it in a jsf fragment or a jsf page you can combine both and fill in values:

<af:outputText value="#{af:format2(rechnungslegungtaskflowviewcontrollerBundle.DRUCK_FORTSCHRITT, 
pageFlowScope.myBean.counter ,'3')}" id="of8"/>

You can use hard values like the ‘3’ or you can reference to any binding or bean instance you have in access.

Format Named

Another possibility is the usage of format names to use names instead of indizes in the placeholders. It is the same idea like above but you can fill it with names.

  • af:formatNamed(String, String, Object) <- with 1 parameter
  • af:formatNamed2(String, String, Object, String, Object) <- with 2 paramters
  • af:formatNamed3(String, String, Object, String, Object, String, Object) <- with 3 parameters
  • af:formatNamed4(String, String, Object, String, Object, String, Object, String, Object) <- with 4 parameters

 

This is a sample text with one placeholder:

NEUER_WERT=Der neue Wert ist {first}.

To use it in a jsf fragment or a jsf page:

<af:outputText value="#{af:formatNamed(rechnungslegungtaskflowviewcontrollerBundle.NEUER_WERT, 
'first', '42')}" id="of2"/>