Passing tokens to ADF Faces Message

The following article shows how to add tokens to Faces Messages popped up on GUI.

Tokenization can be achieved by using java.text.MessageFormat class' format method. The format method takes in 2 arguments:

1. A String message - you can add a bundle text with tokens. The tokens will be replaced by supplied values, and the completed message will be displayed on the GUI.
2. Arguments of type Object array (Object[ ]).

The end results are as follows:


So how do we achieve this?

Step 1: We build the object arguments from the EmployeesVO1Iterator current row.
Step 2: We fetch the display message from the ViewControllerBundle file.
Step 3: We pass the arguments to the message, and the message is formatted using those arguments, and finally displayed on the GUI.

The below image shows the above logic inside a button action listener:

The "emp_click_message" bundle key looks something like this:


And here is how tokenization is achieved for the two arguments {0} and {1}:

You can add your favourite helper methods inside JSFUtils class and you're done! You have a full fledged tokenization system ready.

Comments