开发者

Pass Data between ManagedBeans

开发者 https://www.devze.com 2023-02-08 14:26 出处:网络
I have one Class called Foo. And one ManagedBean called FooBean. In a page (Facelet) I get a new Foo info from user and insert it to DB. After first submission of data the print button will be enabled

I have one Class called Foo. And one ManagedBean called FooBean. In a page (Facelet) I get a new Foo info from user and insert it to DB. After first submission of data the print button will be enabled. Now I need the user click the print button and see the other page (Facelet) which is the print page with PrintFooBean. How can I pass the ID of the recently inserted Foo to the PrintFooBean and load it and display its items on the printing page?

What is the best way? And I prefer th开发者_开发知识库e user to see the print page in a new browser window/tab.


Pass it as request parameter.

<a href="print.jsf?id=#{foo.id}" target="_blank">print</a>

or unobtrusively progressively enhanced by JS window.open

<a href="print.jsf?id=#{foo.id}" target="_blank"
    onclick="window.open('print.jsf?id=#{foo.id}'); return false;">print</a>

Populate the print bean with the id.

@ManagedProperty(value="#{param.id}")
private Long id;

Preload the Foo data in same bean based on id.

@PostConstruct
public void init() {
    this.foo = fooDAO.find(id);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消