Java’s String.format() in JavaScript

For a recent project I needed to use Java’s excellent String.format() in JavaScript. I couldn’t find a implementation that did this, so I decided to try and port it from the OpenJDK sources. In case you are interested, please see my github project:

Currently, all formatting flags are supported. Conversion from integer, long, double and all kinds of dates are implemented. Not implemented is conversion to scientific format, hexadecimal and some other stuff, although it is quite straight-forward to implement the latter.



Inside WDK DocbaseObject

Last days I’ve been struggling with the dmfx:docbaseobject in the wdk 5.3.

Because I wanted more control on the layout of the attributes, I choose to create the attributes one by one in the jsp, instead of using the attributelist.


<dmfx:docbaseobject name='current_document' />                        
<dmfx:docbaseattribute name='attr_obj_id' object='current_document' attribute='r_object_id'  col1="</td><td>" />
<dmfx:docbaseattribute name='attr_medewerkercode' object='current_document' attribute='medewerkercode' size='12' col1="</td><td>" />

This piece of code resides in a component-page. I have created a button that refreshes the page and changes the docbaseobject’s id. When re-rendering, the old values of the attributes remain on the page. This has to do with the internal workings of the DocbaseAttributeValueTag.

The problem lies in the renderEnd code, which does something like this:           

DocbaseAttributeValue value = (DocbaseAttributeValue) getControl();
  strValue = value.getValue();
  if(strValue == null)
    IObjectAdapter objectAdapter = obj.getObjectAdapter();
    if(objectAdapter != null)
      strValue = getValueFromObjectAdapter(objectAdapter);
    } else
      strValue = getValueFromDocbaseObject();
    bGotDisplayValuesForRepeatingAttr = true;

It acutally reads the value directly from it’s control class. But once the value inside the control class gets set to somethinh other than null, the object is no longer updated.

This is how I worked around it.

I created a extra boolean value “m_reloadFromDocbase” in the control class and in the DocbaseAttribute class, and added these lines in the renderEnd

   if (value.getReloadFromDocbase())
      strValue = null;

This ensures the value of the attribute will get reloaded from the docbase.

In the behaviour class that handles thes jsp, the render-code is a little extended:

                DocbaseAttribute dat = (DocbaseAttribute) getControl( "attr_" + attribute, DocbaseAttribute.class );
                dat.setReloadFromDocbase( true );

The attribute comes form analyzing the page, using a FindValidAttribute visitor. If the boolean is set to false, the filled-in value will remain.

If you are interested in more detail, please dorp me a line [still figuring out howto]