• 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

automation and code factoring with struts

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,
In my webapplications there are many html page with
the similar look and structure. I am trying to factor
out them. So I created utility functions to print out
html code to the jspWriter. But I am not able to
incorporate struts tags into these functions because
they will just be printed without being rendered
through the struts engine.
So if I print <struts:radio .../> to jspWriter it will come out
like <struts:radio.../> without any change.
On the other hand if I don't incorporate struts tags
into my utility functions and use just plain html
code, I don't get to take the full advantage of struts
tags.
How do I get around this problem?
thanks
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jonathan,
You are correct that you can't have tags within tags. Don't know if this is the best way, but I factor the common code into a .jspf (JSP fragment) and jsp:include it in.

The latest version of JSP allows you to use this approach for taglibs as well, so it will get less awkward when we upgrade to this.
 
jonathan Greens
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeane,
thank you for the suggestion. However I am trying to do something different, maybe an example will elaborate. I have a utility function printTable1 that I want to use to print different tables because the tables in my jsps share a lot of common structures. Are you suggesting that I might create custom taglibs to do it with the latest jsp?
 
Jeanne Boyarsky
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jonathan,
I still think that should go in a jspf. Once it's there, you can work on converting some of the java to struts logic tags or JSTL.
 
jonathan Greens
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeane,
even in a jspf, can I have nested tags like this?
<html:<bean:write name="type"/> property=""/>
sorry can you elaborate a little? what's your approach on factoring the code so that it can accept parameters and act as a template.
thank you!!
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jonathan,

With the obvious exception of custom tag implementation classes, there would have to be very compelling reasons to render HTML using Java code. As such, I would seriously question the appropriateness of what you are doing. HTML markup should be in JSPs, not in Java code.

I usually use Tiles to factor out common markup elements. If you are not using Tiles, use jsp:includes. Any kind of iteration or dynamic rendering such as rendering rows of data in tables would be accomplished with JSTL.
 
Ranch Hand
Posts: 111
Mac Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by jonathan Greens:
Jeane,
thank you for the suggestion. However I am trying to do something different, maybe an example will elaborate. I have a utility function printTable1 that I want to use to print different tables because the tables in my jsps share a lot of common structures. Are you suggesting that I might create custom taglibs to do it with the latest jsp?




Hi,

I'm not sure if this is going to help or not, but give it a try,

the method is a utility method. So you can create a new tag library using this, and in your Tag class you can call this method. I'm writing a small example to do that below:

//SomeUtility.class
// a static Method like your method

//TagClass
in doStatrtTag call SomeUtility.aMethod()

//a tld file
<tag>
<name>test</name>
<tagclass>TagClas</..>
some attributes
</tag>

in jsp you can use this like
<prefix:test />

I'm using this type of approach for creating some fields on my jsp. If you need to display some static text you can use the same thing. Just write different methods for each section you want to display on the page.

sorry for bad english.
 
jonathan Greens
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you! I will try the custom tag library approach... if this wont' work, someone please let me know before i die trying
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would only take the taglib approach if the html tables were to display read-only data.

Your example requires editable fields, so I would use static includes. I would choose static includes over tiles because it might get difficult trying to reference the proper ActionForm through the tile, since it might have a different name on different pages. With static includes, your Struts tags should not need a name attribute.
 
jonathan Greens
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks you!

But static include can not allow me to include parameter types other than String, right? So if I have a table of content(2d Vector) that I want to pass it, i have to break it down individually as include parameters? So is it better off using tiles because put allow me to input arbitray types?
 
jonathan Greens
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Junilu,
You are absolutely right! I should not use java code. I will use either jsp:include or tiles.
thank you!!
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by jonathan Greens:
thanks you!

But static include can not allow me to include parameter types other than String, right? So if I have a table of content(2d Vector) that I want to pass it, i have to break it down individually as include parameters? So is it better off using tiles because put allow me to input arbitray types?



With static includes, you would write it exactly the way it would be if you just put the tags directly into the pages themselves. That's what static includes do - they insert the included .jsp before anything gets rendered and then renders the whole thing together.
 
reply
    Bookmark Topic Watch Topic
  • New Topic