Steps to use Hyperlinks in JSF pages

Blog Author


Published Date

17th September, 2018




  • Share this blog :

Steps to use Hyperlinks in JSF pages Step1: Prepare hyperlink in JSP or xhtml pages depending on the JSF Version To prepare hyperlink we have to use the following html <h:command link value=”--”action=”--”/> àWhere ”values” attribute will be hyperlink label àWhere ”action” attribute will take JSF expression to refer a managed bean method to execute. Eg - <h:command link value=”login” action=#{log in bean get log in page}”/}   NOTE <h:command link>must be used under<h:form> Step2 -  To prepare action method in managed bean component Prepare a method in managed bean component with string return type and its name must be same as the method name which we specified in action attribute expression in <h:command link>tag Public class log in bean{ Public string get log in page(){ Return ”log in form”; } }    Note - In case of JSF 2.X The return value from action method should be same as the target age name which we want to open in case of annotations. Step3  PREPARE NAVIGATION RULE IN FACES –CONFIGE.XML FILE <Faces-config…}xsd <navigation- rule> <from- view-id>1page where clicked on hyperlink</from – view -d> <navigation- case> <navigation- rule> </faces-config> Note In JSF 2.X,IF we use annotations than this step is not required     Screenshot_16     Login from.jsp <%@tag lib prefix=”f”url=””%> <%@taglib prefix=”h”url=””%> <html> <body> <f:view> <font color=”red”> <h1> software solutions</h1> </h2;Log in page</h2> </font> <h:form> <h:panel Grid column=”2”> <h:ourput text value=”user name”/> <h:in put text id=u name value=”#{log in bean. U name}”/> <h:ourput text value=”password”/> <h:in put text id=u pwd value=”#{log in bean. U pwd}”/> <h: command button value=”log in” action=”#{log in bean. Log in”/> <h3><h: command link value=”registration” Action =”#{ log in bean .get registration page}”/></h3> </h:parel Grid> </h: form></f:view></body></html>   Registration form. JSP - <%@taglib prefix “f” <html> <body> <f:view> <font color=”red”> <h1> soft</h1> <h2> registration page </h2> </font > <h:from> <h:panel Grid column=”2”> <h:output text value=”user name”/> <h: input text id =u name value=”#{reg bean. u name}”/> <h: output text value=”pass word”/> <h:input text id= u pwd value=”#{reg bean, u pewd}”/> <h: ouput text value=”email”/> <h:input text id- u email value=”#{reg bean. uemail}”/> <h:out put text value=”mobile”/> <h: input text id= umoble value=”#{reg bean. U mobile}”/> <h:command button value=”Registration”action =”#{reg bean. registration}”/> </h: panel Grid> </h:form> </f:view> </body> </html>   Success.jsp - <%@ tag lib prefix=”f”--> <html> <body> <f:view> <h:command link value=”login” action=”#{log in bean get log in page}”/> </h:form> </f:view></body></html>   Failure.JSP  <%@ taglib prefix=”f” <html> <body> <f:view> <h1>failure</h1> <h:form> <h:command like value=”registration” action=”#{log in bean. Get registration page}”/> </h:form> </f:view> </body> </html>   Existed.jsp <%@taglib prefix=”f” <html> <body> </f:view> <h1>User already existed</h1> <h:from> <h:command link value=”log in ”action=”#{log in bean. Get language”/> </h: form></f:view></body></html>   Index. Html </html> <head> <meta http-equiv=”Refresh Content=”2;url=http://local host:1010/log in  app/ log in form. dss> </head> <body><h1>Application is Loading</h1> </body> </html>   Log in Bean. Java Package com. soft Import javax. faces. bean. Managed bean; Import javax. faces. bean. sessionscoped; @ Managed bean(name=”log in Bean”) @session scoped Public class log in bean { Private string u name; Private string upwd; //provide getter()& setters() Public string get log in page(){ Return ”log in form”; } Public string get registration page() { Return ”Registration form”; } Public string log in(){ User DAO dao=user dao factory. Get user dao(); String status=dao.check log in ( u name, u pwd); Return status; } }   Registration Bean. Java Package com. soft; Import javax. faces. bean. managed bean; Import javax. faces. bean. Session scoped; @managed Bean (name=”meg Bean”) @Session scoped Public class registration bean{ Private string u name; Private string u pwd; Private string uemail; Private string u mobile; //provide getter()& setter() Public string registration() { User DAO dao=user Dao Factory. get user Dao(); String status=dao. registration (u name. upwd, ue mail, umobile); Return status; } }   User Dao.Java Package com.soft; Public interface user Dao{ Public string check log in(string u name, string u pwd) Public string registration[string u name, String upwd, string uemail, string umobile); }   User Dao Package com. soft sql. connection; Import .java. sql. Prepared statement Import .java. sql. ResultSet Public class user dao imp/ implements user dao { String status=””; Public storing checkLog in (string uname, string upwd) { Try { Connection con- Connection factory. get Connection(); Prepared statement pst=con.PrepareStatement(“ Select from reg-users where u name=”+u name+”and ResultSet ms=pst.executeQuery(); Boolean b=; If(b==true) { Status=”success”; } Else { Status-“failure”; } } Catch(Exception e) {

  1. print stack trace();

} Return status } Public string registration(string uname, string upwd, stromg uemail. String u mobile){ Try{ Connection con- Connection factory. get Connection(); Prepared statement pst=con. prepareStatement (“select*from reg-users where uname=”+u name+”) ResultSet ms=pst. execute query(); Boolean b=ms. next(); If(b==true){ Status=”existed”; } Else{ Pst=con. prepared statement (“insert into reg-users values(????)”); Pst. string(1,uname); Pst. string(2,upwd); Pst. string(3,uemail); Pst. string(4,umobile); Pst. execute(); Status=”success”; } } Catch(Exception e){ Status=”failure”;

  1. print stack trace()

} Return statue; } }   User Dao Factory. Java Package com. soft; Public class user Dao Factory{ Static user Dao dao; Static{ Dao= new userDaoimpl(); } Public static user Dao get user Dao(){ Return dao; } }   Connection factory. Java Package com. soft Import Java.Sql.*; Public class Connection factory { Static Connection; Static{ Try{ Class.for Name(“oracle jdbc. oracle driver”); Con= driver manager. Get Connection(“jdbc. Oracle: thin:@local host:1521: “scoh”,”tiger”); } Catch (Exception c){

  1. print stack trace();

} } Public static Connection getConnection(){ Return con; } }   Web.xml SQN as Designing Java applications w.r.t the users notive Connection  is called as II8N

  • Java Technology is able to provide very good support for II8N due to the availability of UNICODE representation
  • To provide II8N Support in java applications, first , we have to represent all a group of local users
  • To represent a group local users, first, we have to classify all the users as per the following local parameters


  1. Language

It will be represented in the form of two lower case letters Ex: ”en”,” hi”,” te”,….  

  1. Country

It will be represented in the form at two upper case letters Ex;”us”,” IN”,”IT”,….  

  1. Operating system[system variant]

It will be represented in the form of three lower case letters Ex: ”win”,” lin”,” uni”,….

  • To represent a group of local users, java tech has provided a predefined class java.util. local
  • To create locale class object, we have to use the following constructors.

Public local(String lang) Public local(String lang, String country) Public local(String lang, String country String sys-var)   Ex Local I= New local(“en”); Local I= New local(“en”,” us”); Local I= New local(“en”,”s”,”wub”);                                

About Author


Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills .

Related Blogs

Write For Us