SCJP, SCJD, SCWCD, SCBCD
SCJP 1.4, SCWCD, SCDJWS
Regards,<br />Deepti.
Color: <formTags:select name='colorField' optionsList='${sessionScope.colorList}'
tabindex='2' />
Color: <formTags:select optionsList='${sessionScope.colorList}'/>
SCJP 5.0<br />SCWCD 1.4<br />Preparing for <b>SCEA</b>.<br /><b>"I prefer an interesting vice to a virtue that bores."</b>
The second method setDynamicAttribute stores any attributes other than those declared in the TLD. In our form.jsp page, the 'name' and 'tabindex' attributes will be stored in the tag object using this method. The localName parameter is the name of the tag and the value is an Object (usually a String) that was passed in as the value of the attribute. The uri parameter is only used when the JSP is a "JSP Document" (an XML document) which may use multiple namespaces. This is rare (and not on the SCWCD exam) so I will not go into any detail on it; for most purposes you can safely ignore this parameter. The most common implementation of this method is to store the localName and value paratemers in a Map object to be used when the HTML is generated.
Turn on, tune in, drop out.
SCJP 5.0<br />SCWCD 1.4<br />Preparing for <b>SCEA</b>.<br /><b>"I prefer an interesting vice to a virtue that bores."</b>
Originally posted by Sreeraj G H:
Sayak i know the usage of dynamic attribute.
But i told here is that the example is not good enough to show the perfect usage of dynamic attribute.If he put that dynamic attributes in the select option list that will make clear to everyone. Am i right?
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Thanks,<br />Target Scwcd<br />SCJP 1.4
<formTags:select name='colorField'
optionsList='${sessionScope.colorList}' tabindex='2' />
rgrds,
Khushhal
I think if we have both static and dynamic attributes for a tag, the static attributes need to come first.
Can we have EL to set the values for dynamic attributes??
[My Blog]
All roads lead to JavaRanch
package myTags;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
public class FunctionTag extends SimpleTagSupport implements DynamicAttributes
{
private double num = 0;
private String output = "";
public void setNum(double num)
{
this.num = num;
}
public void setDynamicAttribute(String uri, String localname, Object value)
{
double val = Double.parseDouble((String)value);
if(localname == "min")
{
output = output + "<tr><td>The minimum of " + num + " and " + val + " </td><td> " + Math.min(num, val) + "</td></tr>";
}
else if(localname == "max")
{
output = output + "<tr><td>The maximum of " + num + " and " + val + " </td><td> " + Math.max(num, val) + "</td></tr>";
}
else if(localname == "pow")
{
output = output + "<tr><td>" + num + " raised to the " + val + " power </td><td>" + Math.pow(num, val) + "</td></tr>";
}
}
public void doTag() throws IOException, JspException
{
getJspContext().getOut().print(output);
}
}
<?xml version="1.0" encoding="ISO-8859-1"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3g.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"
version="2.0">
<tlib-version>1.2</tlib-version>
<tag>
<name>functions</name>
<tag-class>myTags.FunctionTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>num</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<dynamic-attributes>
true
</dynamic-attributes>
</tag>
</taglib>
<%@ page isELIgnored="false"%>
<%@ taglib prefix="test" uri="http://myFuncs/Functions"%>
<table border="1">
<test:functions num="${3*2}" min="4" max="8" pow="2"/>
</table>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page isELIgnored="false"%>
<%@ taglib prefix="test" uri="http://myFuncs/Functions"%>
<c:set var="var2" value="6" scope="request"/>
<table border="1">
var1 = <c ut value="${var2}"/>
<test:functions min="${var2}" num="${3*2}" max="8" pow="2"/>
</table>
var1 = 6
The minimum of 0.0 and 6.0 0.0
The maximum of 6.0 and 8.0 8.0
6.0 raised to the 2.0 power 36.0
rgrds,
Khushhal
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page isELIgnored="false"%>
<%@ taglib prefix="test" uri="http://myFuncs/Functions"%>
<c:set var="var2" value="4" scope="request"/>
<table border="1">
var1 = <c ut value="${var2}"/>
<test:functions num="${3*2}" min="${var2}" max="8" pow="2"/>
</table>
var1 = 4
The minimum of 6.0 and 4.0 4.0
The maximum of 6.0 and 8.0 8.0
6.0 raised to the 2.0 power 36.0
rgrds,
Khushhal
rgrds,
Khushhal
One more thing, is there some version compatibilty regarding the use of runtime expressions for dynamic atrributes.??? Or the runtime expressions have been always applicable to dynamic strributes. Please confirm that.
[My Blog]
All roads lead to JavaRanch
rgrds,
Khushhal
rgrds,
Khushhal
rgrds,
Khushhal
for ( String attrName : tagAttributes.keySet() ) {
out.print(attrName);
out.print("='");
out.print(tagAttributes.get(attrName));
out.print('\'');
}
Originally posted by sid sree:
This code is from the tag handler
Does'nt this give a compile time error ???
SCJP 1.5, SCWCD 1.4, Next... SCBCD5
SCJP 1.5, SCWCD 1.4, Next... SCBCD5
If you ask me anything I don't know, I'm not going to answer.<br />--Yogi Berra
If you ask me anything I don't know, I'm not going to answer.<br />--Yogi Berra
Most of the programming problems can't be solved because you don't know what the exact problem is.
Defining your problem correctly leads you to the right solution.
SCJP 5.0 (80%)<br />SCWCD 1.5 (89%)
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|