可以从 java 函数返回预先输入的结果吗 [英] Can typeahead results be returned from a java function

查看:18
本文介绍了可以从 java 函数返回预先输入的结果吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个由两部分组成的问题.

This is a bit of a two part question.

我正在使用 Tim Tripcony 的 Fancy XPage Typeahead 脚本应用程序根据特定数据库中的许多不同视图返回预先输入列表.

I am using Tim Tripcony's Fancy XPage Typeahead script in a number of applications to return a typeahead list based on a number of different views in a specific database.

  1. 该博客中列出的服务器端 javascript 是否可以转换为 Java 类,以返回与 XPage 中的本机预输入函数可以获取的结果相同的结果.

  1. Can the server side javascript listed in that blog be transformed into a java class to return the same results that can be picked up by the native typeahead functions in XPages.

该类是否可以成为部署到所有服务器的扩展库的一部分,以便所有应用程序都可以立即使用它,如果可以,如何从 XPage 调用它.

Can that class be part of an extension library that is deployed to all servers so it is available to all applications for immediate use and if so how would it be called from the XPage.

推荐答案

是的,我想不出任何无法转换为 Java 的 SSJS 的示例,这是 Tim Tripcony 的 SSJS 移植到 Java 的示例.

Yes, I can't think of an example of any SSJS that cannot be converted to Java, Here is Tim Tripcony's SSJS ported to Java.

import java.util.HashMap;
import java.util.Map;
import lotus.domino.*;
import com.ibm.domino.xsp.module.nsf.NotesContext;
public class TypeAhead {
    public static String directoryTypeAhead(String searchValue) {
        String returnList = "";
        try {

            Database directory = NotesContext.getCurrent().getCurrentSession().getDatabase("", "names.nsf");
            View allUsers = directory.getView("($Users)");
            Map<String, HashMap<String, String>> matches = new HashMap<String, HashMap<String, String>>();
                Map<String, String> individualMatches = new HashMap<String, String>();
            Map<String, Boolean> includeForm = new HashMap<String, Boolean>();
            includeForm.put("Person", Boolean.TRUE);
            includeForm.put("Group", Boolean.TRUE);
            ViewEntryCollection matchingEntries = allUsers.getAllEntriesByKey(searchValue, false);
            ViewEntry entry = matchingEntries.getFirstEntry();
            int resultCount = 0;
            while (entry != null) {
                Document matchDoc = entry.getDocument();
                String matchType = matchDoc.getItemValueString("Form");
                if ((Boolean)includeForm.get(matchType)) {
                    String fullName = matchDoc.getItemValue("FullName").elementAt(0).toString();
                    if (matches.get(fullName) == null) {
                        resultCount++;
                        Name matchName = NotesContext.getCurrent().getCurrentSession().createName(fullName);
                        individualMatches = new HashMap<String, String>();
                        individualMatches.put("cn", matchName.getCommon());
                        individualMatches.put("photo", matchDoc.getItemValueString("photoUrl"));
                        individualMatches.put("job", matchDoc.getItemValueString("jobTitle"));
                        individualMatches.put("email", matchDoc.getItemValueString("internetAddress"));
                        matches.put(fullName, (HashMap<String, String>) individualMatches);
                    }
                }
                if (resultCount > 9) {
                    entry = null;
                }
                else {
                    entry = matchingEntries.getNextEntry(entry);
                }
            }
            returnList = "<ul>";
            for (Map<String, String> match : matches.values()) {    
                String matchDetails = "<li><table><tr><td><img class=\"avatar\" src=\"" + match.get("photo") + "\"/></td><td valign=\"top\"><p><strong>" +  match.get("cn") + "</strong></p><p><span class=\"informal\">" + match.get("job") + "<br/>" +  match.get("email") + "</span></p></td></tr></table></li>";
                returnList += matchDetails;
            }
            returnList += "</ul>";
        } catch(Exception e) {
            System.out.println(e);
        }
        return returnList;
    }
}

至于在扩展库中创建它,你真正需要做的就是把它放在一个插件 Jar 中并创建一个功能和更新站点,然后你可以使用新的 8.5.3 功能来将其复制到您的所有服务器.

As far as creating it in an extension library all you really have to do to get what I think you want is put it in a plugin Jar and create a feature and update site then you can use the new 8.5.3 functionality to replicate it out to all of your servers.

您可以通过在 xpage 中执行以下操作来使用此代码:

You might use this code by doing the following inside of your xpage:

<xp:inputText id="inputText1" value="#{viewScope.someVar}">
  <xp:typeAhead mode="partial" minChars="1" valueMarkup="true"
   var="searchValue"
   valueList="#{javascript:return com.tobysamples.demo.TypeAhead.directoryTypeAhead(searchValue);}">
  </xp:typeAhead></xp:inputText>

这篇关于可以从 java 函数返回预先输入的结果吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