JSTL EL expressions in JavaScript

I'm new to JSTL. I'm using JSTL version 1.0 on Tomcat 4.1.37.
I've created a servlet that generates a list of items and sets them to the attribute of the request. I'm using the following code to populate a drop down menu using this list.
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<select id="myMenu" name="myMenu" onchange="foo();">
     <option value="">Select an item</option>
     <c:forEach var="someBean" items="${allBeans}">
          <option value="${someBean.id}">
               <c:out value="${someBean.name}" />
          </option>
     </c:forEach>
</select>When the page loads, I do see the proper list of names in the drop down menu as I would expect. So the values of someBean.name are being rendered properly.
When the user selects an item in the menu, the foo method executes in javascript. It looks like this
function foo() {
     var menu = document.getElementById("myMenu");
     var index = menu.selectedIndex;
     var id = menu[index].value;
     alert( "index = " + index + " id = " + id );
}I was assuming I would see the id values for the selected name. But I don't. Instead I see ..
index = 5 id = ${someBean.id}Can someone explain why? In other words I find that the EL expression pertaining to the name attribute of the bean is being properly evaluated, but the id EL expression is not being evaluated. Thanks in advance for any help.
Edited by: nantucket on Jun 23, 2008 10:57 AM

hi modify your code like this,
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<select id="myMenu" name="myMenu" onchange="foo();">
<option value="">Select an item</option>
<c:forEach var="someBean" items="${allBeans}">
{color:#339966}_*<option value="<c:out value='${someBean.id}'}">*_
{color}<c:out value="${someBean.name}" />
</option>
</c:forEach>
</select>
then you will get the expected result...
This is because normal HTML elements doesn't have capablity to render EL...

Similar Messages

  • How can I add a watch to a variable or expression during javascript debugging

    Since the new update to safari 6 I am looking for a way to add a watch to a variable or expression during javascript debugging. I don't want to go to the console line every time to type in the separate variables and expressions over and over again. Also hovering over a variable doesn't show the value.

    I couldn't find the answer either (I submitted an enhancement request to http://www.apple.com/feedback/safari.html in hopes that it will get added back in), but downloading a nightly build of webkit (http://nightly.webkit.org) will give you an alternative version of Safari that still uses the version 5 inspector, which to me is preferable anyway. 

  • Faces expression in Javascript?  Flash/Flex and Faces Session Variables

    Does anyone know how to add a faces expression in Javascript?
    I basically want to pass a Faces Variable to Flash/Flex. The best way to do that would be in Javascript.
    I thought it would be fairly easy. Something like:
                        <webuijsf:script binding="#{Page1.script1}" id="script1" >
                            function foo() {
                              var text = #{Page1.textField1.text};
                              alert(text);
                        </webuijsf:script>Or something like that, and hope that the Faces expression will be expanded before sent to the browser. Unfortunately, that's not happening:
    SEVERE: Servlet.service() for servlet Faces Servlet threw exception
    org.apache.jasper.JasperException: /Page1.jsp(16,38) #{..} is not allowed in template textWhen ran in the HTTP context of NetBeans.
    Edited by: Neelixx on Apr 5, 2008 4:42 PM - Clarified using more javascript example

    Have a look at Shared Objects, I think these are the sort of
    thing you are after. I think the "Specifying a path" subtopic
    should be particularly relevant for sharing the variables/objects
    between the two swf files.
    Livedocs
    - Shared Objects

  • Regular expressing in javascript

    Hi All,
    Does anybody know if there's a way to find out how many words
    appear in a string using regular expression in javascript? For
    example, I have the following code that pops a "Not OK" alert
    whenever str contains "it it it information technology", and I need
    to find out how many times the word "it" exists in the string using
    regular expression.
    <html>
    <body>
    <script type="text/javascript">
    var str = "it it it information technology";
    var reg = /^(\bin\b|\bit\b|\bof\b)(?!
    (\bin\b|\bit\b|\bof\b))/;
    reg = new RegExp(reg);
    var result = str.match(reg);
    document.write(result);
    if (result) {
    alert("OK");
    } else {
    alert("Not OK");
    </script>
    </body>
    </html>
    Thanks very much in advance!

    Refer
    this
    tutorial.

  • How to pass values from JSTL to JSP or Javascript ?

    Hi All,
    Is it possible to share or use the variables which are declared are used by JSTL in JSP expression or scriplet code and in Java Script.
    Example:
    This Works:
    <fmt:set var="test" value="JSTL" />
    <fmt:out value="${test}" />
    But, this gives error:
    <% out.println(test) %>
    And passing the value of variable 'test' to Java Script code also gives error.
    How to use JSTL variables in JSP and in Javascript ?
    Yours,
    Sankar.B

    <% out.println(pageContext.getAttribute("test") %>
    If your tags use a different scope then you'll nee to access them accordingly e.g this will work
    <c:set var="test" value="JSTL" scope="session" />
    <c:out value="${test}" />
    <% out.println(session.getAttribute("test")); %>

  • Regular expressions in JavaScript for CP5?

    I'm having trouble implementing a regular expression from within the JavaScript window. First of all, does CP 5 support regular expressions?

    On slide 1 I have a Text Entry Box, (called TheTeb) with a Submit button. TheTeb has variable associated with it called TypedText.
    In the box, the user may type anything.
    On slide 2 there is a caption.
    The caption must show the text that the user typed  into TheTeb but filtered so that only the letters, numbers, and spaces can be shown.
    For example,
    if the user types:           123 & abc /DEF
    the caption will show: 123 abc DEF
    This requirement is represents the behavior of an application that I am simulating, so I don't want to change the interaction in any way.
    My strategy is to use 2 different variables, one for the text entry box (TypedText), the other for the caption (FilteredText). I can add JavaScript to the On Enter event of slide 2. The script will Get the TypedText, pass the TypedText to FilteredText, and run a regular expression somewhere so the filtered text displays on slide 2.
    Here's the script so far:
    var objCP = document.Captivate;    
    var ScriptTypedText = objCP.cpEIGetValue('TypedText');
    function ReturnValue(){    
      objCP.cpEISetValue('FilteredText', ScriptTypedText);
    ReturnValue();
    The script works as is. The user types text on slide 1 (as TypedText), presses Enter and the text shows up on slide 2 (as $$FilteredText$$). Obviously, the trouble is, I don't know where to add my regular expression into the JavaScript so the text actually gets filtered. Do I make a new function?
    By the way, a sort of pseudocode syntax for the expression would be:
    FilteredText = TypedText.replace(/ /g,"");

  • HELP: Possible to nest %=expression% within javascript code?

    Hi, I'm working on an application where I need to use dynamic JSP variables in javascript, as shown below
    onclick="jsFunc(this.form, '<=myClass.getSpecialString()%>');">(Te code is originally within a button tag)
    This will not work, any ideas why? If I alert the second javascript parameter in the jsFunc javascript function, I'll get <=myClass.getSpecialString%> written out in the message box instead of the value returned by myClass.getSpecialString().
    This means that the parser apparently does not first evaluate the JSP <%%> tags as one would expect...
    How can I provide JSP values in a javascript function as shown??
    Very thanful for any answers on this one!!
    Best Regards/
    AC

    As you see, there is some struts involved, however,it
    does not affect the main problem here...
    <html:button property="page"styleClass="form"
    onclick="jsFunc('<%=myClass.getString()%>');">
    <bean:message
    ean:message
    key="regularcustomer.ord.bulkorder.addBtn"/>
    </html:button>
    <SCRIPT LANGUAGE="JavaScript">
    function sFunc(test){
    alert(test);
    </SCRIPT>
    The problem is that the onclick attribute of the
    button tag can support run time JSP expressions, ONLY
    if the entire attribute is a JSP expression. If you
    just had this...
    onclick="<%=myClass.getString()%>", it would work.You would have to wrap the jsFunc() call inside of a Java String, along with the myClass.getString() String, for it to work correctly.

  • How to open Outlook express from Javascript

    Hi,
    The requirement is to open the outlook client when clicked on some button in the web application. Also I need to pre populate the email with body of approx 3000+ characters.
    Since the characters is huge i cannot use mailto:. So how to do this?

    I tried this
    var theApp = new ActiveXObject("Outlook.Application");
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var subject;
    var msg = "type Email message here.";
    var theMailItem = theApp.CreateItem(0);
    theMailItem.to = "[email protected]";
    theMailItem.HTMLBody = (olook);
    theMailItem.Subject = (subject);
    theMailItem.display();
    once the java script executes in IE, it tries to open outlook but, I am not seeing any new email page opening

  • Regular expressions in ActionScript??

    I have been looking at the Adobe publication Programming Action Script (pdf) and it
    specifies ECMA-262 3rd edition specification. But the specification don't seem to
    state exactly what type of regular expression engine and version is used.
    Is it POSIX, or PERL compatible regular expressions (or both)?
    I have read and used the classic O'Reilly text Mastering Regular Expressions
    and coded regular expressions in javascript/php/etc (anywhere regular expressions
    could be use, Apache configuration file, other server config files, etc etc etc)
    There is a difference in the type of engine used, where as performance is
    concerned, as well as the range of syntax valid in a particular implementation.
    Thank You
    JK

    http://www.regular-expressions.info/javascript.html

  • How to write this logic  in EL expression ? (new line characters in string

    iam using JSTL EL expression in my JSP.
    iam printing a string in JSP as ${vobject.rmessage} where rmessage is a string .
    problem is i want to identify the newline characters in the above rmessage string and print the line break <br> in html where ever the new lines character is present in the string.
    How should i write an EL expression for the above.
    Can anyone please guide me on writing EL expression for the above problem?

    Several ways. You can wrap the output with <pre> tags. You can apply CSS property white-space: pre; to the element. You can use String#replaceAll() in the Java code to replace each occurence of "\r\n" by "<br>".

  • Validate form entries: does java support regular expressions?

    i want to validate form entries, does java support regular express like javascript?

    Just recently in 1.4 regex was finally introduced :)
    Take a look at http://developer.java.sun.com/developer/technicalArticles/releases/1.4regex/

  • JSF (richfaces) component + JSTL forEach

    Hi,
    I'm using MyFaces implementation of JSF 1.2, together with RichFaces components, and inside a <rich:dataTable>'s <rich:column> I want to iterate over a Set, which is a property of the variable of the dataTable. Something like
    <rich:dataTable var="myvar">
    <rich:column>
       <c:forEach var="innerVar" values="${myVar.mySet}"
           ${innerVar}
       </c:forEach>
    </rich:column
    </rich:dataTable>But it doesn't work. myVar seems to be empty for c:forEach. The odd thing is that if I place the following code inside the <rich:column>
    <c:if test="${empty myVar">
            ${myVar.class.name}
    </c:if>the name of the class is outputted. I also tried # isntead of $, with no success.
    I tried iterating over a list in a declared backing bean, and it worked fine. So the question would go like this - how do I make this variable accessible for jstl tags' expressions.
    Edited by: Glammy on Mar 2, 2009 9:36 AM

    and why wouldn't you use a getter which does the transformation from Set to List just for the UI layer:
    public List<InnerVar> getInnerVarList() {
       // transform Set into a List<> here
    } and then in the UI:
    <rich:column>
       <ui:repeat var="innerVar" values="#{innerVarList}"
           #{innerVar}
       </ui:repeat>
    </rich:column>

  • Expression language to determine Mobile Device in spaces

    Sr#-3-6785317771
    Ver- PS5
    Customer wanted to switch our navigation on webcenter spaces based on the device.
    We tried to use the below EL, but it cannot differentiate between tablets and phones.
    #{requestContext.agent.platformName
    Eg: Android tablet and phone, both return the output as android.
    We are looking for an EL, that can determine phone, tablets.
    Customer just wanted to know to know the EL to determine the device.
    Jsut like the one we sent you in the past,
    #{requestContext.agent.platformName}
    This tells us the device platform, but we are looking for Device recognition.
    Any clue please?

    Try with JSTL EL Expression directly:
    <c:set var="browser" value="${header['User-Agent']}" scope="session"/>Regards.

  • Help in JavaScript Validation!!!

    I have written a function for testing alphabetic fields, using regular expressions in javascript. Can anybody help me out.
    function validateAlphabet(alpha, field) {
         var alphaTest = /^[^a-zA-Z ]$/;
         if(alpha.search(alphaTest) != -1)
              alert("Numeric values and special characters not allowed in " + field + " field");
    }

    Java is not JavaScript. Although they share 4 letters, they are entirely different beasts with only superfluous similarities in the syntax.
    So you probably would get more help in a JavaScript forum.
    Additionally you didn't even state what your problem is, so even if someone was willing to help you here they couldn't.

  • JSP/Expression Language in Web AS 6.40

    Hello
    We are trying to port a Servlet/JSP Application from Tomcat to SAP Web AS. It's based on Spring/Hibernate and we are heavily using JSP with Expression Language and JSTL.
    The first problem i had with the "c:forEach" tag, was solved by using the "core" taglib instead of the "core_el" taglib (which means JSTL without Expression Language seems to work)
    As i found out SAP Web AS 6.40 complies to the J2EE 1.3 Standard. Therefore it supports JSP 1.2 and not JSP 2.0 with Expression Language EL.
    Despite not supporting the current JSP Standard, is there any possibility to get JSP Pages with Expression Language running on Web AS 6.40?
    If no, is it planned to support JSP 2.0 in future versions of Web AS and when is it scheduled?
    Thanks for answers
    Sigmar

    Sigmar,
    there is already released light version of J2EE engine including J2EE1.4...You can have a look at the begin page of the SDN, or directly download it by link :
    https://www.sdn.sap.com/irj/sdn/downloaditem?rid=/webcontent/uuid/64919927-0b01-0010-e9bf-d1570518023d [original link is broken]
    As bonus it includes Java EE 5 preview
    Regards
    Bojidar

Maybe you are looking for