r978 - in trunk/wikitty-struts/src/main: java/org/nuiton/wikitty/struts/component java/template/xhtml tld
Author: mfortun Date: 2011-06-27 12:16:49 +0200 (Mon, 27 Jun 2011) New Revision: 978 Url: http://nuiton.org/repositories/revision/wikitty/978 Log: * wikittyfield handle now select element for wikitty value or fixed values Modified: trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/ExtensionFieldStrutsBean.java trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/WikittyFieldHandler.java trunk/wikitty-struts/src/main/java/template/xhtml/wikitty-close.ftl trunk/wikitty-struts/src/main/tld/wikitty-struts.tld Modified: trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/ExtensionFieldStrutsBean.java =================================================================== --- trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/ExtensionFieldStrutsBean.java 2011-06-27 09:51:18 UTC (rev 977) +++ trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/ExtensionFieldStrutsBean.java 2011-06-27 10:16:49 UTC (rev 978) @@ -47,7 +47,14 @@ } + public void addOption(String val, String desc){ + Option opt= new Option(); + opt.setDescription(desc); + opt.setValeur(val); + this.listOption.add(opt); + } + public class Option { protected String valeur; @@ -64,12 +71,8 @@ public void setDescription(String description) { this.description = description; } - - public void addOption(Option opt){ - listOption.add(opt); - } + - } } Modified: trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/WikittyFieldHandler.java =================================================================== --- trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/WikittyFieldHandler.java 2011-06-27 09:51:18 UTC (rev 977) +++ trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/WikittyFieldHandler.java 2011-06-27 10:16:49 UTC (rev 978) @@ -11,6 +11,10 @@ import org.nuiton.wikitty.entities.FieldType; import org.nuiton.wikitty.entities.Wikitty; import org.nuiton.wikitty.entities.WikittyExtension; +import org.nuiton.wikitty.search.Criteria; +import org.nuiton.wikitty.search.PagedResult; +import org.nuiton.wikitty.search.Search; +import org.nuiton.wikitty.struts.component.ExtensionFieldStrutsBean.Option; public class WikittyFieldHandler { @@ -19,10 +23,10 @@ protected String include = ""; protected String exclude = ""; protected String order = ""; - protected Map<String,FieldSpecialisation> field; + protected Map<String, FieldSpecialisation> field; public WikittyFieldHandler() { - field = new HashMap<String,FieldSpecialisation>(); + field = new HashMap<String, FieldSpecialisation>(); } public Wikitty getWikitty() { @@ -65,8 +69,6 @@ this.order = order; } - - public Map<String, FieldSpecialisation> getField() { return field; } @@ -76,7 +78,7 @@ } public void specialiseField(FieldSpecialisation fieldSpe) { - field.put(fieldSpe.getName(),fieldSpe); + field.put(fieldSpe.getName(), fieldSpe); } public Collection<ExtensionFieldStrutsBean> getWikittyField() { @@ -91,9 +93,7 @@ * included and excluded, it will not appear in the result */ - - - //delegate construction of map + // delegate construction of map Map<String, List<String>> excludeMap = constructIncludeExcludeMap(exclude); Map<String, List<String>> includeMap = constructIncludeExcludeMap(include); // if include is enable it change how to construct result @@ -134,6 +134,8 @@ temp.setLabel(temp.getName()); temp.setValue(""); + + // set the field type. switch (fieldType.getType()) { case BINARY: temp.setType("file"); @@ -175,33 +177,81 @@ } } - - for (Map.Entry<String, FieldSpecialisation> speEntry : field.entrySet()){ - ExtensionFieldStrutsBean obj = mapField.get(speEntry.getKey()); + /* + * specialize field. With name, label, type etc. + */ + for (Map.Entry<String, FieldSpecialisation> speEntry : field.entrySet()) { + ExtensionFieldStrutsBean fieldExtension = mapField.get(speEntry.getKey()); FieldSpecialisation spe = speEntry.getValue(); - if( obj != null){ - + if (fieldExtension != null) { + if (!"".equals(spe.getLabel())) { - obj.setLabel(spe.getLabel()); + fieldExtension.setLabel(spe.getLabel()); } - if (!"".equals(spe.getType())){ - obj.setType(spe.getType()); + if (!"".equals(spe.getType())) { + fieldExtension.setType(spe.getType()); } - - - + + // if fixed list of item is passed via fixvalues attribut + if ("fixed".equals(spe.getSubtype())) { + String[] valu = StringUtil.split(spe.getFixvalues(), ","); + for (String va : valu) { + fieldExtension.addOption(va, va); + } + + // if wikitty load all the options values + } else if ("wikitty".equals(spe.getSubtype())) { + PagedResult<Wikitty> wikitties = null; + + // check the criteria and request wikitty + if (!"".equals(spe.getCriteria())) { + + Criteria criteria = Search.query() + .keyword(spe.getCriteria()).criteria(); + wikitties = proxy.findAllByCriteria(criteria); + } + + String[] descriptor = StringUtil.split(spe.getDescfields(), + ","); + + if (wikitties != null) { + for (Wikitty wiki : wikitties) { + // by default value and description are the same + // wikitty id + String val = wiki.getId(); + + String desc = wiki.getId(); + + // if attribute descripteur fill with something + // extract from wikitty corresponding field value + if (descriptor.length != 0) { + desc = ""; + for (String descriptorIt : descriptor) { + String[] descTable = StringUtil.split( + descriptorIt, "."); + + desc += wiki.getFieldAsString(descTable[0], + descTable[1]); + + } + } + fieldExtension.addOption(val, desc); + } + + } + + } + } - + } - - - + String[] fieldOrder = StringUtil.split(order, ","); /* - * if an order is define parse order and construct ordering result - * if all the field are not defined in the order juste add the rest - * at the end of the result list. + * if an order is define parse order and construct ordering result if + * all the field are not defined in the order juste add the rest at the + * end of the result list. */ if (fieldOrder.length != 0) { @@ -217,30 +267,29 @@ orderedResult.addAll(mapField.values()); return orderedResult; } - + return mapField.values(); } - protected enum fieldTypeSpecialization{ - wikitty, - fixed; + protected enum fieldTypeSpecialization { + wikitty, fixed; } - /** * construct map for exclude or include template * - * @param entry the attribut of the wikitty field tag exemple include="machin.*, truc.bob, truc.tt" - * @return a map with key the string before the dot and a list with the value after the dot example: - * [machin:[*], truc:[tt,bob]] + * @param entry + * the attribut of the wikitty field tag exemple + * include="machin.*, truc.bob, truc.tt" + * @return a map with key the string before the dot and a list with the + * value after the dot example: [machin:[*], truc:[tt,bob]] */ - protected Map<String,List<String>> constructIncludeExcludeMap(String entry){ - - String [] entryTab = StringUtil.split(entry,","); - - - Map<String,List<String>> result= new HashMap<String, List<String>>(); - + protected Map<String, List<String>> constructIncludeExcludeMap(String entry) { + + String[] entryTab = StringUtil.split(entry, ","); + + Map<String, List<String>> result = new HashMap<String, List<String>>(); + // prepare list of excluded field and extension for (String excludeIt : entryTab) { String[] extfield = StringUtil.split(excludeIt, "."); @@ -259,5 +308,5 @@ } return result; } - + } Modified: trunk/wikitty-struts/src/main/java/template/xhtml/wikitty-close.ftl =================================================================== --- trunk/wikitty-struts/src/main/java/template/xhtml/wikitty-close.ftl 2011-06-27 09:51:18 UTC (rev 977) +++ trunk/wikitty-struts/src/main/java/template/xhtml/wikitty-close.ftl 2011-06-27 10:16:49 UTC (rev 978) @@ -26,7 +26,29 @@ </#if> /> </#if> +<#-- +--> +<#if aKey.type=="select" > +${aKey.label} : +<select name="${aKey.name}" size="1"> +<#assign optionKeys = aKey.listOption><#t/> + <#list optionKeys as optionKey><#t/> + <option value="${optionKey.valeur}" + <#if optionKey.valeur==aKey.value > + selected + </#if> + > ${optionKey.description} </option> + </#list><#t/> + +</select> +</#if> + + + + + + </br> </#list><#t/> Modified: trunk/wikitty-struts/src/main/tld/wikitty-struts.tld =================================================================== --- trunk/wikitty-struts/src/main/tld/wikitty-struts.tld 2011-06-27 09:51:18 UTC (rev 977) +++ trunk/wikitty-struts/src/main/tld/wikitty-struts.tld 2011-06-27 10:16:49 UTC (rev 978) @@ -59,6 +59,7 @@ <attribute> <name>name</name> <rtexprvalue>true</rtexprvalue> + <required>true</required> </attribute> <attribute> <name>label</name>
participants (1)
-
mfortun@users.nuiton.org