我试图使用jsf中的Request Scoped JSF Managed Bean GendersManager.java在xhtml页面之间传递值,如下所示:
页面流:
index.xhtml ---超级链接---> GendersInsertCreateKeyin.xhtml --- Confirm ---> GendersInsertCreateConfirm.xhtml --- Commit ---> GendersInsertCreateCommitted.xhtml --- Committed --->索引。 xhtml
问题:
字段值显示在“ GendersInsertCreateConfirm.xhtml”中(即在第一次导航期间) ,但是字段值在GendersInsertCreateCommitted.xhtml中(即在第二次导航期间)变为空/空字符串。
更新:
a)将GendersInsertCreateConfirm.xhtml中的用户界面 h:outputText 转换为 h:inputText ,以在页面流期间保留字段值。
b)转换用户界面后,将 h:outputText 更改为 h:inputText 并设置其参数 readonly = true < / strong>,则页面流期间字段值将变为空/空字符串。
c)尝试使用GendersInsertCreateConfirm.xhtml中的以下javascript代码将值设置为jsf受管beanGendersManager的成员变量:
<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>
,但引发错误,该值应带有引号
请指导我使用jsf托管bean在xhtml页面之间传递值。
参考:
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托管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页面:
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>