Forum Moderators: open

Message Too Old, No Replies

image Taglib doesnot working as a hyperlink

button created dynamically not working as a hyperlink

         

java9g

9:27 am on Dec 20, 2004 (gmt 0)

10+ Year Member



Hi,
I have a taglib which creates buttons dynamically in the jsp. The jsp page is a struts page,which calls this taglib to create buttons dynamically. The button is created to be working as a Hyperlink.when i execute the jsp,
the taglib displays the button but the hyperlink doesnt work. The same thing is working fine in tomcat3.22 but not in Tomcat4.1/5.0.
the code is somewat like this,

For Link


public class ToggleButtonLink extends LinkTag
{
private static Category cat = WebServerCategory.getInstance(" ToggleButtonLink ");

public ToggleButtonLink()
{
src = null;
onSrc = null;
first = true;
results = new StringBuffer();
}

public String getSrc()
{
return src;
}

public void setSrc(String src)
{
this.src = src;
}

public String getOnSrc()
{
return onSrc;
}

public void setOnSrc(String onSrc)
{
this.onSrc = onSrc;
}

public String getImageName()
{
return imageName;
}

private void createImageName()
{
Integer counter = (Integer)super.pageContext.getAttribute("imageCounter");
if(counter == null)
counter = new Integer(0);
Integer next = new Integer(counter.intValue() + 1);
super.pageContext.setAttribute("imageCounter", next);
imageName = "button" + next.toString();
}

protected static String concat(String s1, String s2)
{
if(s1 == null)
return s2;
if(s2 == null)
return s1;
else
return s1 + ";" + s2;
}

public int doStartTag()
throws JspException
{
if(getOnSrc() == null)
setOnSrc(getSrc().substring(0, getSrc().length() - 5) + "2.gif");
createImageName();
if(first)
{
setOnmouseover(concat("document.images['" + getImageName() + "'].src='" + getOnSrc() + "'", getOnmouseover()));
setOnmouseout(concat("document.images['" + getImageName() + "'].src='" + getSrc() + "'", getOnmouseout()));
first = false;
}
reply = super.doStartTag();
results = new StringBuffer("<img name=\"" + getImageName() + "\" src=" + getSrc() + " border=\"0\">");
ResponseUtils.write(super.pageContext, results.toString());
return reply;
}

private String src;
private String onSrc;
private String imageName;
boolean first;
private int reply ;
private StringBuffer results;

For Image Input

public class ToggleImageInput extends ImageTag
{
private static Category cat = WebServerCategory.getInstance(" ToggleImageInput ");

public ToggleImageInput()
{
onSrc = null;
}

public String getOnSrc()
{
return onSrc;
}

public void setOnSrc(String onSrc)
{
this.onSrc = onSrc;
}

public String getImageName()
{
return getProperty();
}

private void createImageName()
{
if(getProperty() == null ¦¦ getProperty().length() == 0)
{
Integer counter = (Integer)super.pageContext.getAttribute("imageCounter");
if(counter == null)
counter = new Integer(0);
Integer next = new Integer(counter.intValue() + 1);
super.pageContext.setAttribute("imageCounter", next);
setProperty("button" + next.toString());
}
}

public int doStartTag()
throws JspException
{
FormTag formTag = (FormTag)TagSupport.findAncestorWithClass(this, org.apache.struts.taglib.html.FormTag.class);
if(formTag == null)
throw new JspTagException("ToggleImageInput must be enclosed in a FormTag");
if(getOnSrc() == null)
setOnSrc(getSrc().substring(0, getSrc().length() - 5) + "2.gif");
if(getBorder() == null ¦¦ getBorder().length() == 0)
setBorder("0");
createImageName();
setOnmouseover("MM_swapImage('" + getImageName() + "','','" + getOnSrc() + "',1)");
setOnmouseout("MM_swapImgRestore()");
return super.doStartTag();
}

private String onSrc;
}

For Image Submit


public class ToggleImageSubmit extends ToggleButtonLink
{
private static Category cat = WebServerCategory.getInstance(" ToggleImageSubmit ");

public ToggleImageSubmit()
{
first = true;
}

public int doStartTag()
throws JspException
{
if(first)
{
setHref("#");
setOnclick(ToggleButtonLink.concat(getOnclick(), "submit()"));
setOnmouseover(ToggleButtonLink.concat("href=document.location.href+'#'", getOnmouseover()));
setOnmouseover(ToggleButtonLink.concat("search=document.location.search", getOnmouseover()));
first = false;
}
return super.doStartTag();
}

boolean first;
}

And the above code is used in jsp as follows :


<%
FW_S fws = new FW_S(3,((Integer) ugtm.getValueAt(i,7)).intValue());
java.util.Vector actions = (java.util.Vector) PMC.getAllowedActions(Profile, fws);
for (int u=0; u< actions.size();u++){
String ki =(String)actions.get(u); //actions.get(u).toString();
if (!ki.equalsIgnoreCase("z")){
String fn = "../images/action_"+actions.get(u)+"1.gif";
String onc = "document.forms[0].action.value='"+ki+"';document.forms[0].desk.value='"+pk+"'";
%>
<td class="<%=myclass%>" height="21" valign="top" align="center">
<webform:toggleSubmit onclick="<%=onc%>" src="<%=fn%>" /></td>
<% } %>
<% } %>

Can anyone pls recommend,why the hyperlink( onClick function) doesnt seem to be working?

Thanks
java9g

jbot

10:59 am on Dec 20, 2004 (gmt 0)

10+ Year Member



FYI, this is a Javascript forum, not a Java one - do you know the difference?!

anyway, as one JSP/Struts developer to another, I'll be charitable and help you.

firstly, wot is the printed HTML string, wot does the HTML source read?

java9g

12:36 pm on Dec 20, 2004 (gmt 0)

10+ Year Member



I do know the difference ,but i didnt found special section for jsp/java questions.so i posted it here.

Html source reads fine with the button and the image being created.

java9g

jbot

2:29 pm on Dec 20, 2004 (gmt 0)

10+ Year Member



well, can you post the relevant (not the whole lot) HTML and JS code so we can see. (you should have done this in the first place, since the JSP/Java servlet is essentially redundant to us.)

java9g

3:38 pm on Dec 20, 2004 (gmt 0)

10+ Year Member



well heres the related JSP code with html


<logic:iterate id="reg" collection="<%= c %>" type="com.User">
<% userColor =(userColor.equals(ETLayout.userRowDark))? ETLayout.userRowBright2: ETLayout.userRowDark;
boolean isRowOdd = (userColor.equals(ETLayout.userRowDark));
%>
<tr bgcolor="<%= userColor %>">
<% String myclass = isRowOdd?"bgGray0":"bgGray1"; %>
<td class="<%=myclass%>"><%=reg.getName() %> </td>
<td class="<%=myclass%>" valign="top" align="center" height="21">
<webform:toggleButtonLink href="ETAdmin.jsp" paramId="id" paramName="reg" paramProperty="name" src= "../images/details1.gif" />
</td>
<% } %>
</tr>
</logic:iterate>

