• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

form/input tags and turning off autocomplete

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone have experience in turning off autocomplete when using <html:form> or <html:text> tags? I put an autocomplete attribute in and it comes up with an error that autocomplete is not a valid attribute. Any ideas?

Thanks!!!
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately, the autocomplete attribute is not passed through to the rendered HTML by the <html:text> tag. If you must have the ability to turn off autocomplete, you have 2 options:

1. Use the regular HTML <input> tag If the name attribute you specify is the same as the property attribute you'd use with an <html:text> tag, Struts will still populate the form bean when it's submitted. To display the value from the form bean, specify value="${myFormBean.myProperty}".

2. Write your own custom tag that extends the <html:text> tag to accept the autocomplete attribute and pass it through to the rendered <input> tag.
[ June 19, 2006: Message edited by: Merrill Higginson ]
 
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We did option #2 (created a custom form tag). Here's the code:



You'll also need to copy the form tld definition from struts-html.tld to define your new custom tag and add the following attribute:

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote the above class and pasted the atribute tag inside my asrs-struts-html.tld file. This attribute tag i.e.

<attribute>
<name>autocomplete</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>

was pasted within the tag with the name text. The tag class for this is
<tagclass>org.apache.struts.taglib.html.TextTag</tagclass>

However I have written my tag class in the package called asrs.ia.webauth.web.customTags.ASRSTextTag

ASRSTextTag.java extends the TextTag indicated, but when I am trying to use the autocomplete tag inside my html:text fieled as below:

<td class="BodyText"><html:text property="ssn" size="20" maxlength="11" autocomplete="off"/> ex: ###-##-####</td>

It is still giving me the following error:

OracleJSP: oracle.jsp.parse.JspParseException: Line # 25, <td class="BodyText"><html:text property="ssn" size="20" maxlength="11" autocomplete="off"/> ex: ###-##-####</td>
Error: autocomplete is not a property of asrs.ia.webauth.web.customTags.ASRSTextTag

What is the problem and why its not being recognised? Please help.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anand,

For what you're doing, the class posted above by Martin won't work. His class extends the <html:form> tag, while yours is attempting to extend the <html:text> tag. He defines a "customAttributes" property, while you define an "autocomplete" property.

Here's a class that might work for you:
 
Anand ASRS Kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill,

Thanks for the reply. I didn't get the error message this time but the problem still persists. The attribute was accepted in the text field as below:

<td class="BodyText"><html:text property="ssn" size="20" maxlength="11" autocomplete="off"/> ex: ###-##-####</td>

And it ditn give me any error. But the AutoComplete is not yet OFF. Both IE and Mozila yet are storing the SSN values. No differences as such. Could you please tell me what could be the problem?

Also when I did "view source", I was surprised not to see the autocomplete="off" attribute in the SSN field.

Please help.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use the above class and it works for me. When I select "view source" the autocomplete is there. Did you change the name of the class in the TLD? Example:

<tag>
<name>text</name>
<tagclass>com.mycompany.taglib.TextTag</tagclass>

One other thing to check:

Are you using Struts 1.2 or above? If not, this won't work. Only Struts 1.2 and above has the prepareOtherAttributes method that can be overridden.
[ August 22, 2006: Message edited by: Merrill Higginson ]
 
Anand ASRS Kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill:

Thanks a lot for your prompt reply.
Unfortunately we are using Struts 1.1 and as you say, because of this, I have not been able to successfully use it. The cost of migrating our application to the higher version of struts and the complications involved will be too much at this juncture so probably, this wont be an immediate option for us.

Do you know any other ways of doing this may be using some java script render this attribute in the text field?

Any help would be highly appreciated.
Thanks anyways.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can still extend TextTag in Struts 1.1. It's just that you have to work a little harder to do so. Since there's no designated method to override, you will have to download and study the 1.1 source code to find out how to keep the functionality of the current tag while adding the new autocomplete tag.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Thanks for posting. I am trying to implement the same autocomplete in my application using struts 1.3.8. But it gives the error

JSPG0123E: Unable to locate tag attribute info for tag attribute autocomplete.

Though, I have used the exact procedure that you have mentioned in your posting. I overwrite the <tagclass> and include an <attribute> as follows:
<tag>
<name>text</name>
<tagclass>com.mycomp.app0008.taglib.TextTag</tagclass>
<attribute>
<name>autocomplete</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>

and included in the class as

