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

被折叠的 条评论
为什么被折叠?



