File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes attribute problem in custom tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "attribute problem in custom tag" Watch "attribute problem in custom tag" New topic
Author

attribute problem in custom tag

Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Hello everybody......
I had tried to run the following programme of custom tag from HFSJ but it throws Exception as: "org.apache.jasper.JasperException: /result.jsp(7,0) According to the TLD or the tag file, attribute user> is mandatory for tag "

my source code in the programme and directory structure as:

1)C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\readTld\form.html

2)C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\readTld\result.jsp

3)C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\readTld\WEB-INF\tlds\test.tld

4)C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\readTld\WEB-INF\lib\jstl.jar

5)C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\readTld\WEB-INF\lib\standard.jar

6)C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\readTld\WEB-INF\classes\foo\AdviserTagHandler.class

And the source code as follows
1) form.html

<html>
<body>
<form action = "result.jsp" method="Get">
<h1> Login Page </h1>
Name:<input type="text"name="userName">
Password:<input type="password"name="userPassword">
<input type = "SUBMIT">
</form>
</body>
</html>

2) result.jsp

<html>
<body>

<%@ taglib prefix="mine" uri="randomThings" %>
Adviser Page


<mine:advice user ="${param.userName}" />
</body>
</html>

3)test.tld

<?xml version="1.0" encoding="ISO-8859-1" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">
<tlib-version>1.1</tlib-version>
<uri>randomThings</uri>
<tag>
<description>random advice</description>
<name>advice</name>
<tag-class>foo.AdviserTagHandler</tag-class>
<body-content>empty</body-content>

<attribute>
<name>user></name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>

</tag>

</taglib>


4) and 5) are jar files

6) java file of AdviserTagHandler.class is like as:

package foo;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

public class AdviserTagHandler extends SimpleTagSupport
{
private String user;

public void doTag() throws JspException,IOException
{
getJspContext().getOut().write("Hello"+user+"
");
getJspContext().getOut().write("Your advice is:"+getAdvice());
}

public void setUser(String user)
{
this.user = user;
}

String getAdvice()
{
String[] adviceString = {"That color's is not working for you","You should call in sick.","You might have to rethink that haircut."};
int random = (int)(Math.random()*adviceString.length);
return adviceString[random];
}
}


so, Please tell me what's wrong in this programme as it says:According to the TLD or the tag file, attribute user> is mandatory for tag

Life is easy because we write the source code.....
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Pramod. There is an error present in test.tld. Use
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

yes I think you are right.
Thank you Chinmaya

will you please tell me how the control is transfer from form.html to result.jsp and tag handler.
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Pramod. When we submit the form, the control goes to the result.jsp. In result.jsp, there is taglib directive, the container sees the uri and locates the corresponding tld file by searching the predifined locations and it calls the appropriate tag handler class. At this time tag handler life cycle starts, and atlast control will return to the result.jsp and the response will sent to the client.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: attribute problem in custom tag
 
Similar Threads
Compiling my first custom tag handler
HTTP Status 404 - /myApp/servlet/Testing
Request Resource not available.
Compiling java file
org.apache.jasper.JasperException: Unable to compile class for JSP: