Foros de discusión

Pass values while typing

Federico Basanese, modificado hace 8 años.

Pass values while typing

New Member Mensaje: 1 Fecha de incorporación: 27/04/16 Mensajes recientes
Hi

I have an <aui:input> textfield that needs to autocomplete using values found on the Database. I 've already developed the query as finder in the service.xml , now i need to pass what i'm typing in the textfield to the serveResource method. How can i do that?

Thank you
thumbnail
David H Nebinger, modificado hace 8 años.

RE: Pass values while typing

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
Welcome!

Usually when I'm looking for an example of how to do something, I use the portal source and find an example.

Also google can be a great tool, points to a long discussion here that may give you some ideas of how to proceed.
thumbnail
Andrew Jardine, modificado hace 8 años.

RE: Pass values while typing

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
There is also a lot of content of aui autocomplete -- check out this thread for example: https://web.liferay.com/community/forums/-/message_boards/message/32046351
thumbnail
David H Nebinger, modificado hace 8 años.

RE: Pass values while typing

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
Hey, Andrew, that's actually the link I posted emoticon
thumbnail
Andrew Jardine, modificado hace 8 años.

RE: Pass values while typing

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
LOL -- burn. Here -- let me try a different one emoticon

https://web.liferay.com/web/meera.success/blog/-/blogs/liferay-auto-complete-list-with-ajax
vikas ch, modificado hace 7 años.

RE: Pass values while typing

New Member Mensajes: 18 Fecha de incorporación: 17/07/14 Mensajes recientes
Hello Fed,

I would suggest you can either use AUI or JQuery for this requirement.First you need to have a on keyup event and call an resource URL (ie: AJAX ) and pass the data from input field to the ajax and call your finder return list or object depending upon you requirement loop that list and form an JSONObject and put that JSONObject inside an JSONArray and use PrintWriter to return it back to the AJAX call and use either JQuery autocomplete or AUI and pass the corresponding JSONArray passing the input id the autocomplete list would render

Please share your code if you need further help.
thumbnail
Andrew Jardine, modificado hace 7 años.

RE: Pass values while typing

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
Hey Vikas,

I thought the PrintWriter class was used for format responses? I've never used it in a serveResource method before -- can you show me an example of how you use it? Normally I just do something like this

    @Override
    public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws IOException, PortletException {
       
        String result = StringPool.BLANK;
    
		// execute logic to get your list of values and set "string" to result
       
        resourceResponse.getPortletOutputStream().write(result.getBytes());
        resourceResponse.getPortletOutputStream().flush();
    }
vikas ch, modificado hace 7 años.

RE: Pass values while typing

New Member Mensajes: 18 Fecha de incorporación: 17/07/14 Mensajes recientes
Hey Andrew, I generally use it like the below mentioned code btw you have showed me your code thanks learnt a new way emoticon


               PrintWriter writer = null;
		try {
			writer = resourceResponse.getWriter();
			writer.println(jsonArray);
		} catch (IOException e) {
			_log.error(e);
		}