I am trying to pass the values between xhtml pages using the Request Scoped JSF Managed Bean, GendersManager.java in jsf as follows:
Page Flow:
index.xhtml ---hyper link---> GendersInsertCreateKeyin.xhtml ---Confirm---> GendersInsertCreateConfirm.xhtml ---Commit---> GendersInsertCreateCommitted.xhtml ---Committed---> index.xhtml
Issue:
The field vaues are shown in "GendersInsertCreateConfirm.xhtml" (ie.during 1st navigation) but field values become null/empty string in GendersInsertCreateCommitted.xhtml (ie. during 2nd navigation) during the page flows.
Update:
a) Converting the user interfaces, h:outputText to h:inputText in GendersInsertCreateConfirm.xhtml retains field values during the page flows.
b) After Converting the user interfaces, h:outputText to h:inputText and setting its parameter readonly=true, field values become null/empty string during the page flows.
c) tried to set the values to the member variables of jsf managed bean,GendersManager with the following javascript code from GendersInsertCreateConfirm.xhtml:
<h:commandButton id="insertCreateConfirmBtnUi" value="Genders Insert Create Confirm" action="#{gendersManager.insertCreateConfirm}"/></td>
<f:verbatim>
<script type="text/js" language="javascript">
var genderSlNoUiText = document.getElementByid("genderSlNoUi").getValue();
</script>
<f:setPropertyActionListener target="#{gendersManager.genderSlNo}" value=genderSlNoUiText/>
<f:verbatim>
</h:commandButton>
, but throws error that value should have quotes
Please guide me in passing values between xhtml pages using the jsf managed bean.
References:
faces-config.xml:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<navigation-rule>
<navigation-case>
<from-action>#{gendersManager.insertCreateKeyin}</from-action>
<from-outcome>Confirm</from-outcome>
<to-view-id>GendersInsertCreateConfirm.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>GendersInsertCreateConfirm.xhtml</from-view-id>
<navigation-case>
<from-action>#{gendersManager.insertCreateConfirm}</from-action>
<from-outcome>Commit</from-outcome>
<to-view-id>GendersInsertCreateCommitted.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>GendersInsertCreateCommitted.xhtml</from-view-id>
<navigation-case>
<from-action>#{gendersManager.insertCreateCommitted}</from-action>
<from-outcome>Committed</from-outcome>
<to-view-id>index.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
JSF Managed Bean:
GendersManager.java:
package com.practice.web;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ManagedBean;
@ManagedBean
@RequestScoped
public class GendersManager {
private Long genderSlNo;
public String insertCreateKeyin(){
Genders genders = new Genders ();
genders.setGenderSlNo(getGenderSlNo());
return "Confirm";
}
public String insertCreateConfirm(){
Genders genders = new Genders ();
genders.setGenderSlNo(getGenderSlNo());
return "Commit";
}
public String insertCreateCommitted(){
Genders genders = new Genders ();
genders.setGenderSlNo(getGenderSlNo());
return "Committed";
}
public Long getGenderSlNo() {
return genderSlNo;
}
public void setGenderSlNo(Long genderSlNo) {
this.genderSlNo = genderSlNo;
}
}
XHTML Pages:
GendersInsertCreateKeyin.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Genders Insert Create Keyin</title>
</h:head>
<h:body>
<h:form>
<table border="1">
<tr>
<td><h:outputLabel for="genderSlNoUi" id="genderSlNoLbl" value="Gender Sl No"/></td>
<td><h:inputText id="genderSlNoUi" value="#{gendersManager.genderSlNo}"/></td>
</tr>
<tr>
<td align="right"><h:commandButton id="insertCreateKeyinBtnUi" value="Insert Genders" action="#{gendersManager.insertCreateKeyin}"/></td>
</tr>
</table>
</h:form>
</h:body>
</html>
GendersInsertCreateConfirm.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Genders Insert Create Confirm</title>
</h:head>
<h:body>
<h:form>
<table border="1">
<tr>
<td><h:outputLabel for="genderSlNoUi" id="genderSlNoLbl" value="Gender Sl No"/></td>
<td><h:outputText id="genderSlNoUi" value="#{gendersManager.genderSlNo}"/></td>
</tr>
<tr>
<td align="right"><h:commandButton id="insertCreateConfirmBtnUi" value="Genders Insert Create Confirm" action="#{gendersManager.insertCreateConfirm}"/></td>
</tr>
</table>
</h:form>
</h:body>
</html>
GendersInsertCreateCommitted.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Genders Insert Create Committed</title>
</h:head>
<h:body>
<h:form>
<table border="1">
<tr>
<td><h:outputLabel for="genderSlNoUi" id="genderSlNoLbl" value="Gender Sl No"/></td>
<td><h:outputText id="genderSlNoUi" value="#{gendersManager.genderSlNo}"/></td>
</tr>
<tr>
</tr>
</table>
</h:form>
</h:body>
</html>