package com.mycomp.app0008.taglib;
public class TextTag extends org.apache.struts.taglib.html.TextTag
{
protected String autocomplete = null;


/**
* @return Returns the autocomplete.
*/
public String getAutocomplete() {
return autocomplete;

}
/**
* @param autocomplete The autocomplete to set.
*/
public void setAutocomplete(String autocomplete) {
this.autocomplete = autocomplete;

}
/* (non-Javadoc) *
* @see org.apache.struts.taglib.html.TextTag#renderOtherAttributes(java.lang.StringBuffer)
*
* @Override
*/
public void prepareOtherAttributes(StringBuffer sb) {
if (autocomplete != null) {
sb.append(" autocomplete=\""+autocomplete+"\"");
}
}

}

The tag I used as

<html:text property="ssn" size="10" maxlength="30" autocomplete="off" />

Could anyone please, check what could be the error.

I appreciate your help. Thanks,

Rafiqul
[ June 26, 2007: Message edited by: RAF ISLAM ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Struts 1.3.8 the TLDs are contained in the META-INF/tld directory inside the struts-taglib-1.3.8.jar file. If you're trying to modify the existing Struts html tag library, Struts will be using the TLD inside the jar file rather than yours, and that's why you're getting the error message. The easiest way to fix this is to reference your new TLD directly by its name, rather than by the namespace. That way it's sure to pick up yours and not the original version. Example:

<%@ taglib uri="/WEB-INF/myHtml.tld" prefix="html" %>

instead of

<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

I read all the posts above. I am in need of autocomplete=off in the struts html:form on my jsp. I am using Struts-1.2.9. I created a custom Form Tag as follows:

package dhs.fspp.common.util;
import org.apache.struts.taglib.html.*;

public class FormTag extends org.apache.struts.taglib.html.FormTag {

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+"\"");
}
}
}

Then I added the following to my Struts-html.tld:

<name>form</name>
<tagclass>dhs.fspp.common.util.FormTag</tagclass>
<attribute>
<name>autocomplete</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>

and my Form definition goes in this way:
<html:form action="/createapp.do"
method="post" styleId="mainForm" autocomplete="off">

After adding this,the page gets displayed fine but when I view source of the html from the browser, I cannot see the autocomplete attribute in the html Form tag and the autocomplete feature doesn't work.

Can someone explain me where I went wrong?

Thanks,
Naveen
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe in the version of Struts that you're using the FormTag method you need to override is renderOtherAttributes. If you're using Java SDK 1.5 or above, it's a good idea to put the annotation @Override above the method. That way, if the signature doesn't match a method in the superclass, the compiler will let you know that you're not really overriding anything.
[ April 22, 2008: Message edited by: Merrill Higginson ]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I founded a really "non standard solution" to this problem.
I should say it is a sort of "sql injection" transposed into the java code (and probably it works thanks to java reflection, which I think is largely used in rendering the tags...)



I have the same problem with autocomplete.
Since I am in a great hurry, after reading your comments about this, I decided to simply generate (manually) the tag (standard input and java code inside an old style jsp page).

I was still working, when came to my mind a possible workaround, which is really far from your proposed solutions, but which worked for me.
From a practical point of view:

take an html:text tag, lets say:

<html:text styleId="driver2" onchange="getTownsByCap('driver3','driver2');" property="driver.residenceCap" style="width:148px;" maxlength="5" tabindex="30"/>

Then, find an "inoffensive attribute"; I've chosen the style, and changed it in this way,

from: style="width:148px;"
to: style="width:148px;\" autocomplete=\"off"

What I did is to put an escaped set of quotes (with the proper text) inside the html:text style attribute, so that now the tag looks like

<html:text styleId="driver2" onchange="getTownsByCap('driver3','driver2');" property="driver.residenceCap" style="width:148px;\" autocomplete=\"off" maxlength="5" tabindex="30"/>

...
well, when it is rendered, the tag becomes:

<input id="driver2" type="text" autocomplete="off" style="width: 148px;" onchange="getTownsByCap('driver3','driver2');" value="" tabindex="30" maxlength="5" name="driver.residenceCap"/>


It seems it works...
I'd like to know if this works for you also.. I'm using struts 1.3, java 1.6, tomcat 6.0.18

I hope someone will read this post (the topic seems fairly old)... and please, do not forget to tell me if it works for you also

Enrico
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see why it *wouldn't* work, but in general I try to discourage solutions like this.
 
Enrico Scelsa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well David.
Thanks for your comment.