The button generated makes use of Toggling also using the javascript which is being embedded in the doStartTag() of the jsp.
The output looks fine ,but the toggling is not working and for some buttons the onclick/hyperlink doesnt seem to be working.

jbot

4:14 pm on Dec 20, 2004 (gmt 0)

10+ Year Member



can't you just print what's output ... otherwise i have to decipher what you meant, and being lazy, is something quite frankly i can't really be arsed doing ...

jbot

4:17 pm on Dec 20, 2004 (gmt 0)

10+ Year Member



<webform:toggleButtonLink href="ETAdmin.jsp" paramId="id" paramName="reg" paramProperty="name" src= "../images/details1.gif" />

that doesn't mean anything to me, other than it probably printing out another form control with value and name set from the form bean. but i don't know what it's gonna do unless I see the HTML it actually prints, not the JSTL thanks.

java9g

5:05 pm on Dec 20, 2004 (gmt 0)

10+ Year Member



This is the viw source html code which is being generated.

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>SOME SYSTEM</title>
<link rel="stylesheet" type="text/css" href="/someapp/css/standard.css"/>
<script type="text/javascript" language="JavaScript" src="/someapp/js/QXPscripts.js"></script>
<script type="text/javascript" language="JavaScript" src="/someapp/js/bas.js"></script>
<html>
<head>
<title>
</title>
<base href="http://localhost:8080/webPackage/jsp/ETApp.jsp">
<style>
body {margin-left:15px;margin-top:0px}
</style>
</head>
<body>

