Skip to main content

Posts

Showing posts with the label java

Project in Review - Part 3: What didn't work

Of course, not everything was an unmitigated success. I tried many things that didn't work out. Much of which I've removed and forgotten about, but a few things remain - either scarred into my psyche or woven too deeply to fix. What didn't work Storing my entire configuration in application.properties Using properties files is great. It let me get configuration out of a profile document and into something much easier to edit - particularly configuration that users will never see or maintain (and thus there is no need for an interface for). But I took it too far. The paths to the other databases are there, and that's good. But view aliases are also there, and that was a mistake. I already have a ViewDefinition enum that describes each view and all the information I need to know about it. I could have set view names there, but instead I'm reading them from the application config. I can change where a view is pointing without having to go into my code. Except of co...

Project in Review - Part 2: What worked

Here are some of the techniques I adopted that turned out great. I made no claim to innovation or superiority. What worked? PhaseListener: Having a PhaseListener to let me know where I was in the JSF lifecycle was extremely helpful. I used this information constantly to determine the state of various objects at any given time. In fact, as much as I know it's bad technique to troubleshoot via print statements, I found it invaluable to be able to observe the exact order of state changes. That being said, it's important to note that THE CONSOLE LIES! If you see something very unusual happening, like the lifecycle restarting multiple times or events just never finishing - look at the console log. My experience was that what appeared to be going on in the log was not necessarily what was going on, but if it looked crazy it was an indication that something wasn't right. I don't care if you're trying to go pure Java as I did, or pure SSJS - a PhaseListener is a si...

Project in Review - Part 1: Lessons learned

At this point, I think it's fair to call my project a success. So while everything is fresh in my mind, I want to get down things I felt worked very well for me, and things I felt did not, and lessons learned along the way. This is mainly for myself, but if anyone else learns anything, so much the better. Lessons learned the hard way MVC: So trying to adopt MVC was a challenge. It was the first time I'd done it, though I'd read enough I was familiar with the ideas, and I had many mis-starts along the way - some of which got corrected and some didn't. In fact, I could write a whole series of blog posts on lessons learned here - and most of them come from a lot of reading on Java. But if I had to refine it to a single idea, it's "keep your concept clear". I spent a lot of time trying to shoehorn everything into my model classes and I wasn't really clear what belonged in the controller except as something between the model and the front end - which se...

XPages Application Framework (Part 2 of ?)

In my last post, I offered a very rough overview of the framework I've been building and adapting. Full credit where it's due, I've been borrowing and adapting from Jesse Gallagher's XPages Scaffolding - an awesome project that I've learned a great deal dissecting. This is one of those projects that, if you make the effort to truly understand it, will give you entirely new tools and approaches for problems. As usual, I've learned the most changin g things and breaking them. My project differ s f rom Jesse's mostly in that it supports 8.5.3 and doesn't require any relaxed security permissions - bec ause I'm on 8.5.3 and because the admins h ere will not grant any relaxed permissions.

XPages Application Framework (Part 1?)

Note: I changed projects and priorities after my last POI article, resulting in a long hiatus. I anticipate using that framework on my current project and will likely refine and complete my related article series. For the past several months, I've been fortunate enough to lead a project overhaul from traditional Domino Webapp to XPages. I had a few goals in mind, but the top three were integrating Bootstrap, embracing MVC principles, and eliminating all SSJS . I imagine the motivation for Bootstrap integration is self-explanatory. There is an OpenNTF project out there called Bootstrap4XPages. I didn't use that for a number of reasons - the main being a policy in the current environment. But you may ask yourself (if you didn't follow that link), why so much hatred for SSJS? I have a litany of reasons. It impacts readability of the XPage source; it hurts maintainability when logic is scattered across dozens of XPages, custom controls, and script libraries; it mixes log...

POI Spreadsheet Manager - Part 3

Between the holidays and some deadline pressure, it's taken longer to get to this than I'd like. But at last, here it is. This is my CellStyleManager and CellStyles enum. public class CellStyleManager {     public static final int BORDERLOC_NONE = 0;     public static final int BORDERLOC_TOP = 1;     public static final int BORDERLOC_BOTTOM = 2;     public static final int BORDERLOC_LEFT = 4;     public static final int BORDERLOC_RIGHT = 8;     public static final int BORDERLOC_ALL = BORDERLOC_BOTTOM | BORDERLOC_TOP | BORDERLOC_LEFT | BORDERLOC_RIGHT;     public static final int BORDERLOC_SIDES = BORDERLOC_LEFT | BORDERLOC_RIGHT;     public static final int BORDERLOC_TB = BORDERLOC_TOP | BORDERLOC_BOTTOM;     private final Workbook wb;     private final Map<cellstyles cellstyle=""> styleMap;     private final FontManag...

POI Spreadsheet Manager - Part 2

Part 1 was just laying some foundation. Now it's time to tackle some of the more troublesome bits of managing XLSX through POI. The first challenge I wanted to tackle is how to define Fonts and CellStyles. Every time you create one of these elements, it gets added to the .xlsx file, even if it is a duplicate of something you've already created. Also, there is a maximum number of each, so if you create your cells dynamically, you can run out of room to create new cells. You can get around this by first creating your spreadsheet, and then applying styling to groups of cells. Buy my goal was dynamic reports. I want to write a report without knowing what kind of data is going to be in each row or cell.

POI Spreadsheet Manager - Part 1

I've been working on this project for about two years off and on now. Some parts of it shaped up early on, while others have undergone significant refactoring. Most of my reports are in Excel, but some few are done in Word. So I started with a class that accepts any POI XML document and a file name, and sends that file to the browser.

Update to yesterday's non-managed bean post

One difference I've noticed when I create my bean in the XPage rather than having the server manage it, is that a managed bean seems to be created only once, while loading it up in a DataContext seems to execute the constructor multiple times. If you have a somewhat slow bean, like say it is compiling report data, this can be a significant performance hit. In the example I'm working on today, generating report data took 246 seconds as a DataContext and 117 seconds as a managed bean.

Quick Tip: Content-Disposition

I ran into a problem that it took me a few hours to figure out, so maybe I can spare someone the headache. I'm creating a file using POI and streaming it to the browser. It was working great in Firefox, but in Internet explorer if I opened the file instead of saving it, the file name was xAgent_PrintForm.xsp and not the correct Form.docx . If I saved the file, it had the correct file name. Even worse, it had been working fine before and just started happening without any explanation. It turned out to be a header in my response writer.