Summary on 20080716: close the current page through backend bean method

本文介绍了一个在JSF(不使用Ajax的情况下)处理弹窗提交数据后关闭窗口并刷新主页的方法。主要通过后端Bean进行数据保存,并利用JavaScript实现页面的关闭与刷新。文章提供了一段具体的实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

There is such process that: in home page, click some link/button to open one pop up child window, in the window, input/edit/add some content and click  'submit' button to submit the change, if the change is saved successfully, close the child window and refresh the home page if necessary.

For this case, in JSP page, it can be handled by ajax easily, however, in normal jsf(with out ajax), it's quite one tricky and hard-to-resolve problem. The dificulty is that: save is done by backend bean, while close and refresh is done by JavaScript, backend bean can't close/refresh page directly.

To achive this, the only way is that: in backend bean, return some state/value to frontend. And fortunately that we can do this by FacesContext. Refer the following code:

//Get the current context;
FacesContext context = FacesContext.getCurrentInstance();
//Get servlet response;
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
PrintWriter writer = response.getWriter();

writer.write("");

the first script code will refresh the home page
the second script code will close the child page;

The related link:
1. web page for summary of js code that commonly used:
http://www.utf.com.cn/article/s1024
2. one simple sample for the usage:
http://www.itzhe.cn/article/20080116/55203.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值