Skip to main content

Posts

Showing posts with the label xpages

Fixing FontAwesome for Windows 10

I ran into an issue with FontAwesome a few months back, where a NoCache header was being injected at the server and FA was broken for any partial refresh. I convinced the admin to reverse that setting and all was well until last week... We had some users who were not getting any icons to appear. Ever. We tracked it down to a new Windows 10 setting for IE11 which disallows untrusted fonts. Since we do not set security protocols for our users, and there is no chance of ever convincing those admins to change this policy that they explicitly turned on, I had to find a new solution. I did some searching and it turned out to not be too difficult. First, here is the original implementation. The theme: <control> <name>Icon.Search</name> <property mode="override"> <name>tagName</name> <value>i</value> </property> <property mode="concat"> <name>styleClass</name> <value>fa fa-search...

Rows per page selection: Part 2

I was asked to create a control that would allow users to select the number of rows per page in a view/repeat control (the application uses both). It seemed simple at first, but I ran into a few issues that I thought I'd share the solutions to. Problem 2: When the page refreshed, the combobox value always reverted back to the default It turns out that the Integer value stored in the viewScope doesn't get run through the converter back to a string before being compared to options. I needed a way to calculate the option values so that they would be Integers. This is also not the first time I've run into issues where I need a value to be of a different type, and I see questions like this on StackOverflow from time to time. I attempted a few minor things before I realized I needed to break out my old stand-by, the GetMap . The GetMap is just a fake Map implementation that takes the key and transforms it or uses it to look up some other value. In this case, we are doing the f...

Rows per page selection: Part 1

I was asked to create a control that would allow users to select the number of rows per page in a view/repeat control (the application uses both). It seemed simple at first, but I ran into a few issues that I thought I'd share the solutions to. First, lets start at the beginning. I went through the relevant design elements and set row="#{viewScope.tableRows}" , and I created an xp:comboBox with value="#{viewScope.tableRows}" and added items for 20, 30, 50, and 100, and I assigned it an onChange event handler that did a partial execution and partial refresh of a div containing the combo box, pager and the table. Then I started fixing all the problems. Problem 1: The combobox value was a string, but the rows parameter requires an integer. This was causing IllegalArgumentException / java.lang.String incompatible with java.lang.Integer. I added a NumberConverter, but this only slightly changed the exception message to java.lang.Long incompatible with java.lang....

Quick tip: Convert a number to String in EL

I just had a need to do this and a Google search didn't immediately turn up a solution. So I thought for a couple of minutes and came up with this: value="0#{numberVar}" This takes advantage of the way Java auto-converts objects to strings when doing a concatenation. So if your number is 13, Java EL turns this into new String("0"+13), which becomes "013". You can then strip off the leading zero or just parse the string back into a number.

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.

Killing SSJS - Passing a parameter using Expression Language - Part 2

In part 1, I showed how you can expand the DataObject implementation to allow you to pass a parameter to a method and return the result. It's not a perfectly elegant solution, and it has some limitations, but it's a very solid technique and not at all difficult to implement or maintain. But I kept running into roadblocks. What if I have to compute part of the expression? What if I have to get a value based on another parameterized getter? You can't compute part of an EL expression in your EL. So after some research and experimentation, I created the GetMap. This isn't a new concept - it was developed for JSF 1.1 (which is what XPages is built on) but the rest of the world has moved on to JSF 2.0 and so some of these older techniques can be a little tricky to unearth since this hasn't been an issue in the JSF world for years.

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.

Custom Control Design Definition Tricks

I think by now many people are aware of the Design Definition you can set when creating a custom control. Here is a quick refresher if you are not. A design definition simply replaces what you see when you drop the control on an xpage. By default, it shows whatever is in your control, but this property can be used to replace that with: documentation about how to use the control, for example what custom properties mean or other requirements such as using a data source named "document1" A visual short-hand, for example a control could just show <Header Control> instead of everything inside. This is great for minimizing clutter in the designer and it can also speed up the loading/rendering of the xpage in designer. An interactive tool that allows you to drop additional controls inside  There are a couple of advanced features that can be tricky to figure out unless someone shows you. Here is one:

Problem with naming a custom property "size"

I ran into this issue today and thought I'd share: I created a custom control, and for that custom control I created a few custom properties. One of these properties was unfortunately named "size". There isn't any warning that size would be a bad name for a property, but that causes a problem. It causes a problem because compositeData is just a Map, and size is a method of Map. So what you wind up getting for some reason, is the entire javascript array instead of the value you are looking for. Something like this: {size=md, label={columns=2, text=test}, input={dataBinding=null, columns=10}} I haven't tested it, but I suspect it would be the same with properties named values and clear, among others. However, if you rename the size property, everything works just fine.

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.