Hi,
I created a jsp page and I want to use jQuery in order to autocomplete field on this:
<link rel="stylesheet" href="../JS/jquery-ui-1.11.4/jquery-ui.min.css">
<script src="../JS/jquery-1.11.3.min.js"></script>
<script src="../JS/jquery-ui-1.11.4/jquery-ui.min.js"></script>
<script>
$(document).ready(function(){
$("#tags").autocomplete({
source: './trfListeArticles.jsp',
minLength: 3,
select: function(event, ui) {
var article = ui.item.designation;
}
});
});
</script>
The fied is a simple HTML input field:
<td>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags"></input>
</div>
</td>
In order to do that, I created an extra jsp with egl jsfhandler behind:
Here is the JSP -->
<!DOCTYPE HTML>
<%@page import="egl.java.J2EELib_Lib"%>
<%@page import="jsfhandlers.demandeplan.myPageBeanInfo"%>
<%@page import="jsfhandlers.demandeplan.myPage"%>
<%-- jsf:pagecode language="EGL" location="/EGLSource/jsfhandlers/myPages/myPage.egl" --%><%-- /jsf:pagecode --%>
<%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@page
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<% response.setContentType("application/json");%>
<html>
<head>
<title>myPage</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<f:view>
<body>
<hx:scriptCollector id="scriptor" preRender="#{myPage._preRender}" postRender="#{myPage._postRender}">
<h:outputText value="#{myPage.tags}" binding="#{myPage.tags_Ref}"></h:outputText>
</hx:scriptCollector>
</body>
</f:view>
</html>
Here is the EGL -->
package jsfhandlers.myPages;
import com.ibm.egl.jsf.UIViewRoot;
import be.mycode.business.Lists;
import be.mycode.rec.items;
handler myPage type JSFHandler
{onConstructionFunction = onConstruction,
onPrerenderFunction = onPrerender,
view = "myPages/myPage.jsp",
viewRootVar = viewRoot,
cancelOnPageTransition = yes}
items items[];
tags string = "";
viewRoot UIViewRoot;
// Function Declarations
function onConstruction()
end
function onPrerender()
Lists.getItemsList();
createTagsJSONString();
end
//**************************************************************************************************
// createTagsJSONString => because jQuery autocomplete needs a JSON string and the f*#@!g EGL use
// one ofneeded names as reserved word (label)
//**************************************************************************************************
function createTagsJSONString()
jsonString string = "";
jsonTempString string = "";
count int = 0;
for (i int from 1 to items.getSize() by 1)
count = count +1;
jsonTempString += "{label: \"" + items[i].designation + "\", value: \"" + items[i].reference + "\"}";
if (jsonString == "")
jsonString += jsonTempString;
else
jsonString += "," + jsonTempString;
end
jsonTempString = "";
end
if (jsonString != "")
tags = "[" + jsonString + "]";
end
end
end
I have the following questions:
1- how do I get the value of input field in my jsfhandler? I need this in order to reduce my list and make the autocomplete
2- how do I get back the generated JSON array in order to use it in my jQuery code?
Thank you,
Olivier
OlivierLx