0

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).

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Satoshi
  • 41
  • 1
  • 1
  • 3
  • 1
    Possible duplicate of [commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated](https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value) – Kukeltje Aug 11 '19 at 00:19
  • See #1 in the duplicate – Kukeltje Aug 11 '19 at 00:19
  • @Kukeltje do you refer to "h:form is missing" part of the duplicate, or to the first answer? – Selaron Aug 12 '19 at 06:58
  • Is there a reason why you don't `` ? – Selaron Aug 12 '19 at 07:19
  • @selaron: the first link in the first bullit https://stackoverflow.com/questions/3681123/how-to-send-form-input-values-and-invoke-a-method-in-jsf-bean – Kukeltje Aug 12 '19 at 07:40
  • Check your import, @RequestScoped should be from this package: javax.faces.bean and not from this: javax.enterprise.context – theMahaloRecords Aug 12 '19 at 13:00

0 Answers0