In searching for information on how to use Java generated data as a *suggestion* list in a CFORM multivaluefield I came across the 3 month old email thread below.

I am interested in using this... did it get resolved?

Regards,
David Legg


Jeroen Reijn wrote:
Ah.. I must have been still a sleep. I'll try to have a look today as well. The suggestion list has the ability for an attribute type='java', but the flowscript part I have no idea yet.


Reijn

Gabriel Gruber wrote:

Hmm, thanx for your quick replies.

however you are referring to the "selection-list" while I would like to use the new "suggestion-list". an example is provided within the latest cocoon cforms samples, but the suggestion-list is created via javascript (which is very hard to debug). so my question is: is there a way to do that in java?

  <fd:field id="personId">
      <fd:datatype base="integer"/>
      <fd:initial-value>16</fd:initial-value>
      <fd:suggestion-list type="javascript">
      <![CDATA[
        function addSuggestion(bean) {
            suggestions.push({value: bean.value, label: bean.label});
        }

        function personList() {
          return [
                  {value: 1, label: "Donald Ball"},
                  {value: 2, label: "Sylvain Wallez"},
                  {value: 3, label: "Carsten Ziegeler"},
                  {value: 4, label: "Torsten Curdt"},
                  {value: 5, label: "Marcus Crafter"},
                  {value: 6, label: "Ovidiu Predescu"},
                  {value: 7, label: "Christian Haul"},
                  {value: 8, label: "Jeremy Quinn"},
                  {value: 9, label: "Stefano Mazzocchi"},
                  {value: 10, label: "Pierpaolo Fumagalli"},
                  {value: 11, label: "Davanum Srinivas"},
                  {value: 12, label: "Antonio Gallardo"},
                  {value: 13, label: "Ugo Cei"},
                  {value: 14, label: "David Crossley"},
                  {value: 15, label: "Bertrand Delacr&#233;taz"},
                  {value: 16, label: "Bruno Dumon"},
                  {value: 17, label: "Daniel Fagerstrom"},
                  {value: 18, label: "Leszek Gawron"},
                  {value: 19, label: "Ralph Goers"},
                  {value: 20, label: "Vadim Gritsenko"},
                  {value: 21, label: "Jorg Heymans"},
                  {value: 22, label: "J&#246;rg Heinicke"},
                  {value: 23, label: "Jean-Baptiste Quenot"}
                ];
        }

        function startsWith(string1, string2) {
          return (new java.lang.String(string1)).startsWith(string2);
        }
               function searchByString() {
          for (var i = 0; i < list.length; i++) {
            if (startsWith(list[i].label, filter)) {
              addSuggestion(list[i]);
            }
          }
        }
               function searchById() {
          for (var i = 0; i < list.length; i++) {
            if (list[i].value == parseInt(filter)) {
              addSuggestion(list[i]);
            }
          }
        }
               var suggestions = [];
        var list = personList();
        if (filter) {
          var phase = cocoon.request.getParameter("phase");
          if (phase && phase.equals("init")) {
            if (!isNaN(parseInt(filter))) {
              searchById();
            } else {
cocoon.log.error("The filter: '" + filter + "' must be a number.");
            }
          } else {                          searchByString();
          }                  } else {
          suggestions = list;
        }
        return suggestions;
      ]]>
      </fd:suggestion-list>
    </fd:field>

thanx for you help

gabriel


Gabriel Gruber wrote:
 >
 > Hello!
 >
 > I was just wondering, if it is possible to use java instead of
> javascript to generate a suggestion-list for a cforms widget. this java
 > aims to query a database (via hibernate) and should return a list of
 > results.
 >
 > something like this...
 > <fd:field id="person">
 >     <fd:datatype base="string"/>
 >     <fd:suggestion-list type="java"
 > src="com.mycompany.SuggestionListHandler"/>
 > </fd:field>
 >
> any ideas? from looking in the api i couldn't find a way for this to work. >

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to