Java Server Faces

19 JSF Important Interview Questions

Java Server Faces
19 JSF Important Interview Questions: JSF(Java server faces) is component driven programming language which can be implemented with different faces like icefaces, acefaces, primefaces, richfaces etc. This can also be used with spring core and hibernate for ORM. Below are the few most important and repeated interview questions for JSF developers.   1. What are all the 6 phases of JSF Lifecycle ? 1. Restore view 2. Apply request values 3. Process validations 4. Update model values 5. Invoke application 6. Render response   2.¬†What is FacesContext or facescontext instance ? Facescontext is responsible to keep all the information's to process the single request.   3. What are all the scopes of JSF ? Scope represents the lifetime of the bean. @SessionScoped @

[solved] uioutput cannot be resolved to a type JSF

Errors and solutions, Java Server Faces
[solved] uioutput cannot be resolved to a type JSF: Error meaning is you did not import the UIOutput in your bean/controller. So you have to import the below UIOutput package, "import javax.faces.component.UIOutput;" to resolve the uioutput cannot be resolved to a type error/exception. If you are getting this exception in eclipse like in the below/similar line, String ajaxListValue = (String) ((UIOutput) event.getSource()).getValue(); then you need to put the cursor near UIOutput and enter the Ctrl+Space to get the auto import suggestions. In that select and import "javax.faces.component.UIOutput;"

Icefaces user session expired popup

Java Server Faces
Icefaces user session expired popup: Icefaces user session expired popup issue has been resolved after adding the below entries in the deployment descriptors (web.xml), The below one will redirect you to the ERRORPAGE.jsp onclick of any button after session timeout, [plain gutter="false"] org.icefaces.sessionExpiredRedirectURI /ERRORPAGE.jsp [/plain] But ensure you have added this entry too, [plain gutter="false"] javax.faces.application.ViewExpiredException /ERRORPAGE.jsp [/plain] If you want to redirect to ERRORPAGE.jsp after the session timeout automatically, then have to add the below code to web.xml (deployment descriptor) [plain gutter="false"] org.icefaces.strictSessionTimeout true [/plain] Try changing org.icefaces.strictSessionTim...

How to truncate td value in icefaces (jsf)

Java Server Faces
You can truncate the td value in jsf icefaces like this, You have to add "word-break:break-all" to your table style property. It will look like this, <ice:dataTable style="word-break:break-all"> <ice:colomn style="white-space:normal;"> </ice:column> </ice:dataTable> Ensure you have given the columnWidths property also to your datatable. Recommended Books:

Session Handling in Jsf Example

Java Server Faces
JsfSession.java: [java] package com.ngdeveloper.com; import javax.faces.FacesException; import javax.faces.application.Application; import javax.faces.application.ViewHandler; import javax.faces.component.UIViewRoot; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.faces.event.PhaseEvent; import javax.faces.event.PhaseId; import javax.faces.event.PhaseListener; import javax.servlet.http.HttpSession; public class JsfSession implements PhaseListener { @Override public void afterPhase(PhaseEvent event) { //Do anything } @Override public void beforePhase(PhaseEvent event) { FacesContext context = event.getFacesContext(); ExternalContext ext = context.getExternalC...

Iceface datatable column width adjustment

Java Server Faces
Solution for iceface datatable column width adjustment: You may face the issue while setting the iceface datatable column width adjustments. This can be achieved by the below way,   Use style="table-layout:fixed;" in the ice:column and ensure you have set the columnwidths already for all the columns. eg: <ice:column style="table-layout:fixed;" columnwidths="350px,490px">  

jQuery Show/Hide Example in Jsf

Java Server Faces, Jquery
jQuery Show/Hide Example in Jsf: Program: [html] <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"> <h:head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"> </script> <script> $(document).ready(function() { $("#content").hide(); $("#show_button").click(function() { $("#content").show(); }); $("#hide_button").click(function() { $("#content").hide(); }); }); </script> </h:head> <h:body> <h:commandButton value="show" id="show_button&quo...

Dynamically add/remove jsf components example

Java Server Faces
Program:   dynamic.xhtml: [html] <?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:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"> <h:head> </h:head> <h:body> <h:form> <h:dataTable value="#{dynBean.dynList}" var="myListElement"> <h:column> <h:panelGrid> <h:outputText value="www.ngdeveloper.com"></h:outputText> </h:panelGrid> </h:column> </h:dataTable> &l...

Ice Panel Popup Examples

Java Server Faces
In JSF, those who are using Ice components if they need popup they can go with Ice panel Popups. Ice Panel Popup : [html]<?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:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:ace="http://www.icefaces.org/icefaces/components" xmlns:ice="http://www.icesoft.com/icefaces/component" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head> </h:head> <h:body>...

[solved] diff propagated to root but no id set html null

Errors and solutions, Java Server Faces
diff propagated to root but no id set html null: Error: diff propagated to root but no id set html null Solution: Use <redirect/> in the faces-config file. Try to put h:panelGroup inside body (this error may occur if we use the ice components directly inside the body) - so it can be avoided if we use the ice components inside h:panelGroup. Recommended Books: