Requirement: I have a demo.jspx page on which I have a button with the name “Show Multiline FacesMessage“.
Now, when we click on the “Show Multiline FacesMessage” button, it should show us the Multiline FacesMessage as shown below:
Solution: For solution of the above requirement follow the steps as shown below:
Step 1: Create an Oracle ADF Fusion Web Application with the name “MultilineFacesMessageSample“
Step 2: Create a demo.jspx. Drag and drop the panelGroupLayout and inside that drag and drop a button.
Set the text of the button as “Show Multiline FacesMessage“. Set the actionListener for the button as “showMultilineFacesMessageAL“
Thus, the complete demo.jspx is as 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:panelGroupLayout id="pgl1">
<af:button text="Show Multiline FacesMessage" id="b1"
actionListener="#{pageFlowScope.MyBean.showMultilineFacesMessageAL}"/>
</af:panelGroupLayout>
</af:form>
</af:document>
</f:view>
</jsp:root>
And the complete MyBean.java code is as below:
package susantotech.com;
import javax.faces.event.ActionEvent;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
public class MyBean {
public MyBean() {
}
public void showMultilineFacesMessageAL(ActionEvent actionEvent) {
StringBuilder message = new StringBuilder("<html><body>");
message.append("<p>My Name is <b>Susanto Paul</b></p>");
message.append("<p>I welcome you to the world of <b>Oracle ADF</b></p>");
message.append("<p style='color:green'><i>Please do join SusantoTech on Facebook page</b></p>");
message.append("</body></html>");
FacesMessage fm = new FacesMessage(message.toString());
fm.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext fctx = FacesContext.getCurrentInstance();
fctx.addMessage(null, fm);
}
}
Save all and run the application. Thus, the ran application is shown below.
Click on the “Show Multiline FacesMessage” button and we can see the Multiline FacesMessage 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
524 total views, 2 views today