<form name="SingleUserForm" method="post" action="/someapp/singleUser.do">
<input type="hidden" name="action" value="">
<input type="hidden" name="desk" value="">

<table>
<tr>
<td class="tblHead">At</td>
<td class="tblHead">Valid from</td>
<td class="tblHead">Valid to</td>
</tr>

<tr>
<td class="bgGray1">2004-12-17</td>
<td class="bgGray1">2004-12-17</td>
<td class="bgGray1">2029-12-31</td>
<td class="bgGray1" valign="top" align="center">
<a href="ETUAN.jsp?i=997518&modifier=/viewUser" onmouseover="document.images['button1'].src='../images/view2.gif'" onmouseout="document.images['button1'].src='../images/view1.gif'"><img name="button13" src=../images/view1.gif border="0"></a>
</td>

<td class="bgGray1" height="21" valign="top" align="center">
<a href="#" onclick="document.forms[0].action.value='a3';document.forms[0].desk.value='997518'" onmouseover="document.images['button2'].src='../images/action_a32.gif';search=document.location.search;href=document.location.href+'#'" onmouseout="document.images['button2'].src='../images/action_a31.gif'"><img name="button14" src=../images/action_a31.gif border="0"></a>
</td>
<td class="bgGray1" height="21" valign="top" align="center">
<a href="#" onclick="document.forms[0].action.value='r3';document.forms[0].desk.value='997518'" onmouseover="document.images['button2'].src='../images/action_a32.gif';search=document.location.search;href=document.location.href+'#'" onmouseout="document.images['button2'].src='../images/action_a31.gif'"><img name="button15" src=../images/action_r31.gif border="0"></a>

</td>
</tr>
</table>
</form>
</body>
</html>

jbot

5:13 pm on Dec 20, 2004 (gmt 0)

10+ Year Member



ok at the end of each onclick, insert this: ";return false".

voila: <a href="#" onclick="...; return false" ...>

java9g

3:18 pm on Dec 21, 2004 (gmt 0)

10+ Year Member



Jbot,
i checked out the code and its to do with the cleaning up of the instance variables with respect to tags. Because what i observed with HTML source code is as follows


<a href="#" onclick="document.forms[0].action.value='a3';document.forms[0].desk.value='997502'" onmouseover="document.images['button2'].src='../images/action_a32.gif';search=document.location.search;href=document.location.href+'#'" onmouseout="document.images['button2'].src='../images/action_a31.gif'"><img name="button5" src=../images/action_a31.gif border="0"></a>

<a href="#" onclick="document.forms[0].action.value='r3';document.forms[0].desk.value='997502'" onmouseover="document.images['button2'].src='../images/action_a32.gif';search=document.location.search;href=document.location.href+'#'" onmouseout="document.images['button2'].src='../images/action_a31.gif'"><img name="button6" src=../images/action_r31.gif border="0"></a>

The button name in the image Tag is not getting updated.thats why the onmouseover functionality is not working.
This is working fine in tomcat3.22 but fails in tomcat4.1.so any idea about the cleaning up of instance variables in tomcat4.1?

thanks
java9g