最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - calling alert box from code behind java in jsf - Stack Overflow

programmeradmin3浏览0评论

I have a requirement to update the properties file based upon the input provided by the user in the jsf page. After updating the file, user session should be cleared and alert box should say 'setting has been updated' and the page should navigate to the login page.

I don't know how to call a alert box from java code. I found this to be possible in asp. I searched google, but didn't get any possible solution

How can I make this possible?

All possible solutions are wele. Thanks in advance.

UPDATE @balusc thanks for your pointer. I am using JSF RI 1.2 and Richfaces 3.3.2

I have a requirement to update the properties file based upon the input provided by the user in the jsf page. After updating the file, user session should be cleared and alert box should say 'setting has been updated' and the page should navigate to the login page.

I don't know how to call a alert box from java code. I found this to be possible in asp. I searched google, but didn't get any possible solution

How can I make this possible?

All possible solutions are wele. Thanks in advance.

UPDATE @balusc thanks for your pointer. I am using JSF RI 1.2 and Richfaces 3.3.2

Share Improve this question edited Sep 15, 2010 at 11:59 mvg asked Sep 15, 2010 at 6:19 mvgmvg 1,5844 gold badges38 silver badges63 bronze badges 4
  • As per your question history, you're using RichFaces. Are you open to RichFaces targeted answers? In future JSF related questions, you should mention the JSF impl/version and any JSF ponent libraries used. – BalusC Commented Sep 15, 2010 at 11:25
  • I am open to Richfaces targeted answer and also others. – mvg Commented Sep 15, 2010 at 12:30
  • Ok, keep in mind that mixing various "major" ponent libraries like RichFaces + IceFaces + PrimeFaces + OpenFaces + etc isn't always a good idea. The one might collide with the other. RichFaces must have this kind of functionality, but since I don't use it, I can't tell from top of head. – BalusC Commented Sep 17, 2010 at 11:23
  • Oh! Thanks for the pointer. I first started my search with Richfaces. Since I was unable to find it, I thought other libraries would be helpful. Ok I will focus with Richfaces based solution. – mvg Commented Sep 17, 2010 at 12:06
Add a ment  | 

5 Answers 5

Reset to default 2

I managed to solve this problem by using 'onplete' attribute in a4j mandbutton. 'onplete' attribute is used to call javascript function after the server side process is pleted.

After pleting the server side process, I called a javascript function which called an alert box and using

document.location="../login.jsf";

I navigated to the login page.

Any suggestions regarding this solution is wele.

Thanks every one for the answers and ments.

You can use PrimeFaces dialog.

PrimeFaces is an open source of ponents that enhance GUI and development.

The dialog has action listener on buttons, so when the user approves reading the dialog, you can redirect him to any page the you need.

For displaying alert-box you can use below code in your bean :

JavascriptContext.addJavascriptCall(facesContext, "alert('Setting has been updated');");

Clearing the session :

HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
session.invalidate();

Use the rich:modalPanel with the showWhenRendered attribute set to a boolean property of your managed bean. Then just reRender the parent of the modal panel after your call.

List of attributes for modal panel

Eg:

<a4j:outputPanel id="modalParent">
   <rich:modalPanel showWhenRendered="#{bean.someBooleanValue}">

   </rich:modalPanel>
</a4j:outputPanel>

And your button/link would have reRender="modalParent"

Something like this

<%

ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
HttpSession session = (HttpSession)ectx.getSession(false);
session.invalidate(); 
%>
<script type="text/javascript">
alert('Setting has been updated');
location.replace('/index.jsp');
</script>
发布评论

评论列表(0)

  1. 暂无评论