• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to access values in session from javascript

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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>

But how to do that in JSF?

Thanks
 
Priti Shah
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Does any one know how to do this ?

Thanks
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read this.
 
Priti Shah
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry but I really need some answer for that. I am also trying my self to get some work around.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the answer for your 1st question
http://www.exadel.com/tutorial/jsf/jsftutorial-validation.html

See this example, it shows validation like min to max etc

second question, i have to see abt it.
 
Priti Shah
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have already tried the first approach, I wanted to know which is standard way to do such thing.

Thanks
 
Ranch Hand
Posts: 686
Mac
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Priti Shah
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ulf,

I think I will do validation on both side.

Hi Ansar,

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.

Any clue any one??

Thanks
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, here is what I did and it worked....



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
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 "#{..."

Thanks anyways
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is v.common.alert.invalidalias?
 
Priti Shah
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'v.commom.alert.invalidalias' is my key in properties file

v.commom.alert.invalidalias=Invalid alias

Thanks
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What J2EE version are we working with here?
 
Priti Shah
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using

jdk1.4
Tomcat 5.5.9
Sun RI 1.1
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I have and it works fine.

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Priti Shah
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I do have <f:loadbundle> Here is the code

<f:loadBundle basename="/Message" var="message"/>
<f:subview id="controllerSettings">
<h:form id="controllerSettingsForm" onsubmit="return validateForm();">
<h utputText value="#{message['v.controller.id']}"/>
<h utputText value="#{controllerSettings.ID}"/>

....

<f:verbatim>

<script>

elements = document.forms['controllerSettings:controllerSettingsForm'].elements;

function validateForm()
{
alias=elements['controllerSettings:controllerSettingsForm:alias'];
if (alias == null || !validateAlias(alias.value)) {
alert("${requestScope.message['v.commom.alert.invalidalias']}");
alias.focus();
return false;
}
</script>
</f:verbatim>

</f:subview>

I am using 'message' bundle many times inside my subview its working fine but somehow its not working within javascript.

Thanks
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am at a loss. From what I can tell it should work. It works fine for me.
 
Priti Shah
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will try to figure it out.

Thanks gregg for helping out.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In order for the ${...} to work outside of a jstl tag i think you need to add web-app version in web.xml. I have:



Also, you could try replacing:
${requestScope.message['v.commom.alert.invalidalias']}
with:
<c:out value="${requestScope.message['v.commom.alert.invalidalias']}"/>
[ September 02, 2005: Message edited by: seb petterson ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic