1

I am trying to build sample JSF 2 based autocomplete form. I am using primefaces 3.0.M2, JSF 2.1.2 libraries and JBoss 6.

I am using autoComplete component of primefaces but its not working. I am not getting any autocomplete text when I type in input text box.

I can see only following warning in JBoss console window :

19:40:56,874 WARN  [Parameters] Parameters: Invalid chunk ignored.

My xhtml file looks like following :

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
       <title>sample auto completer</title> 
    </h:head>
    <h:body>
        <p:messages id="messages" />
        <p:autoComplete id="AutoCompleter" 
            value="#{myBean.text}" 
            completeMethod="#{myBean.complete}"
            onSelectUpdate="messages"/>
    </h:body>
</html>

and java bean code is as follows :

package com.shekhar.jsf;

import java.util.ArrayList;
import java.util.List;

public class Bean {

    private String text;

    public List<String> complete(String val) {
        List<String> lst = new ArrayList<String>();

        for (int i = 0; i < 10; i++) {
            lst.add(val + i);
        }
        return lst;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getText() {
        return text;
    }
}

and my faces-config file contains following code :

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">
    <managed-bean>
        <managed-bean-name>myBean</managed-bean-name>
        <managed-bean-class>com.shekhar.jsf.Bean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
</faces-config>

I dont understand which thing I am missing. Please help !!!

Shekhar
  • 11,438
  • 36
  • 130
  • 186
  • What happens when you put logging in the complete method? What happens when you change `request` to `view`? – maple_shaft Sep 02 '11 at 16:17
  • @maple_shaft, thanks for clues. I will experiment with it n get back. – Shekhar Sep 02 '11 at 16:43
  • @maple_shaft, i tried changing scope. it didnt worked. ill try to put logging in complete method. – Shekhar Sep 02 '11 at 16:59
  • @maple_shaft, forgive me for my lack of knowledge. I do not how to log in java based web app. I tried System.out.println() and used Java's built in Logger class. but nothing came on JBoss console. Can you please provide some pointers about how to write logs? any idea? – Shekhar Sep 02 '11 at 17:46
  • 1
    You should see output in the console or in the log files for `System.out.println()`. If you did not then that means the `complete` method is not getting executed. It might be because you need to wrap your autoComplete and messages components in an ``. – maple_shaft Sep 02 '11 at 17:58
  • Your doubt about logging makes me think that you are new to Java as a programming language. You should learn to master the basics of Java before trying to develop a JSF application. JSF is very complex. Good luck. – maple_shaft Sep 02 '11 at 18:00
  • @maple_shaft, it worked :D thanks a lot !!!!! post it as an answer. Ill accept it right away – Shekhar Sep 02 '11 at 18:02
  • @maple_shaft, yes you are right. I am relatively new to JEE world. I am from .net background but my new task is to build this JSF based app and connect it to my main .net based app. Dont know whether its good or bad – Shekhar Sep 02 '11 at 18:04
  • Note that it's called `prependId="false"` and note that it's **not** required to get it to work. Just a `` is perfectly fine. The `` generates namely a HTML input element which is required to be placed inside a HTML form. Note that the JBoss warning which you mentioned in the title is totally unrelated to this problem. – BalusC Sep 02 '11 at 21:53
  • @Balusc, surprisingly both prependToId and prependId also works. – Shekhar Sep 03 '11 at 04:13

1 Answers1

3

From the comment above as the accepted answer

You should see output in the console or in the log files for System.out.println(). If you did not then that means the complete method is not getting executed. It might be because you need to wrap your autoComplete and messages components in an <h:form prependId="false">.

Glad to see it worked for you. It may seem strange but there are a LOT of similarities between JSF and ASP.NET. I used to be an ASP.NET developer and I picked up JSF fairly easy. Good luck!

Community
  • 1
  • 1
maple_shaft
  • 10,435
  • 6
  • 46
  • 74