Typeahead results can be returned from java function

This is a two-part question.

I use the Tim Tripcony Fancy XPage Typeahead script in a number of applications to return a list of types based on several different views in a particular database.

  • Can the server-side javascript specified on this blog be converted to a java class to return the same results that can be obtained using native functions like headhead in XPages.

  • Can this class be part of the extension library that is deployed on all servers, so it is available for all applications for immediate use, and if so, how it will be called from XPage.

+4
source share
2 answers

Yes, I can’t come up with an example of any SSJS that cannot be converted to Java, here is Tim Tripcony 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; } } 

As for creating it in the extension library, all you really need to do to get what I think you need is to put it in the Jar plugin and create a site with a function and update, then you can use the new 8.5 functionality .3 for copy it to all your servers.

You can use this code by doing the following inside 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> 
+7
source

I think converting SSJS to Java is not so difficult. Using a managed bean, you can immediately access the java method in the field. And it should be a nice addition to the extension library, so anyone can benefit from this cool type

0
source

Source: https://habr.com/ru/post/1398614/


All Articles