clueless..

2008-07-08
2013-04-29
  • Ati Rosselet
    Ati Rosselet
    2008-07-08

    Ok... just got myself badly stuck. I was trying to implement a way to dyanmically alter the number format used in a current table, and/or change the number format used in a mondrian schema query (dynamicschemaprocessor etc).  Problem is.. well multiple.
    1. there does not seem to be any way to currently alter the formatting of values in cells..
    2. I can't get any setting info back to the dynamicschemaprocessor (i.e replace %numberformat% with '##,##0.00' since there is no session available)
    3. Maybe I'm completely on the wrong track...

    What I'm looking for is a way to change the displayed number format - eg. with .00 or without, and also use that numberformat to change the underlying schema. I can't see

    If I implement an Extension, I get access to the mondrian model.. but I still can't see how I can alter the formatted cell values (that would be a good start), and as far as I can see, no schema access...

    any ideas?  tips of where to start?
    Thanks for any help....
    Ati

     
    • Andreas Voss
      Andreas Voss
      2008-07-08

      You can use the static method RequestContext.instance() everywhere to get access to the http session etc, even in a Mondrian CellFormatter, SchemaProcessor etc. The RequestContext instance is set up by the RequestFilter which is mapped in web.xml, which means this only works if the request was processed by that filter.

      If you can not use RequestContext.instance() for some reason you could create your own java.lang.ThreadLocal to store what you need in the Mondrian SchemaProcessor (but make sure you release the ThreadLocal, otherwise this could lead to memory leaks).

      Regards,
      Andreas

       
      • Ati Rosselet
        Ati Rosselet
        2008-07-08

        Aha! You're a lifesaver... I need to get more accustomed to WCF I guess.  I implemented the numberformat change as a table extension... doing something like this in the build(cell) routine

                   if (!cell.isNull()) {
                        mondrian.olap.Cell mc = ((MondrianCell) cell).getMonCell();
                        String fs = (enabled?selectedFormat:mc.getCachedFormatString());
                        Object val = mc.getValue();
                        if (val instanceof Double) {
                            java.text.DecimalFormat df = new DecimalFormat(fs);
                            ((MondrianCell) cell).setFormattedValue(df.format(val), new FormatStringParser());
                            parent.setAttribute("value", df.format(val));
                        }
                    }

        it seems to work and the formatted values get passed correctly to pdf/xls as well... although I'm pretty sure its not optimal and missing a few not null checks etc...:)  So I have a wcf form where I can set the desired format, and a use/notuse button to enable/disable the extension...  I like it :))

        I'll be looking at the DynamicSchemaProcessor later.. I checked.. RequestContext.instance() does give me access to what I need..  but at 11:30pm.. I'm leaving this for tomorrow :)  The new mondrian cache control is giving me a headache.. and I would LIKE to flush a single measure (all values) when I change the exchangerate given via jpivot, and reread the schema (with the new CalculatedMeasure defined)...   This is fun...

        I tried the selectProperties tag... but it does some odd things with my schemas. If I have time, I'll take a look.  Also, if I can get this numberformat stuff setup properly, I'll send the changes.. it could be useful for some people..

        Cheers , and thanks again.
        Ati

         
        • Andreas Voss
          Andreas Voss
          2008-07-08

          > Aha! You're a lifesaver...

          Thanks, ;-) (blush)

           
          • Ati Rosselet
            Ati Rosselet
            2008-07-09

            ok.. all works... for now... I ended up just getting the table and setting the dirty flag whenever I changed the settings for the numberformat.  I think there should be some listener there that I can attach to the properties of the NumberFormatComponent...   but this works.. and I'm running out of time.

            Similarly will be a currency change fucntion (with customizable exchange rate)....   yay... start with the euro. :)

            Cheers, and thanks for the help.
            Ati