Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom tag attribute?

Status
Not open for further replies.

irinapl

Programmer
Aug 30, 2006
5
NO
Hi,

I need to add custom attribute to the "html:text" tag.

Example:

<html:text name="emailForm" property="email" performValidate="true" />

And the result would be

<input type="text" name="email" value="" performValidate="true">

The attribute "performValidate" will then be checked with JavaScript.

Is this possible to do? Maybe I can extend struts taglib?
 
Hi

irinapl said:
<input type="text" name="email" value="" performValidate="true">

The attribute "performValidate" will then be checked with JavaScript.
Just because you specify an invalid attribute to a tag, the browser will not add a new property to the class which represents that element in the DOM. So you will not access it through JavaScript.
dev_html.html said:
The output is HTML 4.01 compliant

So by default Struts will not generate the desired invalid HTML.

For the server side part of your idea you have to extend the org.apache.struts.taglib.html.BaseInputTag and org.apache.struts.taglib.html.BaseFieldTag classes or more, and update the taglib.tld, struts-form.tld and struts-html.tld.

For the client side part, you have to write a browser.

Feherke.
 
Thank you Feherke,

Is there any other way to mark the element, so that I can chack for that mark later? I have a lot of fields in the form and some of them need to be marked.

irinapl
 
Hi

I suggest to use a style class.

This goes completely off-topic as it belongs to forum216, but in JSP looks like this :
Code:
<%@[blue][b]taglib[/b][/blue] [green]prefix[/green]=[purple]"html"[/purple] [green]uri[/green]=[purple]"/WEB-INF/struts-html.tld"[/purple]%>
<[blue][b]html:html[/b][/blue]>
<[blue]head[/blue]>
<[blue]style[/blue] [green]type[/green]=[purple]"text/css"[/purple]>
input.mandatory { border-color: red; }
</[blue]style[/blue]>
<[blue]script[/blue] [green]type[/green]=[purple]"text/javascript"[/purple]>
function check()
{
  for (i=0;e=document.getElementsByTagName('input')[i++];) {
    if (e.type!='text' || e.className!='mandatory') continue;
    [gray]// check here[/gray]
  }
}
</[blue]script[/blue]>
</[blue]head[/blue]>
<[blue]body[/blue]>
<[blue][b]html:form[/b][/blue] [green]action[/green]=[purple]"#"[/purple] [green]onsubmit[/green]=[purple]"check"[/purple]>
Age : <[blue][b]html:text[/b][/blue] [green]property[/green]=[purple]"age"[/purple] [green]styleClass[/green]=[purple]"mandatory"[/purple]/><[blue]br[/blue]>
Sex : <[blue][b]html:text[/b][/blue] [green]property[/green]=[purple]"sex"[/purple] [green]styleClass[/green]=[purple]"mandatory"[/purple]/><[blue]br[/blue]>
Location : <[blue][b]html:text[/b][/blue] [green]property[/green]=[purple]"location"[/purple]/><[blue]br[/blue]>
<[blue][b]html:submit[/b][/blue]/>
</[blue][b]html:form[/b][/blue]>
</[blue]body[/blue]>
</[blue][b]html:html[/b][/blue]>

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top