JavaBeat FAQs
Sponsors
JAVABEAT
Home
Articles
Tips
QnA
Forums
FAQs Topics Books Topic
Java Java Books
Struts Struts Books
Spring Spring Books
Hibernate Hibernate Books
JBoss Seam Seam Books
J2EE J2EE Books
EJB EJB Books
JSF JSF Books
Servlets Servlets Books
JDBC JDBC Books
RMI RMI Books
JMS JMS Books
JNI JNI Books
Design Patterns Patterns Books
Exception Exception Books
Apache Ant Ant Books
Groovy
Cobertura
Quartz

JavaServerFaces(JSF) Interview Questions

JSF FAQs - 1 | JSF FAQs - 2 | JSF FAQs - 3

11)How to show Confirmation Dialog when user Click the Command Link?

h:commandLink assign the onclick attribute for internal use. So, you cannot use it to write your own code. This problem will fixed in the JSF 1.2. For the current JSF version you can use onmousedown event that occurs before onclick. <script language="javascript"> function ConfirmDelete(link) { var delete = confirm('Do you want to Delete?'); if (delete == true) { link.onclick(); } } </script> . . . . <h:commandLink action="delete" onmousedown="return ConfirmDelete(this);"> <h:outputText value="delete it"/> </h:commandLink>

12)What is the different between getRequestParameterMap() and getRequestParameterValuesMap()

getRequestParameterValuesMap() similar to getRequestParameterMap(), but contains multiple values for for the parameters with the same name. It is important if you one of the components such as <h:selectMany>.

13)Is it possible to have more than one Faces Configuration file?

Yes. You can define the list of the configuration files in the web.xml.
This is an example:
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config-navigation.xml,/WEB-INF/faces-beans.xml</param-value>
</context-param>

Note: Do not register /WEB-INF/faces-config.xml file in the web.xml . Otherwise, the JSF implementation will process it twice.


Hi there, I guess the Note: column should have been meant or intended for "faces-config.xml" file as thats the default configuration file for JSF (which is similar to struts-config.xml for Struts!!). faces-context.xml file sounds like the user defined config file similar to the aforementioned two xml files.



14)How to mask actual URL to the JSF page?

You'll need to implement your own version of javax.faces.ViewHandler which does what you need. Then, you register your own view handler in faces-config.xml.

Here's a simple abstract ViewHandler you can extend and then implement the 3 abstract methods for. The abstract methods you override here are where you'll do your conversions to/from URI to physical paths on the file system. This information is just passed right along to the default ViewHandler for JSF to deal with in the usual way. For example, you could override these methods to add and remove the file extension of an incoming view id (like in your example), for extension-less view URIs.

import java.io.IOException;
import java.util.Locale;

import javax.faces.FacesException;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * A facade view handler which maps URIs into actual physical views that the
 * underlying implementation can deal with regularly.
 
 * Therefore, all internal references to view ids, for example in faces-config,
 * will use the path to the physical files. Everything publicized, however, will
 * see a "converted" / facade url.
 */
public abstract class SimpleConverterViewHandler extends ViewHandler {
  private static final Log LOG = LogFactory
      .getLog(SimpleConverterViewHandler.class);

  private final ViewHandler base;

  public SimpleConverterViewHandler(ViewHandler base) {
    this.base = base;
  }

  /**
   * Distinguishes a URI from a physical file view.
   
   * Tests if a view id is in the expected format -- the format corresponding
   * to the physical file views, as opposed to the URIs.
   
   * This test is necessary because JSF takes the view ID from the
   * faces-config navigation, and calls renderView() on it, etc.
   */
  public abstract boolean isViewFormat(FacesContext context, String viewId);

  /**
   * Convert a private file path (view id) into a public URI.
   */
  public abstract String convertViewToURI(FacesContext context, String viewId);

