cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gabriel Gruber <Gabriel.Gru...@workflow.at>
Subject Re: Java for generating suggestion-list
Date Tue, 09 Oct 2007 07:16:09 GMT
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


______________________
Mag. Gabriel Gruber
Senior Consultant
http://www.workflow.at




Jeroen Reijn <j.reijn@hippo.nl> 
09.10.2007 09:10
Please respond to
users@cocoon.apache.org


To
users@cocoon.apache.org
cc

Subject
Re: Java for generating suggestion-list






Hi Garbriel,

It is possible to create a Java selection  list. In the forms block 
samples a Java selection list is used for the second  selection list of 
birthdays.

http://cocoon.zones.apache.org/demos/release/samples/blocks/forms/form1

Kind regards,

Jeroen Reijn

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.
> 
> gabriel
> ______________________
> Mag. Gabriel Gruber
> Senior Consultant
> mailto:gabriel.gruber@workflow.at
> http://www.workflow.at

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org



Mime
View raw message