Displaying messagebox from backing bean

This piece of code snippet will initially hide the primefaces dialog box, then in any action from the backing bean, it will be activated and seen Back bean RequestContext context = RequestContext.getCurrentInstance(); context.execute("PF('dlgBlackListVar').show();"); View <p:dialog id="dlgBlackList" widgetVar="dlgBlackListVar" header="#{msg.member_blacklist_header}" showEffect="clip" modal="true" visible="false"> <h:outputText value="#{msg.member_blacklist_content}" /> </p:dialog>

Primefaces navigating in between min and max dates

Today at work I was stuck at demonstrating all the possible years which are given by min and max date ranges in the backing bean in primefaces and jsf combo. So as default primefaces calendar component only displays just set the year range to maximize the value the way you wish <p:calendar id="birthdate" value="#{memberController.order.birthdate}" yearRange="c-70:c+10"

JSF Multiple EL String concatenation

Today I’ve come to experience an usual situation which did result me to concatenate two strings values exceptionally derived from different EL sources. One is derived from database/controller the other is the messages/language sources. As you apprehend the situation from the below screenshot, Annual and Monthly values which pointed in the red color are fetched

Loading CSS JS Resources in JSF

  <?xml version=”1.0″ encoding=”UTF-8″?> <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml” xmlns:h=”http://java.sun.com/jsf/html” xmlns:ui=”http://java.sun.com/jsf/facelets”> <h:head> <h:outputStylesheet name=”basetemplate.css” library=”css”/> <h:outputStylesheet name=”shCore.css” library=”css”/> <h:outputStylesheet name=”shThemeDefault.css” library=”css”/> <h:outputScript name=”shCore.js” library=”js”/> <h:outputScript name=”shBrushXml.js” library=”js”/> <h:outputScript name=”shBrushJScript.js” library=”js”/> </h:head>  

Disabling non alphabet characters while entering the input

<p:inputText id="firstName" placeholder="#{msg.member_name}" value="#{memberController.order.firstName}" size="30" maxlength="30" widgetVar="firstNameVar" required="true" styleClass="#{not component.valid ? 'ui-input-invalid default-input-text' : 'default-input-text'}" onkeypress="return disallowNonAlphabethCharacters(event);"> <p:ajax delay="1000" event="keyup" oncomplete="rc([{name: 'component', value: ':primeForm:firstName'}, {name: 'widget', value: 'firstNameVar'}]);" /> </p:inputText>   Javascript <script language="javascript" type="text/javascript"> // <![CDATA[ function disallowNonAlphabethCharacters(e) { var charCode; if (window.event) charCode = window.event.keyCode; //for IE else charCode = e.charCode; //for firefox

Passing objects between managed beans&controllers

in the source controller add your object into faces session map interface and identify it with a name FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("category", category); then in the target controller to acquire the object do the following Category category = (Category) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("category");

JSF Message Resources

in src/main/resource create file called “MessageResources.properties” in which we will define our messages here footerText=This text is defined in the MessageResource.properties file Then add the below lines into your “faces-config.xml” file to identify the messages bundle into the application; <application> <resource-bundle> <base-name>MessageResources</base-name> <var>messages</var> </resource-bundle> </application> then in any of your .xhtml file you are good