Category Archives: Flex

Numeric null check on java server side failing with Flex BlazeDS AMF channel


One of the entities developed had a Numeric field as primary key, with a custom code to populate it rather than utilizing any auto generation strategy of JPA

if(ledegrHead.getLedgerHeadId()==null){
ledegrHead.setLedgerHeadId(financePersistence.getNextLedgerHeadId());
}

I wrote junit to test this and obviously it passed -if ID was set to null it would generate an ID.
But the moment I integrated it with flex, things went bad and it would NOT generate the expected “First” ID.
Reason – I had used autobinding on flex side –

[RemoteClass(alias="com.school.questionbank.Question")]
[Bindable]

This resulted in “auto” initialization of integer filed to zero and hence the condition of ==null would always fail. Solution? -explicit check for null as well as zero:

if(ledegrHead.getLedgerHeadId()==null||ledegrHead.getLedgerHeadId()<=0){
ledegrHead.setLedgerHeadId(financePersistence.getNextLedgerHeadId());
}

All of sudden build failing in FLEX -Problem: failed to create task or type mxmlc


I upgraded JAVA version and after that all of a sudden FLEX project stopped compiling. It started throwing following errors:

C:\workspace\CSB_d3csb52\Source\build.xml:93: Problem: failed to create task or type mxmlc
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

I spend quite a time fixing this issue, so decided to put it here so that some one else might find it and save time -I found two reasons at two different occasion for this:

  • If it’s a ant script build, verify in the build.properties that SDK location is specified appropriately.
  • Open flex build setting (right click build.properties and select properties). On JRR tab, make sure that build is set to run in same JVM as flex. If it’s configured to run in separate JVM, then also this issue is encountered
  • Select same JVM for compiling

    Leveraging factory pattern for UI components in Flex


    Using Factory method for UI components is always a good Idea. This helps adding common look/feel, validation etc. to a set of similar component at centralized place.
    For example:

    • Text box for price input with custom requirement (as only two decimal places, in a given range, a custom look and feel etc.) can appear on multiple pages
    • Standard stuff as email entry boxes can have similar custom requirement

    There are two approaches to deal with above

    1. One argument that most of validation is standard and out of box these day (Email, Date) while css and styling can be leveraged from a shared location, so these can be done “in place”. But greatest flip side I see that any change, say decimal precision from 2 places to 3, color change, background image change etc., will have to be tracked at multiple pages, even if just a reference change (CSS name, Validator name etc).
    2. Factory approach -I can have a method as
      UIElement getATextBoxWith2PlaceDecimal(){
      }
      

      This can encapsulate all validation and custom requirements.

    I tend to use factory If I see repeatation on lot of pages -it seems to be a cleaner and maintainable approach.