<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java Interview Questions &#187; JSF Interview Questions</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/jsf-interview-questions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bestjavainterviewquestions.com</link>
	<description>Java Interview Questions &#124; Core Java Interview Questions &#124; Advanced Java Interview Questions &#124; EJB Interview Questions &#124; J2EE Interview Questions &#124; Hibernate Interview Questions</description>
	<lastBuildDate>Fri, 30 Jul 2010 06:00:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>JSF Important Questions</title>
		<link>http://www.bestjavainterviewquestions.com/jsf-important-questions/</link>
		<comments>http://www.bestjavainterviewquestions.com/jsf-important-questions/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 18:41:25 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[JSF Interview Questions]]></category>
		<category><![CDATA[jsf review]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=84</guid>
		<description><![CDATA[Q) How to show Confirmation Dialog when user Click the Command Link? A) 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. &#60;script language=&#8221;javascript&#8221;&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q) How to show Confirmation Dialog when user Click the Command Link?<br />
A) </strong></p>
<p>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.</p>
<p><em>&lt;script language=&#8221;javascript&#8221;&gt; function ConfirmDelete(link) { var delete = confirm(&#8216;Do you want to Delete?&#8217;); if (delete == true) { link.onclick(); } } &lt;/script&gt; . . . . &lt;h:commandLink action=&#8221;delete&#8221; onmousedown=&#8221;return ConfirmDelete(this);&#8221;&gt; &lt;h:outputText value=&#8221;delete it&#8221;/&gt; &lt;/h:commandLink&gt;</em></p>
<p><strong>Q) What is the different between getRequestParameterMap() and getRequestParameterValuesMap()?<br />
A) </strong>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 .</p>
<p><strong>Q) Is it possible to have more than one Faces Configuration file?<br />
A) </strong>Yes. You can define the list of the configuration files in the web.xml.<br />
This is an example:</p>
<p><em>&lt;context-param&gt; &lt;param-name&gt;javax.faces.CONFIG_FILES&lt;/param-name&gt;      &lt;param-value&gt;/WEB-INF/faces-config-navigation.xml,/WEB-INF/faces-beans.xml&lt;/param-value&gt;&lt;/context-param&gt;</em><br />
Note: Do not register /WEB-INF/faces-config.xml file in the web.xml . Otherwise, the JSF implementation will process it twice.</p>
<p><strong>Q) How to mask actual URL to the JSF page?<br />
A) </strong>You&#8217;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.<br />
Here&#8217;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&#8217;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.</p>
<div style="overflow: auto; width: 450px; height: 200px; background-color: #e9e0da;">import java.io.IOException;<br />
import java.util.Locale;import javax.faces.FacesException;<br />
import javax.faces.application.ViewHandler;<br />
import javax.faces.component.UIViewRoot;<br />
import javax.faces.context.FacesContext;</p>
<p>import org.apache.commons.logging.Log;<br />
import org.apache.commons.logging.LogFactory;</p>
<p>/**<br />
* A facade view handler which maps URIs into actual physical views that the<br />
* underlying implementation can deal with regularly.<br />
*<br />
* Therefore, all internal references to view ids, for example in faces-config,<br />
* will use the path to the physical files. Everything publicized, however, will<br />
* see a &#8220;converted&#8221; / facade url.<br />
*/<br />
public abstract class SimpleConverterViewHandler extends ViewHandler {<br />
private static final Log LOG = LogFactory<br />
.getLog(SimpleConverterViewHandler.class);</p>
<p>private final ViewHandler base;</p>
<p>public SimpleConverterViewHandler(ViewHandler base) {<br />
this.base = base;<br />
}</p>
<p>/**<br />
* Distinguishes a URI from a physical file view.<br />
*<br />
* Tests if a view id is in the expected format &#8212; the format corresponding<br />
* to the physical file views, as opposed to the URIs.<br />
*<br />
* This test is necessary because JSF takes the view ID from the<br />
* faces-config navigation, and calls renderView() on it, etc.<br />
*/<br />
public abstract boolean isViewFormat(FacesContext context, String viewId);</p>
<p>/**<br />
* Convert a private file path (view id) into a public URI.<br />
*/<br />
public abstract String convertViewToURI(FacesContext context, String viewId);</p>
<p>/**<br />
* Convert a public URI into a private file path (view id)<br />
*<br />
* note: uri always starts with &#8220;/&#8221;;<br />
*/<br />
public abstract String convertURIToView(FacesContext context, String uri);</p>
<p>public String getActionURL(FacesContext context, String viewId) {<br />
// NOTE: this is used for FORM actions.</p>
<p>String newViewId = convertViewToURI(context, viewId);<br />
LOG.debug(&#8220;getViewIdPath: &#8221; + viewId + &#8220;-&gt;&#8221; + newViewId);<br />
return base.getActionURL(context, newViewId);<br />
}</p>
<p>private String doConvertURIToView(FacesContext context, String requestURI) {<br />
if (isViewFormat(context, requestURI)) {<br />
return requestURI;<br />
} else {<br />
return convertURIToView(context, requestURI);<br />
}<br />
}</p>
<p>public void renderView(FacesContext context, UIViewRoot viewToRender)<br />
throws IOException, FacesException {<br />
if (null == context || null == viewToRender)<br />
throw new NullPointerException(&#8220;null context or view&#8221;);</p>
<p>String requestURI = viewToRender.getViewId();<br />
String newViewId = doConvertURIToView(context, requestURI);</p>
<p>LOG.debug(&#8220;renderView: &#8221; + requestURI + &#8220;-&gt;&#8221; + newViewId);</p>
<p>viewToRender.setViewId(newViewId);</p>
<p>base.renderView(context, viewToRender);<br />
}</p>
<p>public UIViewRoot restoreView(FacesContext context, String viewId) {<br />
String newViewId = doConvertURIToView(context, viewId);<br />
LOG.debug(&#8220;restoreView: &#8221; + viewId + &#8220;-&gt;&#8221; + newViewId);</p>
<p>return base.restoreView(context, newViewId);<br />
}</p>
<p>public Locale calculateLocale(FacesContext arg0) {<br />
return base.calculateLocale(arg0);<br />
}</p>
<p>public String calculateRenderKitId(FacesContext arg0) {<br />
return base.calculateRenderKitId(arg0);<br />
}</p>
<p>public UIViewRoot createView(FacesContext arg0, String arg1) {<br />
return base.createView(arg0, arg1);<br />
}</p>
<p>public String getResourceURL(FacesContext arg0, String arg1) {<br />
return base.getResourceURL(arg0, arg1);<br />
}</p>
<p>public void writeState(FacesContext arg0) throws IOException {<br />
base.writeState(arg0);<br />
}</p>
<p>}
</p></div>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/explain-java-takes-care-of-registering-the-driver/" title="Explain Java takes care of registering the driver"><img src="Array" alt="Explain Java takes care of registering the driver" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/explain-jsp-declaration/" title="Explain JSP Declaration"><img src="Array" alt="Explain JSP Declaration" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/thread-example-for-runnable-interface/" title="Thread example for Runnable Interface"><img src="Array" alt="Thread example for Runnable Interface" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/what-is-thread-how-to-use-threads/" title="What is Thread, How to Use Threads?"><img src="Array" alt="What is Thread, How to Use Threads?" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/java-multi-thread-questions/" title="Java Multi-Thread Questions"><img src="Array" alt="Java Multi-Thread Questions" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/jsf-important-questions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JSF Important Interview Questions</title>
		<link>http://www.bestjavainterviewquestions.com/jsf-important-interview-questions/</link>
		<comments>http://www.bestjavainterviewquestions.com/jsf-important-interview-questions/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 18:19:40 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[JSF Interview Questions]]></category>
		<category><![CDATA[jsf key questions]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=79</guid>
		<description><![CDATA[Q) How to get current page URL from backing bean? A) You can get a reference to the HTTP request object via FacesContext like this: FacesContext fc = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest(); and then use the normal request methods to obtain path information. Alternatively, context.getViewRoot().getViewId(); will return you the name of the current [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q) How to get current page URL from backing bean?<br />
A) </strong>You can get a reference to the HTTP request object via FacesContext like this:</p>
<div style="overflow: auto; width: 450px; height: 150px; background-color: #e9e0da;">FacesContext fc = FacesContext.getCurrentInstance();<br />
HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();<br />
and then use the normal request methods to obtain path information. Alternatively,<br />
context.getViewRoot().getViewId();</div>
<p></p>
<p>will return you the name of the current JSP (JSF view IDs are basically just JSP path names)</p>
<p><strong>Q) How to access web.xml init parameters from jsp page?<br />
A) </strong>You can get it using initParam pre-defined JSF EL valiable.<br />
For example, if you have:<br />
<strong><br />
&lt;context-param&gt; &lt;param-name&gt;productId&lt;/param-name&gt; &lt;param-value&gt;2004Q4&lt;/param-value&gt;&lt;/context-param&gt;</strong><br />
You can access this parameter with #{initParam['productId']} . For example:<br />
Product Id: <strong>&lt;h:outputText value=&#8221;#{initParam['productId']}&#8221;/&gt;</strong></p>
<p><strong>Q) How to access web.xml init parameters from java code?<br />
A)</strong> You can get it using externalContext getInitParameter method. For example, if you have:<br />
<strong>&lt;context-param&gt; &lt;param-name&gt;connectionString&lt;/param-name&gt; &lt;param-value&gt;jdbc:oracle:thin:scott/tiger@cartman:1521:O901DB&lt;/param-value&gt;&lt;/context-param&gt;</strong><br />
You can access this connection string with:</p>
<p><strong>FacesContext fc = FacesContext.getCurrentInstance();<br />
String connection = fc.getExternalContext().getInitParameter(&#8220;connectionString&#8221;);<br />
</strong></p>
<p><strong><br />
Q) How to terminate the session?<br />
A) </strong>In order to terminate the session you can use session invalidate method.<br />
This is an example how to terminate the session from the action method of a backing bean:</p>
<div style="overflow: auto; width: 450px; height: 200px; background-color: #e9e0da;">public String logout() {</p>
<p>FacesContext fc = FacesContext.getCurrentInstance();<br />
HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);<br />
session.invalidate();<br />
return &#8220;login_page&#8221;;<br />
}</p>
<p>The following code snippet allows to terminate the session from the jsp page:</p>
<p>&lt;% session.invalidate(); %&gt; &lt;c:redirect url=&#8221;loginPage.jsf&#8221; /&gt;</p></div>
<p></p>
<p><strong>Q) How to implement &#8220;Please, Wait&#8230;&#8221; page?<br />
A)</strong> The client-side solution might be very simple. You can wrap the jsp page (or part of it you want to hide) into the DIV, then you can add one more DIV that appears when user clicks the submit button. This DIV can contain the animated gif you speak about or any other content.<br />
Scenario: when user clicks the button, the JavaScript function is called. This function hides the page and shows the &#8220;Wait&#8221; DIV. You can customize the look-n-fill with CSS if you like.<br />
This is a working example:</p>
<div style="overflow: auto; width: 450px; height: 200px; background-color: #e9e0da;">&lt;%@ taglib uri=&#8221;http://java.sun.com/jsf/html&#8221; prefix=&#8221;h&#8221; %&gt;<br />
&lt;%@ taglib uri=&#8221;http://java.sun.com/jsf/core&#8221; prefix=&#8221;f&#8221; %&gt;<br />
&lt;f:loadBundle basename=&#8221;demo.bundle.Messages&#8221; var=&#8221;Message&#8221;/&gt;</p>
<p>&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Input Name Page&lt;/title&gt;<br />
&lt;script&gt;<br />
function gowait() {<br />
document.getElementById(&#8220;main&#8221;).style.visibility=&#8221;hidden&#8221;;<br />
document.getElementById(&#8220;wait&#8221;).style.visibility=&#8221;visible&#8221;;<br />
}<br />
&lt;/script&gt;</p>
<p>&lt;/head&gt;<br />
&lt;body bgcolor=&#8221;white&#8221;&gt;<br />
&lt;f:view&gt;<br />
&lt;div id=&#8221;main&#8221;&gt;<br />
&lt;h1&gt;&lt;h:outputText value=&#8221;#{Message.inputname_header}&#8221;/&gt;&lt;/h1&gt;<br />
&lt;h:messages style=&#8221;color: red&#8221;/&gt;<br />
&lt;h:form id=&#8221;helloForm&#8221;&gt;</p>
<p>&lt;h:outputText value=&#8221;#{Message.prompt}&#8221;/&gt;<br />
&lt;h:inputText id=&#8221;userName&#8221; value=&#8221;#{GetNameBean.userName}&#8221; required=&#8221;true&#8221;&gt;<br />
&lt;f:validateLength minimum=&#8221;2&#8243; maximum=&#8221;20&#8243;/&gt;<br />
&lt;/h:inputText&gt;<br />
&lt;h:commandButton onclick=&#8221;gowait()&#8221; id=&#8221;submit&#8221;<br />
action=&#8221;#{GetNameBean.action}&#8221; value=&#8221;Say Hello&#8221; /&gt;<br />
&lt;/h:form&gt;<br />
&lt;/div&gt;<br />
&lt;div id=&#8221;wait&#8221; style=&#8221;visibility:hidden; position: absolute; top: 0; left: 0&#8243;&gt;<br />
&lt;table width=&#8221;100%&#8221; height =&#8221;300px&#8221;&gt;<br />
&lt;tr&gt;<br />
&lt;td align=&#8221;center&#8221; valign=&#8221;middle&#8221;&gt;<br />
&lt;h2&gt;Please, wait&#8230;&lt;/h2&gt;<br />
&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;/div&gt;<br />
&lt;/f:view&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>If you want to have an animated gif of the &#8220;Wait&#8221; Page, the gif should be reloaded after the form is just submitted. So, assign the id for your image and then add reload code that will be called after some short delay. For the example above, it might be:<br />
&lt;script&gt;<br />
function gowait() {<br />
document.getElementById(&#8220;main&#8221;).style.visibility=&#8221;hidden&#8221;;<br />
document.getElementById(&#8220;wait&#8221;).style.visibility=&#8221;visible&#8221;;<br />
window.setTimeout(&#8216;showProgress()&#8217;, 500);<br />
}<br />
function showProgress(){<br />
var wg = document.getElementById(&#8220;waitgif&#8221;);<br />
wg.src=wg.src;<br />
}<br />
&lt;/script&gt;<br />
&#8230;.<br />
&#8230;.<br />
&#8230;.<br />
&lt;img id=&#8221;waitgif&#8221; src=&#8221;animated.gif&#8221;&gt;</p></div>
<p></p>
<p><strong>Q) How to reload the page after ValueChangeListener is invoked?<br />
A) </strong>At the end of the ValueChangeListener, call FacesContext.getCurrentInstance().renderResponse()</p>
<p><strong>Q) How to download PDF file with JSF?<br />
A)</strong> This is an code example how it can be done with action listener of the backing bean.<br />
Add the following method to the backing bean:</p>
<div style="overflow: auto; width: 450px; height: 200px; background-color: #e9e0da;">public void viewPdf(ActionEvent event) {<br />
String filename = &#8220;filename.pdf&#8221;;// use your own method that reads file to the byte array<br />
byte[] pdf = getTheContentOfTheFile(filename);</p>
<p>FacesContext faces = FacesContext.getCurrentInstance();<br />
HttpServletResponse response = (HttpServletResponse) faces.getExternalContext().getResponse();<br />
response.setContentType(&#8220;application/pdf&#8221;);<br />
response.setContentLength(pdf.length);</p>
<p>response.setHeader( &#8220;Content-disposition&#8221;, &#8220;inline;filename=\&#8221;"+fileName+&#8221;\&#8221;");<br />
try {<br />
ServletOutputStream out;<br />
out = response.getOutputStream();<br />
out.write(pdf);<br />
} catch (IOException e) {<br />
e.printStackTrace();<br />
}<br />
faces.responseComplete();<br />
}<br />
This is a jsp file snippet:</p>
<p>&lt;h:commandButton immediate=&#8221;true&#8221; actionListener=&#8221;#{backingBean.viewPdf}&#8221; value=&#8221;Read PDF&#8221; /&gt;</p></div>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/dynamic-and-static-web-page/" title="Dynamic and Static Web Page"><img src="Array" alt="Dynamic and Static Web Page" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/exception-handling-and-their-uses/" title="Exception Handling and their uses"><img src="Array" alt="Exception Handling and their uses" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/java-swings-interview-questions-2/" title="Java Swings Interview Questions"><img src="Array" alt="Java Swings Interview Questions" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/collection-framework/" title="Collection FrameWork"><img src="Array" alt="Collection FrameWork" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/explain-the-instance-variables-in-servlets/" title="Explain the Instance Variables in Servlets"><img src="Array" alt="Explain the Instance Variables in Servlets" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/jsf-important-interview-questions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
