如何将参数从一个页面传递到另一个页面



在我的页面1中.xhtml

<h:form>
    <h:inputText value="#{page_one.name}" />
    <h:commandButton action="#{page_one.onSubmit}" value="Submit" />
</h:form>

页一豆.class

@ManagedBean(name="page_one")
@RequestScoped
public class PageOneBean {
    private String name;
    public String onSubmit(){
    return "/page2.xhtml";
    }
}

页2.xhtml

<h:form>
    <h:commandButton action="#{page_two.onSubmit}" value="Submit" />
</h:form>

页二豆.class

@ManagedBean(name = "page_two")
@RequestScoped
public class PageTwoBean {
private String name;
public String onSubmit() {
    System.out.println("name" + name);
    return null;
}
}

当我点击page_two.onSubmit按钮时,如何在PageTwoBean中获取 pageOneBean.name?

page2.xhtml

<h:form>
    <f:metadata>
         <f:viewParam name="name" value="#{page_two.name}"/>            
    </f:metadata>
    <h:commandButton action="#{page_two.onSubmit}" value="Submit" />
</h:form>

豆1:

public class PageOneBean {
private String name;
public String onSubmit(){
    return "/page2.xhtml?name=something";
}
public void setName(String name){ this.name = name;}
public String getName(){ return name; }
}

试试看,看看效果如何。

相关内容

  • 没有找到相关文章