Displaying messagebox from backing bean

Reading Time: 1 minute 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

Reading Time: 1 minute 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

Reading Time: 1 minute 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

Reading Time: 1 minute   <?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>  

Catching Primefaces form elements in jquery and preventing copy paste and cut operations

Reading Time: 1 minute xhtml <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 type=”text/javascript”> $( document ).ready(function() { PF(‘firstNameVar’).jq.bind(‘cut copy paste’, function(e) { e.preventDefault(); }); PF(‘firstNameVar’).jq.bind(“contextmenu”, function(e) { e.preventDefault(); }); }); </script>

Disabling non alphabet characters while entering the input

Reading Time: 1 minute <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

Forwarding to a page from controller

Reading Time: 1 minute This is very useful when you compare that a passed object is null in the forthcoming controller you may directly forward user to a different page or maybe assign a message regarding the issue that the user had faced this error it depends on your development favorite FacesContext.getCurrentInstance().getExternalContext().redirect(“index.jsf”);  

Passing objects between managed beans&controllers

Reading Time: 1 minute 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”);

Adding resources css&js into the page

Reading Time: 1 minute Importing resources files for instance css and js can be really painful, which actually caused me tons of trouble to implement them. I’ve checked out many of examples on the internet, all they say it to create a folder named css for css files and js folder for javascript files in src/main/resources. So I did