Just to (partially) follow your reasons, a couple of points (this is not a complete and accurate description of the possible incredible complexities of this problem... just two... no, three ideas):

a) this (seems to be) an hack. It is not officially supported by the Struts community and it is not possible to give any kind of reasonable warranty about the fact that it will work, in any case or situation (at least, it seems so).
b) a new release of struts 1.x (the spec. of the release I am using is 1.2.7) could not support the workaround (but, for instance, could officially support adding arbitrary attributes to a tag (or at least a couple of them)))
c) sometimes, time is not enough, and having also an inappropriate (but working) solution can save your life... it can also definitely destroy it, depends on the use you put on it.

I partially agree with you (because of a) and b)) but I do not totally agree, (because of c), and because sometimes it is good to think outside the box...(I just googled for your book) )

Enrico
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Enrico... i think its brilliant... simple... and works (what better combination)
i had the same problem and have done all above... even extended the taglib.html.TextTag class and tried it out in various versions of struts 1x....i finally get my page to load after all sort of errors (compilation et al) and autocomplete is still on...

@ David... perhaps you can tell us why you discourage solutions like this one....

Thanks All....
 
Enrico Scelsa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankyou Williams,
I am happy it worked for you.

BTW, on my side is still in this way (I'm really overloaded, so I do not have time to overload!!!)
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a similar requirement of disabling autocomplete in my existing web application that uses struts <html:text>, <html:form> tag. I understnd that we can extend either the struts text or form tag to achieve this.

Would like to know if by default i can set the autocomplete off in my extended tag class so that i dont need to modify my thousand lines of input element or 300 's of my form tag to include the autocomplete option.

Can i include a Javascript function i.e. referred from all the Web Pages where i can set the Form Element / Text Element as autocomplete="off" after extending the html:form or html:text tag instead of changing the individual forms/text elements.

I understand this would cause problem if few of the text/ forms needs to be set autocomplete true. But the immediate requirement is to set the autocomplete option off.

Request some insight on this.

Thanks in advance.

Regards
Roshini Sridharan
 
Greenhorn
Posts: 8
Postgres Database Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know this is an old thread but I thought I would offer a different solution for anyone still looking for an answer. My requirements for this were as follows:

Disable the auto-complete feature without destroying the w3c compliance validation for our pages.

The attribute tag "autocomplete", e.g. <form id="testme" action="someaction.do" method="post" autocomplete="off">... works beautifully for us. However it breaks w3c validation for our DOCTYPE.

So rather than modify struts to produce "bad" HTML, we took the approach of adding this attribute via the DOM and thereby hiding from the validation.

In a loaded JavaScript file we added a method that's called by the onload event for the page. Then we get the form by id and set the attribute from there. using the above form example:

var pageForm = document.getElementById("testme");
if(pageForm != null){
pageForm.setAttribute("autocomplete","off");
}

This has worked for IE and FireFox.
 
Ranch Hand
Posts: 35
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand this is old thread, but I didn't see the answer for the problem with using Struts 1.1. In this situation to turn off autocomplete we can use the autocomplete in this format:
<html:text size="46\" autocomplete=\"off" maxlength="18"/>
The tricky part here is introduction of "\" (backslash) before and after autocomplete attribute
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hope property="driver.residenceCap" is Arraylist But it didn't work for me.
No getter method for property formname.propertyname
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Meril,

I tried doing the same. that is adding the attribute, creating a class of new Form tag which is customized and my Struts version is 1.2 as well. I can see the autocomplete="off" in the F12 developer tools but the problem is still persistent. My browser is IE11. My company website works on it and i read that IE11 and all the new versions of browsers ignore autocomplete property and make them on by default. can you suggest me a work around. I also tried the "\" one which is mentioned below about the SQL injection but it is throwing error. Please suggest me some method to do it. Looking forward for your reply soon.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Madhuri Gumma wrote:Hi Meril,

I tried doing the same. that is adding the attribute, creating a class of new Form tag which is customized and my Struts version is 1.2 as well. I can see the autocomplete="off" in the F12 developer tools but the problem is still persistent. My browser is IE11. My company website works on it and i read that IE11 and all the new versions of browsers ignore autocomplete property and make them on by default. can you suggest me a work around. I also tried the "\" one which is mentioned below about the SQL injection but it is throwing error. Please suggest me some method to do it. Looking forward for your reply soon.



Were you able to disable caching with struts 1.2?
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic