JSF Pass Parameter to Next Page





Hey guys, in this post we will discuss pass data from one page to another page in JSF with Example

Complete example


We will create this example step by step, follow this tutorial till the end

Read More:

Create Dynamic Web Project


To create a dynamic web project, you can read the following tutorial

Create Input form


Create hello-world.xhtml file inside the WebContent and add the following content

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
		xmlns:h="http://xmlns.jcp.org/jsf/html">

	<h:head>
		<title>Input Form</title>
	</h:head>
	
	<h:body>
		
		<h:form>
			<h:inputText id="greeting" value="#{theMessage}" />
			<h:commandButton value="Sulbmit" action="messageResponse" />
		</h:form>
		
	</h:body>

</html>
  • The attribute value contains the variable name #{theMessage}, which will hold the user entered value.
  • The attribute action contains the file name in which the control navigate to when user click the submit button.

Create a response page


Create messageResponse.xhtml file inside the WebContent and add the following content

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
		xmlns:h="http://xmlns.jcp.org/jsf/html">
		
	<h:head>
		<title>Response Page</title>	
	</h:head>
	
	<h:body>
		#{theMessage}
	</h:body>
	
</html>

#{theMessage} is used to print the variable value.

Run the app


To run the application, right click on the project, select Run As -> choose Run on Server

Open the browser, navigate to the URL http://localhost:8080/JSF-hello-world/faces/hello-world.xhtml

13

14

That’s it for this post. If you like this post, then please share this with your friends and collogues. Also share this post on your social media profiles as well.




Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

Leave a Reply