i using struts2 create web application facing problem customing tag struts2.
i'd add attribute anchor tab , i've created classes so. don't know how integrate it. think have create tld don't know if have use whole struts-tags.tld override tld don't know how.
here anchor.java:
package com.mycompany.struts.components; import java.util.uuid; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import org.apache.struts2.views.annotations.strutstag; import org.apache.struts2.views.annotations.strutstagattribute; import com.opensymphony.xwork2.util.valuestack; @strutstag(name = "anchor", tldtagclass = "com.mycompany.struts.components.anchortag", description = "render anchor", allowdynamicattributes = true) public class anchor extends org.apache.struts2.components.anchor { protected string token; public anchor(valuestack stack, httpservletrequest request, httpservletresponse response) { super(stack, request, response); } protected void evaluateextraparams() { super.evaluateextraparams(); if (token != null && (boolean) findvalue(token, boolean.class)) { string uuid = string.valueof(uuid.randomuuid()); urlparameters.put("idtoken", uuid); if(onclick == null) onclick = ""; else if(onclick.trim().length() > 0 && onclick.trim().charat(onclick.trim().length()-1) != ';') { onclick += "; "; } else { onclick += " "; } onclick += "tokenizedurl('"+uuid+"');"; } } @strutstagattribute(description = "token", type = "boolean", defaultvalue = "false") public void settoken(string token) { this.token = token; } }
here anchortag.java:
package com.mycompany.struts.components; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import org.apache.struts2.components.component; import com.opensymphony.xwork2.util.valuestack; public class anchortag extends org.apache.struts2.views.jsp.ui.anchortag { private static final long serialversionuid = 5811285953670562288l; protected string token; public component getbean(valuestack stack, httpservletrequest req, httpservletresponse res) { return new anchor(stack, req, res); } protected void populateparams() { super.populateparams(); anchor anchor = ((anchor) component); anchor.settoken(token); } public void settoken(string token) { this.token = token; } }
here a-close.ftl:
<#-- /* * ... */ --> <a<#rt/> <#if parameters.id?if_exists != ""> id="${parameters.id?html}"<#rt/> </#if> <#if parameters.href?if_exists != ""> href="${parameters.href}"<#rt/> </#if> <#if parameters.tabindex??> tabindex="${parameters.tabindex?html}"<#rt/> </#if> <#if parameters.cssclass??> class="${parameters.cssclass?html}"<#rt/> </#if> <#if parameters.cssstyle??> style="${parameters.cssstyle?html}"<#rt/> </#if> <#if parameters.title??> title="${parameters.title?html}"<#rt/> </#if> <#include "/${parameters.templatedir}/simple/scripting-events.ftl" /> <#include "/${parameters.templatedir}/simple/common-attributes.ftl" /> <#include "/${parameters.templatedir}/simple/dynamic-attributes.ftl" /> >${parameters.body}</a>
Comments
Post a Comment