0

在我的 page1.xhtml

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

PageOneBean.class

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

page2.xhtml

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

PageTwoBean.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?

4

1 回答 1

3

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; }
}

试试看,看看效果如何。

于 2013-01-23T16:16:06.183 回答