The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

t800t8 (16) [Avatar] Offline
#1
I'm reading chapter 6 of this book and try to do some examples in this chapter. But I have a problem with validating attribute's value at translation time. See the code below:

/*
* GreetingTag.java
*/

package chapter6;

import java.io.IOException;

import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

public class GreetingTag extends TagSupport {
private String name = null;

public int doStartTag() throws JspException {
try {
pageContext.getOut().println("Hello " + name);
}
catch (IOException ioe) {
throw new JspTagException("Error: IOException while writing to the user!");
}

return SKIP_BODY;
}

public void setName(String name) {
this.name = name;
}
}

++++++++++++++++++++++++++++++++++++++++++++++++++

/*
* GreetingTagInfo.java
*/

package chapter6;

import javax.servlet.jsp.tagext.TagData;
import javax.servlet.jsp.tagext.TagExtraInfo;

public class GreetingTagInfo extends TagExtraInfo {

public boolean isValid(TagData data) {
String name = data.getAttributeString("name");

//if (name.equals("bb")) {
return false;
//}

//return true;
}

}

++++++++++++++++++++++++++++++++++++++++++++++++++

<%@page contentType="text/html;charset=UTF-8"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://tlib.com/TagLibs" prefix="tlib" %>
<html>
<head><title>Validate the value of an attribute</title></head>
<body>

<myjpieces:greeting name="aa" />

</body>
</html>

+++++++++++++++++++++++++++++

The isValid() method in GreetingTagInfo always returns false in my example but my JSP page still run well, it doesn't show an exception or error. I'm using NetBeans 3.6 Beta with Tomcat 5.0.16 built-in. Pls help me. Thx a lot!
t800t8 (16) [Avatar] Offline
#2
Re: TagExtraInfo doesn't work!
Sorry, I miss the tag library descriptor

<tag>
<name>greeting</name>
<tag-class>chapter6.GreetingTag</tag-class>
<tei-class>chapter6.GreetingTagInfo</tei-class>
<body-content>empty</body-content>
<description>Validate the value of an atrribute</description>

<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
t800t8 (16) [Avatar] Offline
#3
Re: TagExtraInfo doesn't work!
Nobody answer me? smilie
t800t8 (16) [Avatar] Offline
#4
Re: TagExtraInfo doesn't work!
Answer by myself smilie

Tomcat have a functional which called "cache objects". Because that, method isValid() in my GreetingTagInfo always return false but Tomcat can't catch this exception. You can turn off cache objects function by modifying server.xml. Add attribute "reloadable" with value "true" in Context tag at Tomcat Root Context. This modifying works for developing only, not recommend for deploying.

Sorry for my English. It's terrible!