Author: ymartel Date: 2012-05-02 16:49:06 +0200 (Wed, 02 May 2012) New Revision: 143 Url: http://chorem.org/repositories/revision/chorem/143 Log: enable tag support to display wikitty fields Modified: trunk/chorem-webmotion/src/main/java/org/wikitty/web/jsptag/WikittyDisplay.java trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/view.jsp trunk/chorem-webmotion/src/main/webapp/WEB-INF/wikitty.tld Modified: trunk/chorem-webmotion/src/main/java/org/wikitty/web/jsptag/WikittyDisplay.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/wikitty/web/jsptag/WikittyDisplay.java 2012-04-26 16:04:03 UTC (rev 142) +++ trunk/chorem-webmotion/src/main/java/org/wikitty/web/jsptag/WikittyDisplay.java 2012-05-02 14:49:06 UTC (rev 143) @@ -1,6 +1,7 @@ package org.wikitty.web.jsptag; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; import org.nuiton.wikitty.WikittyUtil; import org.nuiton.wikitty.entities.FieldType; import org.nuiton.wikitty.entities.Wikitty; @@ -12,6 +13,8 @@ import javax.servlet.jsp.tagext.SimpleTagSupport; import java.io.IOException; import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.NumberFormat; import java.util.Date; import java.util.List; @@ -99,7 +102,8 @@ protected void viewBinary(JspWriter output, String contextPath, String name, Wikitty wikitty, FieldType field, String extName , String fieldName) throws JspException, IOException { - /*{<%=name%> : <c:out value=<%=wikitty.getFieldAsString(extName, fieldName)%>" />}*/ + String value = wikitty.getFieldAsString(extName, fieldName); + /*{<%=name%> : <%=value%>}*/ } protected void viewBoolean(JspWriter output, String contextPath, String name, @@ -114,13 +118,15 @@ throws JspException, IOException { Date date = wikitty.getFieldAsDate(extName, fieldName); - if (field.hasPattern()) { + String value = ""; + + if (field.hasPattern() && date != null) { String pattern = field.getPattern(); - /*{<%=fieldName%> : <fmt:formatDate value="<%=date%>" pattern="<%=pattern%>" />}*/ - } else { - /*{<%=fieldName%> : <fmt:formatDate value="<%=date%>" />}*/ - + value = DateFormatUtils.format(date, pattern); + } else if (date != null) { + value = DateFormatUtils.format(date, "dd/MM/yyyy"); } + /*{<%=fieldName%> : <%=value%> }*/ } protected void viewNumeric(JspWriter output, String contextPath, String name, @@ -130,9 +136,12 @@ if (field.hasPattern()) { String pattern = field.getPattern(); - /*{<%=fieldName%> : <fmt:formatNumber value="<%=value%>" pattern="<%=pattern%>" />}*/ + //TODO ymartel 2012-05-02 : manage localization + NumberFormat formatter = new DecimalFormat(pattern); + String formattedValue = formatter.format(value); + /*{<%=fieldName%> : <%=formattedValue%> }*/ } else { - /*{<%=fieldName%> : <%=value%> />}*/ + /*{<%=fieldName%> : <%=value%>}*/ } } @@ -151,18 +160,18 @@ protected void viewString(JspWriter output, String contextPath, String name, Wikitty wikitty, FieldType field, String extName , String fieldName) throws JspException, IOException { - boolean value = wikitty.getFieldAsBoolean(extName, fieldName); + String value = wikitty.getFieldAsString(extName, fieldName); /*{<%=fieldName%> : <%=value%>}*/ } protected void viewCollectionWikitty(JspWriter output, String contextPath, String name, Wikitty wikitty, FieldType field, String extName , String fieldName) throws JspException, IOException { - String id = wikitty.getId() + "-" + extName + "-" + fieldName; List<Wikitty> values = wikitty.getFieldAsWikittyList(extName, fieldName, false); /*{<%=fieldName%> : <ul>}*/ for (Wikitty value : values) { - /*{<li><a href="<c:url value="/wikitty/view/<%=value.getId()%>"/>"><c:out value="<%=value%>"/></a></li>}*/ + String url = contextPath + "/wikitty/view/" + value.getId(); + /*{<li><a href="<%=url%>"><%=value%></a></li>}*/ } /*{</ul>}*/ @@ -171,12 +180,11 @@ protected void viewWikitty(JspWriter output, String contextPath, String name, Wikitty wikitty, FieldType field, String extName , String fieldName) throws JspException, IOException { - String id = wikitty.getId() + "-" + extName + "-" + fieldName; String value = wikitty.getFieldAsWikitty(extName, fieldName); Wikitty wikittyValue = wikitty.getFieldAsWikitty(extName, fieldName, false); - String url = contextPath + "/wikitty-json/search?extension=" + field.getAllowed(); + String url = contextPath + "/wikitty/view/" + value; if (wikittyValue != null) { - /*{<%=fieldName%>: <a href="<c:url value="/wikitty/view/<%=wikittyValue.getId()%>"/>"><c:out value="<%=wikittyValue%>"/></a>}*/ + /*{<%=fieldName%>: <a href="<%=url%>"><%=wikittyValue%></a>}*/ } } Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/view.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/view.jsp 2012-04-26 16:04:03 UTC (rev 142) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/view.jsp 2012-05-02 14:49:06 UTC (rev 143) @@ -1,5 +1,6 @@ <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="/WEB-INF/wikitty.tld" prefix="w"%> <p> <c:if test="${not empty wikitty}"> @@ -14,8 +15,7 @@ <a class="btn btn-success btn-mini" href="<c:url value="/wikitty/edit/${wikitty.id}?extension=${ext.name}"/>"><i class="icon-pencil icon-white"></i> Edit</a> <a class="btn btn-danger btn-mini" href="<c:url value="/wikitty/delete/${wikitty.id}?extension=${ext.name}&wmDecoratorNo=true"/>"><i class="icon-trash icon-white"></i> Delete</a></dt> <c:forEach var="fieldName" items="${ext.fieldNames}"> - <dd><%@ include file="wikittyFieldView.jsp"%></dd> - <!-- <dd><w:input wikitty="${wikitty}" fqfield="${ext.name}.${fieldName}"/></dd> --> + <dd><w:display wikitty="${wikitty}" fqfield="${ext.name}.${fieldName}"/></dd> </c:forEach> </dl> </c:forEach> Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/wikitty.tld =================================================================== (Binary files differ)