  /**
   * Convert a public URI into a private file path (view id)
   
   * note: uri always starts with "/";
   */
  public abstract String convertURIToView(FacesContext context, String uri);

  public String getActionURL(FacesContext context, String viewId) {
    // NOTE: this is used for FORM actions.

    String newViewId = convertViewToURI(context, viewId);
    LOG.debug("getViewIdPath: " + viewId + "->" + newViewId);
    return base.getActionURL(context, newViewId);
  }

  private String doConvertURIToView(FacesContext context, String requestURI) {
    if (isViewFormat(context, requestURI)) {
      return requestURI;
    else {
      return convertURIToView(context, requestURI);
    }
  }

  public void renderView(FacesContext context, UIViewRoot viewToRender)
      throws IOException, FacesException {
    if (null == context || null == viewToRender)
      throw new NullPointerException("null context or view");

    String requestURI = viewToRender.getViewId();
    String newViewId = doConvertURIToView(context, requestURI);

    LOG.debug("renderView: " + requestURI + "->" + newViewId);

    viewToRender.setViewId(newViewId);

    base.renderView(context, viewToRender);
  }

  public UIViewRoot restoreView(FacesContext context, String viewId) {
    String newViewId = doConvertURIToView(context, viewId);
    LOG.debug("restoreView: " + viewId + "->" + newViewId);

    return base.restoreView(context, newViewId);
  }

  public Locale calculateLocale(FacesContext arg0) {
    return base.calculateLocale(arg0);
  }

  public String calculateRenderKitId(FacesContext arg0) {
    return base.calculateRenderKitId(arg0);
  }

  public UIViewRoot createView(FacesContext arg0, String arg1) {
    return base.createView(arg0, arg1);
  }

  public String getResourceURL(FacesContext arg0, String arg1) {
    return base.getResourceURL(arg0, arg1);
  }

  public void writeState(FacesContext arg0throws IOException {
    base.writeState(arg0);
  }

}


15)How to print out html markup with h:outputText?

The h:outputText has attribute escape that allows to escape the html markup. By default, it equals to "true". It means all the special symbols will be replaced with '&' codes. If you set it to "false", the text will be printed out without ecsaping.

For example, <h:outputText value="<b>This is a text</b>"/>

will be printed out like:

<b>This is a text</b>

In case of <h:outputText escape="false" value="<b>This is a text</b>"/>

you will get:

This is a text


16)h:inputSecret field becomes empty when page is reloaded. How to fix this?

Set redisplay=true, it is false by default.

Bookmark This Page : | | | | | | | | | | |
Related Articles
Liferay Portal Enterprise Intranets
ZK Developer’s Guide : Online Media Library
The BIRT Environment and Your First Report
AJAX - The Complete Reference
The Java 6.0 Compiler API
Spring Web Flow - Introduction
Introduction to Spring Web Framework
Integrating Struts With Spring
What's new in Struts 2.0? - Struts 2.0 Framework
Introductiion to Jakarta Struts
more articles
java6 ejb3 jsf hibernate eclipse ajax groovy spring seam java struts webservice j2me guice java5 jca tapestry soa linux ria

Sponsors
Webmaster Hosting Forum
Java Jobs
Latest in DLinks
http://javawave.blogspot.com/2008/04/quartz-job-scheduler-part-ii-example.html
Quartz Job Scheduler -- Part 1 (Setting up development project in Netbeans 6.1 beta)
Flex Messaging with BEA Workshop Studio
SOA and Virtualization: How do They Fit Together?
Introduction to Enterprise Portals - Why they Benefit IT and the Business
BEA WebLogic Operations Control: Application Virtualization for Enterprise Java
Best Practices for Building Production Quality EAR Files
BEA's SOA Reference Architecture - A Foundation for Business Agility
Blueprint for Successful SOA Integration
Guardian - What a tool!

JavaBeat Media (2004-2008), India
javabeat home | About Us
our network : opensource softwares
Copyright © 2007 JavaBeat