Requirement: I have an af:inputText field where I can enter the Salary. We also have three buttons with the text as English, French, and German. Now, when the user clicks on any of these buttons it should change the Locale accordingly. For example, if the user clicks on the French button it should display the Salary value in French Locale.
Solution: For the solution of the above requirement follow the steps as shown below:
Step 1: Create an ADF Fusion Web Application.
Step 2: Create a demo.jspx page.
Drag and drop af:panelBox inside the demo.jspx page and set text=”Number Format according to Locale” and showDisclosure=”false”
Drag and drop af:toolbar inside the toolbar facet.
Drag and drop af:button and set text=”English” and actionListener=”#{pageFlowScope.MyBean.englishButtonAL}“
Drag and drop af:button and set text=”French” and actionListener=”#{pageFlowScope.MyBean.frenchButtonAL}“
Drag and drop af:button and set text=”German” and actionListener=”#{pageFlowScope.MyBean.germanButtonAL}“
Drag and drop af:inputText and set label=”Salary”and partialTriggers=”b1 b2 b3″
Drag and drop af:convertNumber inside the af:inputText and set locale=”#{pageFlowScope.MyBean.format}”
Thus, the complete code for the demo.jspx is shown below:
<?xml version='1.0' encoding='UTF-8'?> <jsp:root xmlns:jsp="" version="2.1" xmlns:f="" xmlns:af=""> <jsp:directive.page contentType="text/html;charset=UTF-8"/> <f:view> <af:document title="demo.jspx" id="d1"> <af:form id="f1"> <af:panelBox text="Number Format according to Locale" id="pb1" showDisclosure="false"> <af:inputText label="Salary" id="it1" partialTriggers="b1 b2 b3"> <af:convertNumber locale="#{pageFlowScope.MyBean.format}"/> </af:inputText> <f:facet name="toolbar"> <af:toolbar id="t1"> <af:button text="English" id="b1" actionListener="#{pageFlowScope.MyBean.englishButtonAL}"/> <af:button text="French" id="b2" actionListener="#{pageFlowScope.MyBean.frenchButtonAL}"/> <af:button text="German" id="b3" actionListener="#{pageFlowScope.MyBean.germanButtonAL}"/> </af:toolbar> </f:facet> </af:panelBox> </af:form> </af:document> </f:view> </jsp:root>
And the complete code for the MyBean.java class is shown below:
package susantotech.com; import java.util.Locale; import javax.faces.event.ActionEvent; public class MyBean { public MyBean() { } private Locale format = Locale.ENGLISH; public void setFormat(Locale format) { this.format = format; } public Locale getFormat() { return format; } public void englishButtonAL(ActionEvent actionEvent) { this.setFormat(Locale.ENGLISH); } public void frenchButtonAL(ActionEvent actionEvent) { this.setFormat(Locale.FRENCH); } public void germanButtonAL(ActionEvent actionEvent) { this.setFormat(Locale.GERMAN); } }
Save all and run the application. Thus, the ran application is shown below:
Enter the value in the Salary field as 123456789 and click on the English button and we can see the result as shown below:
Now, click on the French button and we can see the result as shown below:
When we click on the German button we can see the result as shown below:
Hence, the solution to our requirement.
If you like the post please comment, share, and do join me on Facebook. Please subscribe to my YouTube Channel for video tutorials.
Thanks & Regards,
Susanto Paul
814 total views, 3 views today