Dealing with null values in JSF without using tags

I needed to check if a value was null and display something else in a JSF application. Problem is I could not change the backing bean to check for not and provide a different value. That other value was also in the backing bean. I didn’t have conditional tags available such as c:if or c:choose, so I ended up finding a way inside the h:outputText itself.

<h:outputText value=”#{empty obj.name ? obj.other : obj.name}”>

Using empty will check for both null and empty string values. Then it can choose which value using the ternary operator ? inside the value itself. Keeps the code clean, easy to read, and fewer tags to parse. I could have swapped the values and put the word not in front by then that is yet another thing to maintain and parse.

Putting space between things in JSF

Sometimes the simplest things are made difficult due to using a framework. Recently I was asked to put some space around some checkboxes. Normally I would do this in CSS and be done 20 seconds later. I am not allowed to touch the CSS though so I had to find a way to do it with JSF tags. It is simple really, but sometimes it is the simple things that give us a lot of trouble.

<h:outputText value=" &nbsp; " escape="false" />

That is all. You don’t really need the spaces around the html entity for a non-breaking space, but I needed more room. Don’t forget to set escape to false. Otherwise it will show the text on the screen instead of allowing the browser to show the fixed space you were hoping for.

Removing viPlugin from Eclipse

Turns out it is simple but the directions are not so clear on this page.

http://www.viplugin.com/viplugin/?q=node/15

You need to go into your eclipse directory and remove the following so that it is completely gone. It is not enough to just remove the jar file.

  • plugins/com.mbartl.eclipse.viplugin.statusbar_1.0.4.jar
  • plugins/com.mbartl.viplugin.eclipse.layer_1.19.0/
  • plugins/com.mbartl.viplugin.eclipse.help_1.19.0/

Look in the features directory to make sure there is no mbartl jar files there as well.

Restart eclipse and you should no longer be bothered with the popup asking you to pay for a license.

Recreating a sale from the Amazon Fulfilled Shipments Data report

While trying to recreate a sale using the fulfilled shipments report for FBA, , I ran into some trouble with the data they provide. Normally, when a sale has multiple items, you would expect the quantity field to have a value larger than 1. Instead I found that a sale where I sold 6 calendars had 6 different line items. In trying to figure out why I realized that there was much more going on than I expected. My guess is that for this sale in particular, the customer added each calendar separately to the order instead of changing the quantity to 6.

The fields that Amazon includes in the Fulfilled Shipments Data report of concern are:

  • order_id – This is a unique id for each customer order
  • amazon_order_item_id – Refers to an item in the customer order
  • shipment_id – A unique identifier for shipments. An order can be split into multiple shipments.
  • shipment_item_id – An id for the items in an order. Quantities can be changed so this refers to the items in a particular shipment.
  • merchant_order_id – Specified by the seller when requesting a shipment through FBA for a sale not on Amazon.com.
  • merchant_order_item_id – An id referring to an item in the merchant order

When attempting to merge the data back together, dealing with merchant orders is fairly straight forward. There are just the two values and normally the order doesn’t get split. For an Amazon order though, it can get split up, and there can be multiple item_id’s that have the same ASIN, price, quantity, and more. Initially this caused my 6 calendar order to be reported as 1 calendar because every one of the rows in the report looked the same. Another order I had was split into a quantity of 2, and another line with quantity 6, and that sale was being reported as having sold 2 instead of 8.

All 4 values for the order and shipment need to be pulled together to ensure an accurate accounting for everything in the order. To ensure this, I created a unique key across all 6 of these columns in the database table. That let me more easily sum up the quantities, shipping costs, prices, and calculate what the total order cost me, what fees there were, and how much I made. If care is not given to dealing with these 4 different values, then your calculations will be way off for orders that have multiple items.