I follow the code which I got the code from developers.java.sun.com
http://developer.java.sun.com/developer/technicalArticles/javaserverpages/maintain_button/#author Here I have paste my code files tld,class,
jsp files as below
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.1</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>RTag</short-name>
<tag>
<name>RadioButton</name>
<tag-class>RadioBean.RadioButtonTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>RadioButtonSet</name>
<tag-class>RadioBean.RadioButtonSetTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>checked</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
public class RadioButtonTag extends TagSupport {
public RadioButtonTag() {
}
private
String value = null;
public void setValue(String value) {
this.value = value;
}
public int doStartTag() throws JspException {
RadioButtonSetTag tag = (RadioButtonSetTag)findAncestorWithClass(this, RadioButtonSetTag.class);
System.out.println("doStartTag()3");
if (tag == null) {
throw new JspTagException("Must be enclosed within RadioButtonSet");
}
try {
System.out.println("doStartTag()4");
pageContext.getOut().print("Radio Button Test");
pageContext.getOut().print("Kumar its working!!!");
//out.write("Helo world");
//pageContext.getOut().write("<input type=\"RADIO\" name=\"" + tag.getName()+ "\" value=\""+ value + "\" "+ tag.getHolder().getCheckStatus(value)+ ">");
System.out.println("doStartTag()5");
System.out.println("doStartTag()end2");
}
catch (Exception ex) {
throw new JspTagException("IO problems");
}
return SKIP_BODY;
}
}
package RadioBean;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class RadioButtonSetTag extends BodyTagSupport {
public RadioButtonSetTag() {
}
private String name = null;
private String checked = "button1";
private ButtonHolder holder = null;
public String getName() {
return name;
}
public void setName(String name) {
this.name=name;
}
public String getChecked(){
return checked;
}
public void setChecked(String checked) {
this.checked=checked;
}
public ButtonHolder getHolder() {
return holder;
}
public int doStartTag() {
System.out.println("doStartTag()1");
try{
holder = new ButtonHolder();
if (checked != null) {
System.out.println("doStartTag()2");
holder.setCheckedButton(checked);
}
}catch(Exception ex){
System.out.println("Error"+ex.getMessage());
}
return EVAL_BODY_AGAIN;
}
}
package RadioBean;
public class ButtonHolder {
public ButtonHolder() {
}
private static final String CHECKED = "";
private static final String UNCHECKED = "";
private String checkedButton = "button1";
private String[] checkedButtons = null;
private boolean radio = false;
public void setCheckedButton(String value) {
checkedButton = value;
System.out.println("Checked"+value);
radio = true;
}
public void setCheckedButtons(String[] values) {
checkedButtons = values;
radio = false;
}
public String getCheckedButton(){
return getCheckStatus("button1");
}
public String getCheckStatus(String value) {
if (radio) {
System.out.println("Radio");
if (value.equals(checkedButton)) {
return CHECKED;
} else {
return UNCHECKED;
}
} else {
if (checkedButtons == null) {
return UNCHECKED;
} else {
for (int i = 0; i < checkedButtons.length; i++) {
if (value.equals(checkedButtons[i])) {
return CHECKED;
}
}
return UNCHECKED;
}
}
}
}
<%@ page errorPage="Radio_error.jsp" %>
<%@ taglib uri="/WEB-INF/kp.tld" prefix="RTag" %>
<html>
<jsp:useBean id="bean0" class="RadioBean.ButtonHolder" />
<body>
<RTag:RadioButtonSet name="radioSet" checked="<%=bean0.getCheckStatus("")%>">
<RTag:RadioButton value="button1"> The first button </RTag:RadioButton>
<RTag:RadioButton value="button2"> The second button </RTag:RadioButton>
</RTag:RadioButtonSet>
<% out.println("Bye Bye "); %>
</body>
</html>
all the above code is working fine but Radio buttons are not appear
in the jsp screen
why?
Hope to hear from you soon...
Kumar