I want to know how to pass parameter from JSF page to backing bean.
I used the examples below as reference.
https://www.mkyong.com/jsf2/4-ways-to-pass-parameter-from-jsf-page-to-backing-bean/
1. Method expression
But my code doesn't work properly.
①Sample.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>Sample</title>
</h:head>
<h:body>
<h:form prependId="false">
<h:inputText id="input"/>
<h:commandButton action="#{scriptNextBb.next(input)}" value="Screen Transition"/>
</h:form>
</h:body>
</html>
②ScriptNextBb.java
@Named
@RequestScoped
public class ScriptNextBb {
private String tmpValue;
public String getTmpValue() {
return tmpValue;
}
public void setTmpValue(String tmpValue) {
this.tmpValue = tmpValue;
}
public String next(String input) {
this.tmpValue = input;
return "other.xhtml";
}
}
③other.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"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>JavaScript</title>
</h:head>
<h:body>
<h:form prependId="false">
<h:outputText id="outputValue" value="#{scriptNextBb.tmpValue}" />
<br/>
</h:form>
</h:body>
</html>
I want to display setting value at Sample.xhtml on other.xhtml. It can make screen transition, but it cannnot pass the parameter(input on Sample.xhtml).