Cal VA
Weblog  
 
July 2010
S M T W T F S
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
<Jun Today Aug>
Search
Topics
Personal Personal
Java Java
Syndicate
Links
Referrers Today
   
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
   
 
 
 
 
 
God Bless America
 
Sunday, September 19, 2004 Bag vs List in Hibernate

Learned a little this weekend - Bag vs List in Hibernate.  I was troubled since i really wanted to have a Java ArrayList in my object so i could index in my jsp and iterate over the list in an update form.  Using a Hibernate Set left me unable to index.  A Hibernate List left the Java ArrayList populated using the primary key - if the keys were 0,1,2,... that would have been ok.  But i only needed a few items from the database in my ArrayList and since the Hibernate List maintains the position of the object in the ArrayList equal to the position in the database the technique was leaving holes in my ArrayList of nulls.  Of course this was not what i wanted.  Now this may be explained in the documentation but after reading it twice i did not fully understand the Hibernate List.  Over the weekend i read the book Hibernate in Action and discovered the Hibernate Bag and it solved my problem.  I can use a Java ArrayList that is loaded simply by adding new objects to the beginning of the ArrayList.

posted at 1759 hrs   | Comments [0]


Saturday, November 15, 2003 Tomcat 5 missing logging JAR

A follow up to the last post.  In configuring a new system I discovered that Tomcat 5.0.14 needs to have the commons-logging-api.jar added to the common\lib directory.  Without it Jasper would not start the org.apache.jasper.JspC class in the jasper2 target.  For some reason Tomcat 5 does not ship with the logging jar.

posted at 2032 hrs   | Comments [0]


Friday, October 31, 2003 Tomcat 5.0 Precompile with Struts and Tiles

Adding precompiled jsps with Tomcat 5 is actually pretty easy to bring into the build process.  First the environment - I was trying to precompile jsps built on Struts 1.1 and Tiles.  My previous attempts in Tomcat 3 were foiled by the complexity of the process.  In Tomcat 5 the documentation provides a good example of setting up the Jasper 2 compiler to precompile your application.

The key is to create the exploded WAR and then invoke the jspc and javac on that structure.  Since they both need all the classes, libraries, and jsps.  My development project structure is below.  The Tomcat example does the precompile on the exploded war in the webapps directory - I use a build directory to pull all the items together prior to making a war file.

First you create the servlets - in following the example I placed them in the WEB-INF directory.  Then you compile the servlets and for me they were compiled into the build/classes directory. Next you need to map all the new servlets to the .jsp requests so I replace a token with the generated_web.xml in my web.xml.  This last step makes the build process automated but means your web.xml is built by ant.  I have not included the compile and war targets.

project
-->src           <-- all .java files

-->build
---->classes     <-- all classes including precompiled jsps
---->WEB-INF 
---->META-INF

-->WebRoot
---->web          <-- html/jsp/css/etc
---->META-INF
---->WEB-INF
------>classes    <-- compiled classes from the project/src the real java classes
------>src        <-- used to store the jsp servlets created in jspc target
------>lib

 <target name="jspc">
  <delete dir="${WEB-INF.dir}/src"/>
 <taskdef    name="jasper2"   classname="org.apache.jasper.JspC" >
  <classpath id="jspc.classpath">
  <pathelement location="${java.home}/../lib/tools.jar"/>
  <fileset dir="${my.catalina.home}/server/lib">
   <include name="*.jar"/>
  </fileset>
  <fileset dir="${my.catalina.home}/common/lib">
     <include name="*.jar"/>
  </fileset>
  </classpath>
 </taskdef>
 
 <jasper2
  validateXml="false"
  uriroot="${WebRoot.dir}"
  webXmlFragment="${WEB-INF.dir}/generated_web.xml"
  outputDir="${WEB-INF.dir}/src" />

</target>
<target name="compilejsp">
 
 <javac  destdir="${build.classes.dir}"
     optimize="off"
     debug="on"
     failonerror="false"
     srcdir="${WEB-INF.dir}/src"
     excludes="**/*.smap">
 
 <classpath>
  <pathelement location="${WEB-INF.dir}/classes"/>
  <fileset dir="${WEB-INF.dir}/lib">
   <include name="*.jar"/>
  </fileset>
  <pathelement location="${my.catalina.home}/common/classes"/>
  <fileset dir="${my.catalina.home}/common/lib">
   <include name="*.jar"/>
  </fileset>
  <pathelement location="${my.catalina.home}/shared/classes"/>
  <fileset dir="${my.catalina.home}/shared/lib">
   <include name="*.jar"/>
  </fileset>
 </classpath>
 <include name="**" />
 <exclude name="tags/**" />
</javac>

    </target>

<target name="compile-jsps" depends="init, compile, jspc,compilejsp">
 <loadfile property="file" srcFile="${WEB-INF.dir}/generated_web.xml"/>
 <copy    file="${ant.template.dir}/web.xml"  
  toFile="${WEB-INF.dir}/web.xml"  filtering="on" overwrite="yes">
  <filterset>
   <filter  token="generated"  value="${file}"/>
  </filterset>
 </copy>  
</target>

posted at 1056 hrs   | Comments [2]


Sunday, August 10, 2003 Tomcat 4.1.27

Just upgraded to Tomcat 4.1.27 because of the enhancements - or fixes - in the release were jk related.  I noticed the ant task for reload was not working and had substituted a stop and start targets - there is now a patch to correct reload on the Tomcat site.  I am also having problems with httpUnit and jwebUnit and compiling jsps with 27 that were not there in 24.  Still working on that one.  It seems ANT related because Tomcat is using ANT to compile the jsp.

posted at 1309 hrs   | Comments [0]


Friday, July 11, 2003 Building Bread Crumbs with Tiles and Struts

Let me preface this with the facts: i am not very technical so there are probably many out there that can do what i am demonstrating in a 'better' manner. I used the ideas from the Tiles creator himself - Cedric Dumoulin (thanks for a great tool) and his advanced manual to create my site. This is a small part of the site demonstrating the use of bread crumbs and Tiles. I love Tiles and probably tend to over use the framework. You will need to download the Crumb.war

There are two techniques used in this app for bread crumb generation. The first is to write a Tiles Action that accesses the Tiles definition and the second is a tag that reads the tiles definition. Both have advantages. Using the Tiles Action you can extend the functionality of the class to provide additional Tiles based services. Using the tag is super easy and reduces the overhead of an additional action class.

The three crumb bars on each page display - from the top - the Tiles Action technique, the default (almost - style class added) crumb tag and the third the crumb tag with a different style class and separator. You have probably already clicked about a figured out how they work - but let me describe the Tiles Action first.

The Tiles Action is triggered by adding a controllerUrl attribute to the definition - in this case i am using controllerUrl="/do/renderCrumb". renderCrumb extends Tiles Action and is called whenever the corresponding Tiles Definition is triggered - this includes any controllerUrl that is in a parent definition. Since i attached the controllerUrl to my base definition it will be called for each page (I only link to definitions). Anyway in the renderCrumb action the Tiles Component Context is read giving us access to the current definition - including all the inherited definitions. So the crumb attributes are accessed as well as the page name attribute. This depends on the crumb link and title attributes following a specific naming convention. Each level of the site must inherit it's definition from it's parent and add a set of crumb attributes incrementing the level number on the end of the attribute.

In the Crumbs Action i extended the ability of the Tiles Action to read and load another attribute (of course this is pretty easy to get directly in the jsp as well). This allows some menu styling based on the current Tiles definition. Some additional things you can do in a Tiles Action is play with the definition - change an attribute or even change the template. For an example of this go to my personal site settings page. Here i change the master template used and the stylesheet based on the user's selection.

Tiles Actions are pretty handy - if you select the portal view each of the little list boxes on the right side of the screen are individual jsps with their own action classes. This allows to each to be used on any jsp and the Action Class for the jsp does not need to know the other tile is there. The little tile can load it's own beans without depending on the page it is included in. Additionally i am using osCache to cache the portal tiles since executing 6 or 7 Action Classes per page is a bit much. The support projects page has all the support projects i am using.

The Tiles Action version displays the root (home) crumb but the Crumb Tag does not - you can modify both. The Crumb Tag needs no attributes if you name your crumb link and title crumblink and crumbtitle. If you are inclined you can change the style, separator character, and names of the crumb attributes in the Tiles definition.xml.

The only "bad" part of all this is - you need to use tiles for your site layout in a structured manner. This may make this technique not right for your site. You could get the crumb definitions from another source in the Tiles Action using a page attribute as a key to a database or xml file.

Again - none of this is original, Cedric provided the code for the Tiles Action and Steve Melzer wrote the tag which i extended.

posted at 0948 hrs   | Comments [0]


Tuesday, June 24, 2003 New Personal Blog

Took a suggestion from Niel Eyde to review the newer version of Personal Blog- wow. I started looking for some source and ideas only two weeks ago and in the last two weeks Personal Blog has really changed. There are some good ideas and Eric is headed in the right direction - moving the HTML to the jsp and Java to the Action Classes. Unfortunately i have already taken the older code and reworked it for my site - so i will continue to improve the code currently running. But i will still watch Personal Blog for great ideas in blog development.

posted at 0822 hrs   | Comments []


Saturday, June 21, 2003 Setting Up a Blogger

To create the blogging section of the site I looked for yet another open source project for code to base my development. I tried both Roller and Personal Blog because they were based on Struts. Roller is quite extensive since it is capable of being set up at a hosting site for several people to use - it is a collection of Struts, Velocity, Hibernate, Castor and others. It was a bit complicated but I may use some of the code.

So I used the code from Personal Blog by Niel Eyde. It is a Struts based weblogger but I changed most of it because it is the opposite design model than the one I use. Most of the java is in the jsp and most the html is in the java - so I wrote my own jsps and am rewriting the Struts action classes. The calendar code is as is - very tough to move the html out of the action class onto the jsp. Also adding DAO objects changing the database layer.

posted at 2107 hrs   | Comments []


Friday, June 13, 2003 Added a Webblog Today

Well I have created a weblog section to the web site - now the real challenge, adding content. I am going to focus on the development of the site in the blog and not many - if any - personal messages.

posted at 2043 hrs   | Comments []


 
 
What's New
02/14 Baileys
02/07 Slideshow
10/20 Wyoming Vaca...
03/30 Mom and Dad ...
11/15 Cal Holman P...

New Pics
Gomez
Tall Flower
Prickly Macro
Ocotillo Up Close
Cholla Blossom

Popular Pics
1 Baileys and Sweet...
2 Sweetpea and a Mo...
3 Sleepy
4 Vacation in Highl...
5 A Christmas Jacket
6 42nd Street Subway
7 Washington Hall -...
8 Sunrise in Manhattan
9 Little Post Office
10 Radio City at Chr...
11 Dinner in Monteverde
12 Sunrise in Manhattan
13 I Can't Believe Y...
14 Salis IT
15 Cozy Fire

Top Page Hits
1 GuestBook
2 ScrapbookSearch
3 blogging
4 SupportProjects
5 PictSearch


    Top Top    
java struts tomcat log4j DTDns MySQL Ant Apache