0

I am trying to implement autocomplete feature of jQuery in a JSF (.jsp) file. Things are working fine but I am unable to fetch a list from my managed bean into a variable in the script. Please help me out.

JSP code:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
    $(function() {
        var availableTags = "#{aCTestBean.placesList}";
        $( "#tags" ).autocomplete({
            source: availableTags
        });
    });
</script>
</head>
<body>
<f:view>
<label for="tags">Symbol: </label>
<h:form id="watchListForm">
<h:inputText id="tags" />
</h:form> 
</f:view>
</body>
</html>

ERROR: HTTP Status 500 - /AutoComplete.jsp (line: 14, column: 24) #{...} is not allowed in template text

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
CMStrider
  • 9
  • 3
  • The question is how to access the List from managed bean. Which not answered anywhere. – CMStrider Jun 02 '16 at 13:43
  • 1
    as far as I can see, the question (at least the underlying problem) **is** answered in the duplicate. You can put **any** string from a bean in the page anywhere via an `h:outputText value="#{...}`, **not** via a just #{...} – Kukeltje Jun 03 '16 at 10:03
  • 1
    You don't exactly "access" list from bean in JS. You just write JSF code in such way that it generates exactly the desired HTML output, which JS code just happens to be part of. Your initial attempt was logically perfectly fine. Only, you're using the since 2009 deprecated JSP view technology instead of its successor Facelets. In JSP, `#{...}` in template text is not supported, exactly as indicated by the error message you got. The cause and correct approach to print `#{...}` in JSP is answered in the duplicate. Do note that you should not stare at question in the duplicate, but at the answer. – BalusC Jun 03 '16 at 11:40

0 Answers0