Home Interviewquestions Jsf JSF Interview Questions
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JSF Interview Questions

Advertisement
How can we replace the JSF Standard Error Message? Create the message bundle file and set the value of the key for a particular type of error specified in JSF specification.

JSF Interview Questions

        

  1. How can we replace the JSF Standard Error Message?
    Create the message bundle file and set the value of the key for a particular type of error specified in JSF specification.
    For example, JSF specification supplies value "Value is required" for key "javax.faces.component.UIInput.REQUIRED" so replace the value in our message bundle file similar to the following :
     javax.faces.component.UIInput.REQUIRED= Please enter the required value.

    Register the message bundle within <application> tag  in the configuration file (faces-config.xml) and restart the server. Now when we use message or messages tag in the view page then the value specified in this message bundle file for a particular error is displayed.
      

  2. How we can change the appearance of error messages in a JSF Page?
    The appearance can be changed by any of the two methods :
    Using "style" attribute or "styleClass" attribute. "style" attribute is used to set the CSS style definition for the component while styleClass attribute is used to set the CSS class for the component. Using "styleClass" attribute is same as html "class" attribute.
  3. What is the significance of properties file (Resource Bundle) and how to use this in our JSF page?
    Properties file is a collection of param=value pairs. This provides a great benefit to the application like we can modify these values easily and there is no need to change the JSP file. For example, we can create "message.properties" like :
    prompt=Enter Your Name:
    greeting_text=Welcome In Roseindia
    button_text=Submit

    Now edit the configuration file using <message-bundle> element which tells the application where the message resource file is located.

    <application>
     <message-bundle>roseindia.messages</message-bundle>
    </application>

    Now, message resource bundle is loaded first using core tag <f:loadBundle> in view page. That loads the bundle and stores it in the request scope. 

    <f:loadBundle basename="roseindia.messages" var="message"/>

    We can now use this in our JSP like below :

    <h:outputText value="#{message.prompt}"/>
  4.  
  5. How can I use several configuration resource files in one single application?
    JSF finds configuration file or files looking in context initialization parameter, javax.faces.CONFIG_FILES  in web.xml, that specifies one or more paths to multiple configuration files for your web application. These multiple paths must be comma separeted. The important point to remember is not to register /WEB-INF/faces-config.xml file in the web.xml. Otherwise, the JSF implementation will process it twice. For example, make changes in web.xml like below :
    <context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>
    /WEB-INF/test1-config.xml,/WEB-INF/test2-config.xml
    </param-value>
    </context-param>
     
  6. Can we use a different configuration resource file in place of traditional "faces-config.xml" file in our application?
    JavaServer Faces technology provides an XML document for configuring resources. This file is used to register application's resources, such as validators, converters, managed beans, and navigation rules. This application configuration resource file is usually called faces-config.xml. You can have more than one application configuration resource file but it must be valid against the DTD located at http://java.sun.com/dtd/web-facesconfig_1_0.dtd. Now register the file within context-param element in web.xml file.
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 27, 2008

Related Tutorials

Ask Questions?    Discuss: JSF Interview Questions  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com