Reputation: 101
i tried to disable auto complete(autocomplete="off") in struts framework,the process i followed is 1)In Strut-html.tld file i had few attributes of TextTag so added autocomplete attribute
<tagclass>org.apache.struts.taglib.html.TextTag</tagclass>
<attribute>
<name>autocomplete</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
2)i wrote a class for customtag by extending org.apache.struts.taglib.html.TextTag
import org.apache.struts.taglib.html.TextTag.*;
public class TextTag extends org.apache.struts.taglib.html.TextTag {
private static final long serialVersionUID = 1L;
private String autocomplete = null;
public String getAutocomplete()
{ return autocomplete; }
public void setAutoComplete(String autocomplete)
{
this.autocomplete = autocomplete;
}
protected void prepareOtherAttributes(StringBuffer sb) {
if (autocomplete != null) {
sb.append(" autocomplete=\""+autocomplete+"\"");
}
}
}
3) And in jsp page i added autocomplete="off" attribute
so when i run my application im getting the following error
/index.jsp(1): Error in using tag library uri='/tags/struts-html' prefix='html':
The Tagclass'org.apache.struts.taglib.html.FormTag' has no setter method corresponding
to TLD declared attribute 'name', (JSP 1.1 spec, 5.4.1) probably occurred due to an
error in /index.jsp line 1:
<%@ taglib uri="/tags/struts-html" prefix="html" %>
Some one please help me to solve this error and i tried with javascript as well but its not working.
function DisableAutocomplete()
{
var AC_Disable_login=document.forms[0].elements['loginID'];
AC_Disable_login.setAttribute ("autocomplete", "off");
}
Upvotes: 5
Views: 8416
Reputation: 19
I have tried many solutions 1. including the dirty hack given above, 2. setting autocomplete off for form by calling a script at page load:
<body class="article-page auxillary-page" onload="autocompletion()">
function autocompletion()
{
for (i=0; i<document.forms.length; i++) {
document.forms[i].setAttribute("AutoComplete","off");
}
}
and few others, None of them seems to work.. I think the only solution is: change your tag to html tag, and then in submit function for form assign that value to your required bean property.
you can use
<input type="password" name="password1" maxlength="4" size="25" readonly onfocus="this.removeAttribute('readonly');" autocomplete="off" />
This worked for me on struts 1 , J7 Eclipse keplar, wildfly server.
Upvotes: 0
Reputation: 6428
There is a quick and dirty hack documented here http://www.coderanch.com/t/54020/Struts/form-input-tags-turning-autocomplete that embeds the autocomplete option inside another form element.
For example
<html:form method="post\" autocomplete=\"off" action="verify_login.do" >
Struts renders as
<form name="LoginForm" method="post" autocomplete="off" action="verify_login.do">
Its not pretty but it saves the need to redefine Struts taglibs.
Upvotes: 1
Reputation: 42040
You do not need to rewrite Struts 1.x to add this functionality. All you need is to add the following lines:
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
$(function(){
$(":text").attr("autocomplete", "off");
});
</script>
Upvotes: 3