/** * Returns the complete list of suggestions available for selection for this user's session. * * @return the list of suggestions available for the given user's session. */ public List<String> getSuggestions() { // Lookup table Object table = getLookupTable(); if (table == null) { SuggestionsModel model = getComponentModel(); List<String> suggestions = model.getSuggestions(); return suggestions == null ? Collections.EMPTY_LIST : suggestions; } else { List<?> lookupSuggestions = APPLICATION_LOOKUP_TABLE.getTable(table); if (lookupSuggestions == null || lookupSuggestions.isEmpty()) { return Collections.EMPTY_LIST; } // Build list of String suggestions List<String> suggestions = new ArrayList<>(lookupSuggestions.size()); for (Object suggestion : lookupSuggestions) { String sugg = APPLICATION_LOOKUP_TABLE.getDescription(table, suggestion); if (sugg != null) { suggestions.add(sugg); } } return Collections.unmodifiableList(suggestions); } }
/** * Retrieves the data list cache key for this component. * * @return the cache key if client-side caching is enabled, null otherwise. */ public String getListCacheKey() { Object table = getLookupTable(); if (table != null && ConfigurationProperties.getDatalistCaching()) { String key = APPLICATION_LOOKUP_TABLE.getCacheKeyForTable(table); return key; } return null; }
/** * Loads the abbreviated text component from the given code reference table entry using the entry's code as the * visible (abbreviated) text and the entry's description as the abbreviation's expanded text toolTip. * * @param entry the CRT entry to use. */ public void setTextWithCode(final Object entry) { setText(TABLE.getCode(null, entry)); setToolTip(TABLE.getDescription(null, entry)); }
Object table = LOOKUP_TABLE.getTableForCacheKey(key); List<?> data = LOOKUP_TABLE.getTable(table); response.setContentType(WebUtilities.CONTENT_TYPE_XML); response.setHeader("Cache-Control", CacheType.DATALIST_CACHE.getSettings()); xml.appendAttribute("value", LOOKUP_TABLE.getCode(table, item)); xml.appendOptionalAttribute("isNull", isNull, "true"); xml.appendClose(); xml.append(WebUtilities.encode(LOOKUP_TABLE.getDescription(table, item))); xml.appendEndTag("ui:option");
/** * Returns the complete list of options available for selection for this user's session. * * @return the list of options available for the given user's session. */ public List<?> getOptions() { if (getLookupTable() == null) { SelectionModel model = getComponentModel(); return model.getOptions(); } else { return APPLICATION_LOOKUP_TABLE.getTable(getLookupTable()); } }
return opt.getCode() == null ? "" : opt.getCode(); } else { String code = APPLICATION_LOOKUP_TABLE.getCode(getLookupTable(), option);
/** * Retrieves the description for the given option. Intended for use by Renderers. * * @param option the option to retrieve the description for. * @param index the option index. * @return the description for the given option. */ public String getDesc(final Object option, final int index) { String desc = ""; if (option instanceof Option) { String optDesc = ((Option) option).getDesc(); if (optDesc != null) { desc = optDesc; } } else { String tableDesc = APPLICATION_LOOKUP_TABLE.getDescription(getLookupTable(), option); if (tableDesc != null) { desc = tableDesc; } else if (option != null) { desc = option.toString(); } } return I18nUtilities.format(null, desc); }
/** * {@inheritDoc} */ @Override protected void preparePaintComponent(final Request request) { super.preparePaintComponent(request); if (!isInitialised()) { LookupTable lookup = Factory.newInstance(LookupTable.class); for (Object entry : lookup.getTable("sex")) { WAbbrText abbr = new WAbbrText(); abbr.setTextWithDesc(entry); crtSexPanel.add(abbr); } for (Object entry : lookup.getTable("icao")) { WAbbrText abbr = new WAbbrText(); abbr.setTextWithCode(entry); crtIcaoPanel.add(abbr); } setInitialised(true); } } }
@Test public void testInterecptor() throws XpathException, SAXException, IOException { String tableKey = TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE; // Create interceptor DataListInterceptor interceptor = new DataListInterceptor(); interceptor.attachUI(new DefaultWComponent()); // Action phase MockRequest request = new MockRequest(); request.setParameter(WServlet.DATA_LIST_PARAM_NAME, tableKey); interceptor.serviceRequest(request); // Render phase MockResponse response = new MockResponse(); interceptor.attachResponse(response); interceptor.paint(new WebXmlRenderContext(new PrintWriter(response.getWriter()))); String xml = response.getWriterOutput(); // Ensure that the data matches the test table. List<TestLookupTable.TableEntry> table = (List<TestLookupTable.TableEntry>) Factory. newInstance(LookupTable.class).getTable(tableKey); assertXpathEvaluatesTo(String.valueOf(table.size()), "count(/ui:datalist/ui:option)", xml); for (int i = 0; i < table.size(); i++) { assertXpathEvaluatesTo(table.get(i).getCode(), "/ui:datalist/ui:option[" + (i + 1) + "]/@value", xml); assertXpathEvaluatesTo(table.get(i).getDesc(), "/ui:datalist/ui:option[" + (i + 1) + "]/text()", xml); } }
/** * Loads the abbreviated text component from the given code reference table entry using the entry's description as * the visible (abbreviated) text and the entry's code as the toolTip (expansion). You probably do not want this: * you probably want {@link #setTextWithCode(java.lang.Object)}. * * @param entry the CRT entry to use */ public void setTextWithDesc(final Object entry) { setText(TABLE.getDescription(null, entry)); setToolTip(TABLE.getCode(null, entry)); }
/** * Retrieves the data list cache key for this component. * * @return the cache key if client-side caching is enabled, null otherwise. */ public String getListCacheKey() { Object table = getLookupTable(); if (table != null && ConfigurationProperties.getDatalistCaching()) { String key = APPLICATION_LOOKUP_TABLE.getCacheKeyForTable(table); return key; } return null; }
newInstance(LookupTable.class).getTable(tableKey);