Wednesday, May 6, 2009

Scaled Back Geographic Translator Service

I had to scale back quite a bit from what the sample web client offers for Geographic Translator Service but I think I finally got it all working as a portlet. At least the concept is there now and someone could expand the 5 possible coordinate systems the portlet offers back to the 36 offered by the service if it proves to be a useful portlet.

I had to learn some things about CSS in order to get a dynamic display of the proper input fields needed for whichever coordinate system the user selects from the pulldown. I ended up going back to the method of using separate divs for each group of form fields AND putting a form in each div. That last part is the key concept I missed when I tried doing it that way the first time.

Copying sample code from the Internet when you don't really understand something has its own hazards. In this case, I was copying the example that gave me the clue about the form within the div but it had a lot of extra CSS attributes that the other example didn't have. And my knowledge of CSS is very limited. I can say, though, that after the struggles to get it to work I know more now about CSS than when I started. In particular, the difference between "display" and "visibility" and why to use one rather than the other.

The really amusing CSS goof resulted because the example I started with used absolute positioning, which I didn't know enough about to change. When I thought everything was ready to test out I was about to give up in despair again when I used the pulldown with the onClick and I still didn't see the divs get changed to display the fields of the form. I tried pulling all the code out of the JSP and putting it into a separate HTML file. When I did it that way it would work.

So what was preventing the divs from displaying when the code was part of the portlet?
Suddenly, during one of the display attempts my eyes were drawn to the top of the portal page. I haven't been seeing the top of the portal page for awhile because as the list of finished portlets grows the one I'm currently working on gets pushed to the bottom of the page. But there up at the top, overlaid on the Geoid Height portlet, was the missing div! I thought at first it was an issue with not having used portlet namespace tags and was ready to go back and add all that nonsense like I had to do for the OpenLayers map portlet. But it turned out the problem was with the absolute positioning within the style attribute. Once I removed all of that and let it use the default (position within the normal flow of the page) the problem went away.

There were still other problems to solve, including how to get the correct default values to display for each of the div sets. I think it was during these struggles that I finally had to cut back on all the parameters and quit trying to reuse the same names within each set. I know it's not very efficient to have different variable names for each of the coordinate value fields. There's probably some way to make use of arrays and if this portlet is to grow back up to the scale of offering 36 different coordinate systems that could probably be solved. But for now I think it's OK and it gives the basic sense of what the portlet is doing.

As usual, I've run out of steam when I think of what's left to do for giving it a thorough testing. The challenge I will deal with next is to remove from the project the extra portlet that I had created when I first started Geographic Translator and thought I was going to need a portlet that would allow the user to look up the meaning of the RESTful interface cryptic parameter strings. A couple of weeks ago I had made the mistake of creating a test portlet in the project that I later wanted to delete. Trying to delete and clean up completely what gets created when a portlet is added to the project turned out to be a non-trivial task. I learned from that experience to create a test portlet within a separate test project where I could delete the whole project when the test was done. But now that there's an unneeded portlet in this project I get to go through the "delete and clean" exercise again. There should be an easier way.

No comments: