Hi there,

Please help me out with this one:

I try creating an autocomplete field that holds just strings. The field has a 
model that contains values inserted into this field in the past (the model is 
generated from values in a database). The field should accept any values from 
this history but also accept new ones. So for example the history says you 
entered "one", "two", "three" and "four" in the past. Now you can select one of 
these values or enter "five" and the submit will take "five" to the database 
and that's it.

The problem that occures is: The Autocomplete doesn't take values when typed in 
by keyboard and not being clicked in the selection box. I first thought, this 
was a bug in tapestry for new/free values and filed it in jira 
(https://issues.apache.org/jira/browse/TAPESTRY-2163). But then i was told by 
Andreas Andreou, that it is a problem in my Autocomplete implementation. I 
fixed that (at least i think it is fixed) but the problem stays...

I did some further investigation and looked at the requests being sent when 
submitting the form and this reveals the following:

Load the page first time.

A) When typing "f" into the autocomplete-field, the selctor pops up and shows 
"four" and "f". When completing the typed text to "five" the only option "five" 
rests in the popup. Now i hit submit and the request to the server contains 
parameters "autocomplete="" and autocomplete_selected=*some value from model*. 
The typed in value seems not to be transfered to the request-parameter and so 
the value doesn't reach the server.

B) But when typing in "five" and selecting the popped up "five" and then 
submitting the form, the request contains autocomplete="Sfive" and 
autocomplete_selected="five" and the new value seems to be transfered to the 
request-parameter and sent to the server.

This also occurs for values that are not different from the model ones. If you 
type "one" and "one" is a value of the model, the behaviour of A occurs. If 
typing "one" and selcting the value "one" from the popup, the behaviour of B 
occurs.

The problem seems to be that a value is only taken into account when it is 
being selected via mouse click. When just entering the value into the textbox 
via keyboard it will be ignored and not transfered to the "real request 
parameter". Is this a bug? Or is it my implementation again? Code is below. 
Thanks for _any_ help.

My environment is:
Netbeans 6.0 with Tomcat 6.0.14
JDK 1.6.0_03
Firefox 2 / Internet Explorer 6

HTML-Snippe
   <input jwcid="autocomplete"/>

Page-Snippet
   <component id="autocomplete" type="Autocompleter">
        <binding name="value" value="acField"/>
        <binding name="model" value="acModel"/>
        <binding name="forceValidOption" value="ognl:false"/>
    </component>

Java-Page-Snippet
   public IAutocompleteModel getAcModel() {
        ArrayList<String> s = new ArrayList<String>(3);
        s.add("One");
        s.add("Two");
        s.add("Three");
        s.add("Four");
        return new StringAutocompleteModel(s);
    }

Java-Model-Code
   public class StringAutocompleteModel implements IAutocompleteModel {
      private List<String> cache = null;

      public StringAutocompleteModel(Collection<String> c) {
          if (c == null) {
              throw new RuntimeException("StringAutocompleteModel not properly 
initialized.");
          }
          cache = new ArrayList<String>(c);
      }

      public Object getValue(Object primaryKey) {
          return primaryKey;
      }

      public Object getPrimaryKey(Object value) {
          return value;
      }

      public List getValues(String filter) {
          List resultList = new ArrayList();

          for (String s : cache) {
              if (s.contains(filter)) {
                  resultList.add(s);
              }
          }
          resultList.add(filter);
          return resultList;
      }

      public String getLabelFor(Object value) {
          return value.toString();
      }
  }




Mit freundlichem Gruß / Best regards

Andreas Stroeber

Siemens AG
Industry Sector, A&D SE RD 7
Tel.    : +49 (911) 750-4513
mailto:[EMAIL PROTECTED]
http://www.siemens.com/automation

Siemens Aktiengesellschaft: Chairman of the Supervisory Board: Gerhard Cromme
Managing Board: Peter Loescher, Chairman, President and Chief Executive 
Officer; 
Wolfgang Dehen, Heinrich Hiesinger, Joe Kaeser, Erich R. Reinhardt, Hermann 
Requardt, 
Siegfried Russwurm, Peter Y. Solmssen
Registered offices: Berlin and Munich; 
Commercial registries: Berlin Charlottenburg, HRB 12300, Munich, HRB 6684
WEEE-Reg.-No. DE 23691322



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to