Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom struts2 tag?

Tags:

jsp

struts2

I want to write a custom struts2 tag,which has a separate action class for itself, and can be called from different jsp pages.

Something like:

<s:writetext type="aaa" parentid="xxx" parentname ="yyy" height ="50" width ="125" />

Is it possible? Please help, I'm very new to this and googling about this didn't help.

Thanks, Aditya

like image 816
Aditya R Avatar asked Dec 29 '22 13:12

Aditya R


1 Answers

This old question became also relevant for me this week when reviewing some existing code. Apart from tbruyelle's answer, this was for me the most helpful reference:

http://bodez.wordpress.com/2009/03/13/customising-struts2-jsp-tags/

In summary(1),

  1. Extend an existing tag (for example, org.apache.struts2.views.jsp.ui.TextFieldTag)
  2. Extend its behaviour (for example, org.apache.struts2.components.TextField)
  3. Define new theme and templates (for example, copy and edit from an existing theme in /core/src/main/resources/template)
  4. Generate the new TLD for the customised version of the taglib
  5. Deploy it in a web application

The struts 2 API could also be helpful.

Unfortunately (and surprisingly), there is very little documentation about how to do this, and the javadoc for the existing struts components is "a bit scarce" and misleading. Perhaps it is not intended to be used this way?


Notes

(1) I have edited this answer a few years after the original post to add this summary, aligning the answer with SO guidelines. Unfortunately, it's been a long time without working with similar code, and I cannot be sure to have kept the essence of the linked blog, so please refer to the link if it still works.

like image 51
Alberto Avatar answered Feb 04 '23 04:02

Alberto