<?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>All1 Source technologies &#187; http support</title>
	<atom:link href="http://www.all1sourcetech.com/tag/http-support/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.all1sourcetech.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 23 Nov 2011 12:26:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Inside JSF 2.0&#8217;s Ajax and HTTP GET Support</title>
		<link>http://www.all1sourcetech.com/jsf-20s-ajax-http-support/</link>
		<comments>http://www.all1sourcetech.com/jsf-20s-ajax-http-support/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 11:46:31 +0000</pubDate>
		<dc:creator>Naggie</dc:creator>
				<category><![CDATA[Expert's Opinions]]></category>
		<category><![CDATA[Purely Technical]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[http support]]></category>
		<category><![CDATA[Java Web framework]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JSF 2.0's Ajax]]></category>
		<category><![CDATA[onlinequiz]]></category>

		<guid isPermaLink="false">http://www.all1sourcetech.com/?p=1043</guid>
		<description><![CDATA[With support for these techniques, this newest version of the Java component UI framework enables developers to build truly dynamic web pages simply and easily.
At the highest level, JSF technology provides an API for creating, managing, and handling UI components and a tag library for using components within a web page. The JSF 2.0 release [...]]]></description>
			<content:encoded><![CDATA[<p>With support for these techniques, this newest version of the Java component UI framework enables developers to build truly dynamic web pages simply and easily.</p>
<p>At the highest level, <a href="http://www.all1martpro.com" target="_blank">JSF technology</a> provides an API for creating, managing, and handling UI components and a tag library for using components within a web page. The JSF 2.0 release simplifies the web developer&#8217;s life by providing the following:</p>
<ul>
<li>Reusable UI components for easy authoring of web pages</li>
<li>Well defined and simple transfer of application data to and from the UI</li>
<li>Easy state management across server requests</li>
<li>Simplified event handling model</li>
<li>Easy creation of custom UI components</li>
</ul>
<p>For GET requests and Ajax integration, we need to drill down into JSF 2.0’s support, as well as the productive features that this support makes possible. The demo application is an online quiz that allows a registered user to answer five simple questions that test his or her general knowledge. Towards the end of the quiz, the application displays the score.</p>
<p><strong>Using GET Requests in JSF 2.0</strong></p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 247px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">To support GET requests, JSF 2.0 introduced the concept of View Parameters. View Parameters provide a way to attach query parameters to URLs. You use the tag &lt;f:viewParam&gt; to specify the query parameters.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 247px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Take this code for example:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 247px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;f:metadata&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 247px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;f:viewParam name=&#8221;previousScore&#8221; value=&#8221;#{recordBean.oldScore}&#8221; /&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 247px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;/f:metadata&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 247px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">In this example, the value of the parameter previousScore will be automatically picked up and pushed into the property oldScore of the recordBean. So, when a request like this comes for a URL:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 247px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">displayData.jspx?previousScore=10</div>
<p>To support GET requests, JSF 2.0 introduced the concept of View Parameters. View Parameters provide a way to attach query parameters to URLs. You use the tag <strong>&lt;f:viewParam&gt;</strong> to specify the query parameters.</p>
<p><strong>Take this code for example:</strong></p>
<p><span style="color: #008000;">&lt;f:metadata&gt;</span></p>
<p><span style="color: #008000;">&lt;f:viewParam name=&#8221;previousScore&#8221; value=&#8221;#{recordBean.oldScore}&#8221; /&gt;</span></p>
<p><span style="color: #008000;">&lt;/f:metadata&gt;</span></p>
<p>In this example, the value of the parameter previousScore will be automatically picked up and pushed into the property oldScore of the recordBean. So, when a request like this comes for a URL:</p>
<p><strong>displayData.jspx?previousScore=10</strong></p>
<p>The value of the bean property oldScore will be set to 10 when the request is processed, which avoids manually setting the value or using a listener. Another interesting point to notice is that like any other component the  tag <strong>&lt;f:viewParam&gt;</strong> supports conversion and validation. Hence, there is no need for separate conversion/validation logic.</p>
<p><strong>The new tags in JSF 2.0 related to support for the GETrequest.</strong></p>
<p><strong>h:button</strong> :- Renders a button that generates a GET request without any handcoding of URLs</p>
<p><strong>h:link</strong> :- Renders a link that generates a GET request without any handcoding of URLs</p>
<p><strong>h:outputStylesheet</strong> :- Refers to a CSS resource</p>
<p><strong>h:outputScript</strong> :- Refers to a JavaScript resource</p>
<p><strong>f:event</strong> :- Registers a specification-defined or a user-defined event</p>
<p><strong>f:ajax</strong> :- Enables associated component(s) to make Ajax calls</p>
<p><strong>f:metadata</strong> :- Declares the metadata facet for this view</p>
<p><strong>f:viewParam</strong> :- Used in  to define a view parameter that associates a request parameter to a model property</p>
<p><strong>f:validateBean</strong> :- Delegates the validation of the local value to the Bean Validation API</p>
<p><strong>f:validateRegex</strong> :- Uses the pattern attribute to validate the wrapping component</p>
<p><strong>f:validateRequired</strong> :- Ensures the presence of a value</p>
<p><strong>Bookmarking Support</strong></p>
<p>Because all <a href="http://www.all1social.com" target="_blank">JSF 1.x interactions</a> with the server use only HTTP POST requests, those JSF versions don&#8217;t support bookmarking pages in a web application. Even though some tags supported the construction of URLs, it was a manual process with no support for dynamic URL generation. JSF 2.0&#8217;s support for HTTP GET requests provides the bookmarking capability with the help of new renderer kits.</p>
<p>A new UI component UIOutcomeTarget provides properties that you can use to produce a hyperlink at render time. The component allows bookmarking pages for a button or a link.</p>
<p>The two HTML tags that support bookmarking are h:link and h:button. Both generate URLs based on the outcome property of the component, so that the author of the page no longer has to hard code the destination URL. These components use the JSF navigation model to decide the appropriate destination.</p>
<p><strong>Take the following code for example:</strong></p>
<p><span style="color: #008000;">&lt;h:link outcome=&#8221;login&#8221; value=&#8221;LoginPage&#8221; &gt;</span></p>
<p><span style="color: #008000;">&lt;f:param name=&#8221;Login&#8221; value=&#8221;#{loginBean.uname }&#8221; /&gt;</span></p>
<p><span style="color: #008000;">&lt;/h:link&gt;</span></p>
<p>This bookmarking feature provides an option for pre-emptive navigation (i.e., the navigation is decided at the render response time before the user has activated the component). This pre-emptive navigation is used to convert the logical outcome of the tag into a physical destination. At render time, the <a href="http://www.all1tunes.com" target="_blank">navigation system</a> is consulted to map the outcome to a target view ID, which is then transparently converted into the destination URL. This frees the page author from having to worry about manual URL construction.</p>
<p><strong>Support for Ajax</strong></p>
<p>The default implementation provides a single <a href="http://www.all1press.com" target="_blank">JavaScript resource</a> that has the resource identifier jsf.js. This resource is required for Ajax, and it must be available under the javax.faces library. The annotation@ResourceDependency is used to specify the Ajax resource for the components, the JavaScript function <strong>jsf.ajax.request</strong> is used to send information to the server in an asynchronous way, and the JavaScript function <strong>jsf.ajax.response</strong> is used for sending the information back from the server to the client.</p>
<p>On the client side, the API <strong>jsf.ajax.request</strong> is used to issue an Ajax request. When the response has to be rendered back to the client, the callback previously provided by jsf.ajax.request is invoked. This automatically updates the client-side DOM to reflect the newly rendered markup.</p>
<p><strong>The two ways to send an Ajax request by registering an event callback function are:</strong></p>
<ul>
<li>Use the JavaScript function jsf.ajax.request</li>
<li>Use the <strong>&lt;f:ajax&gt;</strong> tag</li>
</ul>
<p><strong>JavaScript Function jsf.ajax.request</strong></p>
<p>The function <strong>jsf.ajax.request</strong>(source, event, options) is used to send an asynchronous Ajax request to the server. The code snippet below shows how you can use this function:</p>
<p><span style="color: #008000;">&lt;commandButton id=&#8221;newButton&#8221; value=&#8221;submit&#8221;</span></p>
<p><span style="color: #008000;">onclick=&#8221;jsf.ajax.request(this,event,</span></p>
<p><span style="color: #008000;">{execute:&#8217;newButton&#8217;,render:&#8217;status&#8217;,onevent: handleEvent,onerror: handleError});return false;&#8221;/&gt;</span></p>
<p><span style="color: #008000;">&lt;/commandButton/&gt;</span></p>
<p>The first argument in the function represents the DOM element that made an Ajax call, while the second argument (which is optional) corresponds to the DOM event that triggered this request. The third argument is composed of a set of parameters, which is sent mainly to control the client/server processing. The available options are execute, render, onevent, onerror, and params.</p>
<p><strong>&lt;f:ajax&gt; Tag</strong></p>
<p><strong>JSF 2.0</strong> enables page authoring with <strong>&lt;f:ajax&gt;</strong>, which is a declarative approach for making Ajax requests. You can use this tag instead of manually coding the JavaScript for Ajax request calls. This tag serves two roles, depending on the placement. You can nest it within any <strong>HTML component or custom component</strong>. If you nest it with a single component, it will associate an Ajax action with that component.</p>
<p>The <strong>&lt;f:ajax&gt;</strong> <strong>tag </strong>has four important attributes:</p>
<ul>
<li><strong>render </strong>– ID or a space-delimited list of component identifiers that will be updated as a result of the Ajax call</li>
<li><strong>execute </strong>– ID or a space-delimited list of component identifiers that should be executed on the server</li>
<li><strong>event </strong>– The type of event the Ajax action will apply to (refers to a JavaScript event without the on prefix)</li>
<li><strong>onevent </strong>– The JavaScript function to handle the event</li>
</ul>
<p>Consider the following code from the login page of the online quiz application. The code validates the input of the email field by sending an Ajax call for every keystroke. The validation is done by a managed bean method that acts as a value change listener.</p>
<p><span style="color: #008000;">&lt;h:inputText label=&#8221;eMail ID&#8221;   id=&#8221;emailId&#8221; value=&#8221;#{userBean.email}&#8221; size=&#8221;20&#8243;</span></p>
<p><span style="color: #008000;">required=&#8221;true&#8221; valueChangeListener=&#8221;#{userBean.validateEmail}&#8221;&gt;</span></p>
<p><span style="color: #008000;">&lt;f:ajax event=&#8221;keyup&#8221; render=&#8221;emailResult&#8221;/&gt;</span></p>
<p><span style="color: #008000;">&lt;/h:inputText&gt;</span></p>
<p><span style="color: #008000;">&#8230;</span></p>
<p><span style="color: #008000;">&lt;h:outputText id=&#8221; emailResult&#8221; value=&#8221;#{userBean.emailPrompt}&#8221; /&gt;</span></p>
<p style="text-align: center;"><img class="aligncenter" src="http://www.developer.com/img/2010/03/OnlineQuizAjax_Fig1.JPG" alt=" Inside JSF 2.0s Ajax and HTTP GET Support" width="715" height="302" title="Inside JSF 2.0s Ajax and HTTP GET Support" /></p>
<p>Using Ajax to Validate the Input: The online quiz application validates email field input by sending an Ajax call for every keystroke.</p>
<p>Here, <strong>&lt;f:ajax&gt;</strong> is nested within the emailId inputText component. For every keyup event that is generated, an Ajax call is sent to the server, which invokes the valueChangeListener. By default, the component in which the tag is nested is executed on the server. So, the execute attribute is not specified. Also, for an input component, the default event is valueChange, so the event attribute is also not used. The render attribute indicates that the outputText component emailResult should be updated after the Ajax call.</p>
<p>If you place this tag around a group of components, it will associate an Ajax action with all the components that support the events attribute.</p>
<p><span style="color: #008000;">&lt;f:ajax event=&#8221;mouseover&#8221;&gt;</span></p>
<p><span style="color: #008000;">&lt;h:inputText id=&#8221;input1&#8243; &#8230;/&gt;</span></p>
<p><span style="color: #008000;">&lt;h:commandLink id=&#8221;link1&#8243; &#8230;/&gt;</span></p>
<p><span style="color: #008000;">&lt;/f:ajax&gt;</span></p>
<p><strong>In this example, input1 and link1 will exhibit Ajax behavior on a mouseover event.</strong></p>
<p><span style="color: #008000;">&lt;f:ajax event=&#8221;mouseover&#8221;&gt;</span></p>
<p><span style="color: #008000;">&lt;h:inputText id=&#8221;input1&#8243; &#8230;&gt;</span></p>
<p><span style="color: #008000;">&lt;f:ajax event=&#8221;keyup&#8221;/&gt;</span></p>
<p><span style="color: #008000;">&lt;/h:inputText&gt;</span></p>
<p><span style="color: #008000;">&lt;h:commandLink id=&#8221;link1&#8243; &#8230;/&gt;</span></p>
<p><span style="color: #008000;">&lt;/f:ajax&gt;</span></p>
<p>In this example, input1 and link1 exhibit Ajax behavior on keyup and mouseover events, respectively.</p>
<p>Using the Ajax tag enhances the markup of the associated component to include a script that triggers the Ajax request. This the page author to issue Ajax requests without having to write any JavaScript code.</p>
<p>These new features enable developers to build truly dynamic web pages simply and easily.</p>
<p><a href="http://www.developer.com/" target="_blank">http://www.developer.com</a></p>
<p><a href="http://www.all1sourcetech.com" target="_blank">http://www.all1sourcetech.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.all1sourcetech.com/jsf-20s-ajax-http-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

