Hi All
I'm hitting my head against to the wall to do a filed length validation
using a custom tag library in appfuse 2 .I saw many of the default tld are
defined in the WEB-INF/appfuse.tld and those are simulated in view jsp using
taglib.jsp.So accordingly i also tried adding a new tag lib class in the
web/src/java/taglib and have the tag defined in the appfuse.tld.i packaged
the project and deployed assuming the rest of the configurations are done
automatically and I called the tag lib in the jsp using followings
<%@ include file="/common/taglibs.jsp"%> and ad follows
TravelLocation is a model classes which as a travelLocationId and name as
properties and my tag lib name is nullValuesTag which i defined in the
appfuse.tld.But unfortunately i don't see the validation is happening and I
don't see the out put.I did the validation for the length of the travel
location name property which defined as 20 characters in the DB.Can any one
please help me to figure out how to write custom validation in appfuse
whether my approach is correct.
FYI: in the taglib.jsp i have pass the key values of nullValuesTag.length to
applicationRescources.properties files.I'm not sure how this properties file
is read at run time and i hoped to see the message when the validation is
correctly done
Thanks and regards
Kanchana
code piece from the jsp to call the tag lib
----------------------------------------------
<spring:bind path="travelLocation.travelLocationId">
<input type="hidden" name="id" value="<c:out value="${status.value}"/>"/>
</spring:bind>
<div class="content_table">
<p>
<div class="form_table_column1" >
<appfuse:label styleClass="desc" key="travlLocation.name"/>
</div>
<div class="form_table_column2">
<spring:bind path="travelLocation.name">
<appfuse:nullValuesTag value="<%=request.getParameter("name")%>" key="">
</appfuse:nullValuesTag>
<input class="TextField" type="text" name="name" id="name" value="<c:out
value="${status.value}"/>" />
</spring:bind>
</div>
</p>
Appfuse.tld code piece.
----------------------------------------------------------------------------------
<tag>
<name>nullValuesTag</name>
<tagclass>lk.mazarin.lgs.webapp.taglib.NullValuesTag</tagclass>
<bodycontent>JSP</bodycontent>
<info>tests zip code</info>
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>length</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
=======================================
NullValuesTag.java
package lk.mazarin.lgs.webapp.taglib;
import java.io.IOException;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import lk.mazarin.lgs.util.DateUtil;
import org.springframework.web.servlet.support.RequestContext;
/**
* <p>This class is designed to render a formatted date tag in the format
* the user's locale has speficied.</p>
*
* <p>It is designed to be used as follows:
* <pre><tag:date value="comman.datefield" /></pre>
* </p>
*
* @jsp.tag name="date" bodycontent="empty"
*/
public class NullValuesTag extends TemplateTag {
private String value;
private int length;
public NullValuesTag() {
value = null;
length = 1;
}
public int doStartTag() throws JspException {
if (value == null)
return 1; //check if we have zip code
if (value.equals(null))
return 1; //check if value is not null
if (value.length()> 20) {
//has to be an integer! short case of zip code xxxxx
try {
Integer.parseInt(value);
return 0;
} catch (NumberFormatException e) {
return 1;
}
}
/*else if (value.length() == 10) {
// long case on Zip code xxxxx-xxxx
String part1 = value.substring(0, 5);
String dash = value.substring(5, 6);
String part2 = value.substring(6);
if (!dash.equals("-"))
return 1;
try {
Integer.parseInt(part1);
Integer.parseInt(part2);
return 0;
} catch (NumberFormatException e) {
return 1;
}
}*/
return 1;
}
public int getLength() {
return length;
}
public String getValue() {
return value;
}
public void release() {
value = null;
length = 1;
}
public void setLength(int i) {
length = i;
}
public void setValue(String s) {
value = s;
}
}
--
View this message in context:
http://www.nabble.com/Writing-custom-tag-libraries-in-appfuse-2-tp15872546s2369p15872546.html
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]