Java Object equals, hashCode, Hashing Collections and Hash Code Collision

Introduction In this blog post I’ll be focusing on something very fundamental and assumed as easy in the concept, but fairly the subject requires more focus and better apprehending. Besides that I am quite sure you’ll learn many interesting related to this topic. Object equals and hashCode Methods equals and hashCode methods are shipped with

Builder Pattern in Java

The Builder pattern eliminates building the complexity of the target object as well as eases the construction by providing such methods that will assemble the object same as building a set of blocks. By implementing the Builder pattern, there won’t be any need of larger constructors, parameter objects or custom types. Furthermore, the Builder pattern

Immutable Objects in Java

Immutability of an object indicates that once an object is constructed with given values, its state and values cannot be altered. In case of any value change must result in new object creation. Out of box Java offers some Immutable objects for instance java.lang.String, java.lang.Integer, java.lang.Float, java.math.BigDecimal. Immutable objects make generally a good use in

JSF Input text placeholder

In the Tag description add the pt entry and its corresponding web address <html xmlns=”” xmlns:h=”” xmlns:pt=””> in the input text declaration <h:inputText styleClass=”form-control” pt:placeholder=”Enter Search Value” required=”true” requiredMessage=”Please enter search value” value=”#{orderController.keyword}” id=”keywordSearch”/>

Java XML Parser

Using Dom4J <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version> </dependency> import org.apache.commons.lang.StringUtils; import org.dom4j.Document; import org.dom4j.DocumentHelper; import; import; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.xml.sax.InputSource; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import; import; import; import; public class XMLFormatter { private static Logger

JSF File Download

<h:commandLink action=”#{logController.downloadMessage}”> <h:outputText styleClass=”fa fa-fw fa-download”/> <f:setPropertyActionListener value=”#{log}” target=”#{logController.selectedLog}”/> </h:commandLink> public void downloadMessage() throws IOException {“downloading the log file”); File file = new File(searchKeyword + “_log.txt”); FileUtils.writeStringToFile(file, selectedLog.getMessageContent(), Charset.defaultCharset()); FacesContext facesContext = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); response.setHeader(“Content-Disposition”, “attachment;filename=” + file.getName()); response.setContentLength((int) file.length()); FileInputStream input = null; try { int i = 0;

JSF Primefaces Indicator

This example will show how to show a loader indicator while data is being fetch from the server. <h:panelGrid columns=”1″ id=”searchPanelGrid”> <h:panelGroup> <p:inputText id=”employeeId” placeholder=”Employee Id” required=”true” requiredMessage=”Employee Id is required” value=”#{createAdminController.employeeId}”/> <p:commandButton value=”Search in VCN” update=”ldapPanel @form” actionListener=”#{createAdminController.searchInVCN}” id=”searchButton”/> </h:panelGroup> </h:panelGrid> <p:blockUI block=”searchPanelGrid” trigger=”searchButton”> <h:graphicImage library=”images” name=”loader.gif”/> </p:blockUI>

JSF Return Hostname and App name

private static HttpServletRequest request = (HttpServletRequest) FacesContext .getCurrentInstance().getExternalContext().getRequest(); static Logger logger = LoggerFactory.getLogger(JSFUtils.class); public static String getServerHost() { return “http://” + request.getServerName() + “:” + request.getServerPort(); } public static String getServerHostWithAppName(){ String url = null; try { url = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath()).toString(); } catch (MalformedURLException e) { logger.error(e.toString()); } return url; }