Includes-Functions in Struts

Discussions

Web tier: servlets, JSP, Web frameworks: Includes-Functions in Struts

  1. Includes-Functions in Struts (3 messages)

    Hello
    Does struts have a tag to include (or call functions)???

    I have the same code in 4 jsps and want to put it on 1 function but looking in the struts documentation i think there is no support to include funtions.

    Thanks

    Threaded Messages (3)

  2. What do you mean by include-functions? Certainly you can use JSP includes with Struts or look at Tiles as a more capable version of this.
    If you mean can you share scriptlets then you cna use the JSP include mechanism for that although if you are going to the bother of using a proper controller framework then you shouldn't really have much Java code in the pages in any case
  3. Includes-Functions in Struts[ Go to top ]

    Hi Fernando-

    I agree that you shouldn't be using that much Java code in the JSP pages, but if you find that you must, this is what I would suggest doing:

    * Create a Java class with the code you need. It should have a no-argument constructor.
    * Use the jsp:useBean tag to expose the class to your JSP as a scripting variable.

    It is probably not a good idea to go too crazy using this technique, but you should find some way to avoid that cut-and-paste antipattern action you've got going on right now.

    For the record, I believe that this is approach is essentially the View Helper pattern.

    HTH,

    P
  4. Includes-Functions in Struts[ Go to top ]

    Thanks a lot!!

    At last i rewrote all the page and now is more like a jsp...