This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
My first question is should I use javascript or JSF for minor validations like range check? Is it advisable to go to server for such validations? I am also using 'immidiate=true' when I do such validations. But I just wanted to know the preferrable way.
Second question is when I use javascript in JSF page if I want to use some localized alert messages from my session how can I do that? If it is JSP i can do something like this <script> alert('<%=userSession.getAttribute('invalidAliasAlert')%>') </script>
I do say you need to use both approach. 1. Use java script for client side validation. 2. Also use JSF validation, it works in the cases where browser doesn't support javascript.
ansar basha
Ranch Hand
Joined: Aug 02, 2005
Posts: 34
posted
0
Hi, I doubt if can get a session from javascript, as javascript is at the client side and the session at the server which might not have been created when the page is being rendered or while the javascript is under execution. (I'm too interested to know if there is any work around or any solution for this scenerio).
Thanks Ansar
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
This depends on whether you can require JS on the client, and -if you can require it- whether you turn away users that have it turned off. If the answer is yes to both, go with JavaScript. Of course, if this is a public site where you can't trust the users, you need to check on the server as well, because people will tamper with URLs and request parameters. But it's good practice to check on the client as well, so you can give faster feedback to the user.
I am only setting some alert messages from session which is possible i can do that easily in JSP because I can use JSP and JAvascript together but I donot know how to do that in JSF.
I have set of localized alert messages in property file. I am loading this message bundle using <f:loadBundle> but now I want to use some of the messages from this bundle in my javascript.
I put that in an on load in the body tag just to test. Worked. I'm curious if you even tried anything or if you have been waiting around for someone to give you the answer?
Priti Shah
Ranch Hand
Joined: May 10, 2005
Posts: 43
posted
0
Hi Gregg,
I have already tried that but it is not working. Here is what i did.
function validateForm() { alias=elements['controllerSettings:controllerSettingsForm:alias']; if (alias == null || !validateAlias(alias.value)) { alert("#{requestScope.message['v.common.alert.invalidalias']}"); alias.focus(); return false; } }
its alerting the whole string '#{requestScope.message['v.common.alert.invalidalias']}' I also tried it with '${...' rather than "#{..."
I might mention that you probably need to make sure you have the f:loadBundle tag before you javascript and make sure it is all enclosed in the f:view tag.