Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Advice on handling of variable currency field

    We have a data source that contains a currency code field and a set of decimal values. The decimal values need to be displayed and edited with respect to the currency code for that record.

    A SimpleType with custom display formatters and a customer EditorType sounds like the best approach. But how would the formatters and editors get access to the currency code field?

    We're using SQLDataSource and would prefer it to be something we can specify at the ds.xml level if possible since all forms, ListGrids and other UI components that are used to visualize the field need the same behavior. Something like type="currency" currencyCodeField="curCode" in the field tag.

    #2
    Hi Jay
    The SimpleTypeFormatter should give you access to the field definition when the format method is run - so you could look for the "currentCyCodeField" attribute on the field definiton via getAttribute().
    Similarly, when an editor (FormItem) is generated from a DataSource field definition, the ds field properties should be available directly on the form item via getAttribute().

    Does this give you enough to get going, or are we misunderstanding what you need?

    Comment


      #3
      I thought I would start with a specific implementation and then look for a more generic solution once I understood how all of the pieces worked. When the variable currency field is in a ListGrid I need to use the following to implement the behavior I'm looking for - CellFormatter, CellEditValueParser and CellEditValueFormatter. The EditValue formatter needs slightly different logic so that when the field is editable it won't be formatted with the currency symbol. When the field is on a DynamicForm I need a FormItemValueFormatter and a FormItemValueParser.

      If instead I were to use a SimpleType I think I would need to do the following.

      1) Put the formatting routine into a SimpleTypeFormatter. The format() method gets record as a paramter so I can get the currency code that way. I assume this would take the place of the current CellFormatter, but will it also be invoked in place of CellEditValueFormatter and FormItemValueFormatter?

      2) setEditorType for the SimpleType to a custom subclass of FormItem with a FormItemValueParser for the parsing logic. I can use form.getRecordList().get(0) in this case to get the currency code.

      So I think my only remaining question is, if I want different formatting logic for the EditValue from the normal display only value, is that still possible with the SimpleType approach?

      Comment


        #4
        Sorry for the long pause on this. The answer is that yes it is possible but was not directly wrapped for SmartGWT.
        We've just added wrapper code to allow this all via the SimpleType - as of the next nightly build, SimpleType will support
        - setShortDisplayFormatter
        - setNormalDisplayFormatter
        - setEditFormatter
        - setEditParser
        Which allows you to specify a formatting / parsing pair of functions which will be editing field values in a freeform text item (TextItem or TextAreaitem typically), as well as formatters for short (EG: ListGrid cell) and long (EG DetailViewer) static display.

        Comment

        Working...
        X