Announcement

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

    FormItemValueFormatter.formatValue called multiple times

    In v8.3p_2012-11-27/PowerEdition Deployment (built 2012-11-27)

    TextItem's FormItemValueFormatter.formatValue() was called just once for the field

    ds.xml
    Code:
    <field name="roles">
    hibernate bean
    Code:
    @ManyToMany(targetEntity = Role.class, fetch = FetchType.LAZY)
        @JoinTable(name = "userrole", joinColumns = @JoinColumn(name = "UserID"),
                inverseJoinColumns = @JoinColumn(name = "URID"))
        public List<Role> getRoles()
        {
            return roles;
        }
    
        public void setRoles(List<Role> roles)
        {
            this.roles = roles;
        }
    I was formatting incoming array accordingly.

    Now in v8.3p_2012-12-04/PowerEdition Deployment (built 2012-12-04)

    formatValue is called multiple times for each member of an array.

    Before
    Code:
    JSOHelper.convertToJava(value) = {java.util.ArrayList@9297} size = 14
    [0] = {java.util.LinkedHashMap@9299} size = 4
    [1] = {java.util.LinkedHashMap@9300} size = 4
    [2] = {java.util.LinkedHashMap@9301} size = 4
    ...
    After
    Code:
    JSOHelper.convertToJava(value) = {java.util.LinkedHashMap@9234} size = 4
    [0] = {java.util.LinkedHashMap$Entry@9237}"id" -> "3"
    [1] = {java.util.LinkedHashMap$Entry@9240}"desc" -> "Право на просмотр протокола операций"
    [2] = {java.util.LinkedHashMap$Entry@9243}"name" -> "R_OPERATIONS"
    [3] = {java.util.LinkedHashMap$Entry@9246}"group" ->  size = 3
    Is this a premanent change or a bug?
    Last edited by vostapenko; 4 Dec 2012, 08:09.

    #2
    Permanent change - actually a bugfix - with an array as the underlying value, there would be no way to correctly use a formatter/parser pair to round-trip the value unless calls are made for individual items.

    Comment


      #3
      Is there a simple way to overcome this?

      I need to see "10 records chosen" inside a TextItem, before the fix it was as simple as JSOHelper.convertToArray((JavaScriptObject) value).length inside the formatter.

      Now the field shows ", , , , , , , , , , , , ," even if i return null from it.
      I can get the count of records with record.getAttributeAsRecordArray(item.getName()).length, but then i have "10 records,10 records,10 records,10 records,10 records,10 records".

      Probably i can format just first item comparing value with record.getAttributeAsRecordArray(item.getName())[0]. But it requires smartgwt not to concat null values to ", , , , ,".

      Anyway, the idea of formatting every chosen record is not good for me when a couple of thousand records is selected.
      Last edited by vostapenko; 4 Dec 2012, 14:57.

      Comment


        #4
        I've implemented this behavior using CanvasItem and

        Code:
        addShowValueHandler(new ShowValueHandler()
                {
                    @Override
                    public void onShowValue(ShowValueEvent event)
                    {
                        Object value = event.getDataValue();
        
                        StringBuilder result = new StringBuilder("chosen ");
                        int count = 0;
                        if (value != null && value instanceof JavaScriptObject)
                        {
                            Object[] valueMembers = JSOHelper.convertToArray((JavaScriptObject) value);
                            count = valueMembers.length;
                        }
        
                        result.append(count);
                        textItem.setValue(result.toString());
                    }
                });
        Don't know, whether it's the easiest approach, but it works.
        Last edited by vostapenko; 5 Dec 2012, 10:24.

        Comment

        Working...
        X