Skip to content

Instantly share code, notes, and snippets.

@WarFox
Last active December 14, 2015 00:09
Show Gist options
  • Save WarFox/4996682 to your computer and use it in GitHub Desktop.
Save WarFox/4996682 to your computer and use it in GitHub Desktop.
Spring Roo with cols and rows attributes
<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:spring="http://www.springframework.org/tags" xmlns:form="http://www.springframework.org/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:output omit-xml-declaration="yes" />
<jsp:directive.attribute name="id" type="java.lang.String" required="true" rtexprvalue="true" description="The identifier for this tag (do not change!)" />
<jsp:directive.attribute name="cols" type="java.lang.Integer" required="false" rtexprvalue="true" description="No of columns in the textarea (sets the width)" />
<jsp:directive.attribute name="field" type="java.lang.String" required="true" rtexprvalue="true" description="The field exposed from the form backing object" />
<jsp:directive.attribute name="label" type="java.lang.String" required="false" rtexprvalue="true" description="The label used for this field, will default to a message bundle if not supplied" />
<jsp:directive.attribute name="required" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicates if this field is required (default false)" />
<jsp:directive.attribute name="disabled" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Specify if this field should be enabled" />
<jsp:directive.attribute name="validationRegex" type="java.lang.String" required="false" rtexprvalue="true" description="Specify regular expression to be used for the validation of the input contents" />
<jsp:directive.attribute name="validationMessageCode" type="java.lang.String" required="false" rtexprvalue="true" description="Specify the message (message property code) to be displayed if the regular expression validation fails" />
<jsp:directive.attribute name="validationMessage" type="java.lang.String" required="false" rtexprvalue="true" description="Specify the message to be displayed if the regular expression validation fails" />
<jsp:directive.attribute name="render" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicate if the contents of this tag and all enclosed tags should be rendered (default 'true')" />
<jsp:directive.attribute name="rows" type="java.lang.Integer" required="false" rtexprvalue="true" description="No of rows in the textarea (sets the height)" />
<jsp:directive.attribute name="z" type="java.lang.String" required="false" description="Used for checking if element has been modified (to recalculate simply provide empty string value)" />
<c:if test="${empty render or render}">
<c:if test="${empty cols}">
<c:set var="cols" value="20" />
</c:if>
<c:if test="${empty disabled}">
<c:set value="false" var="disabled" />
</c:if>
<c:if test="${empty label}">
<spring:message code="label_${fn:toLowerCase(fn:substringAfter(id,'_'))}" var="label" htmlEscape="false" />
</c:if>
<c:if test="${empty required}">
<c:set value="false" var="required" />
</c:if>
<c:if test="${empty rows}">
<c:set var="rows" value="3" />
</c:if>
<c:set var="sec_field">
<spring:escapeBody javaScriptEscape="true" >${field}</spring:escapeBody>
</c:set>
<script type="text/javascript">dojo.require("dijit.form.SimpleTextarea");</script>
<div id="_${fn:escapeXml(id)}_id">
<label for="_${sec_field}_id">
<c:out value="${fn:escapeXml(label)}" />:
</label>
<!-- cols and rows defined here work when javascript is disabled -->
<form:textarea cols="${cols}" id="_${sec_field}_id" path="${sec_field}" disabled="${disabled}" rows="${rows}"/>
<br />
<form:errors cssClass="errors" id="_${sec_field}_error_id" path="${sec_field}" />
<!-- cols and rows defined here overrides the values defined in the textarea element, when javascript is enabled. dojo is in action here and converts the element to textarea widget -->
<script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : '_${sec_field}_id', widgetType : 'dijit.form.SimpleTextarea', widgetAttrs : {cols: ${cols}, disabled : ${disabled}, rows: ${rows}}})); </script>
</div>
<br />
</c:if>
</jsp:root>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment