T5: AppPropertyEditBlocks and @Inject ASO

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

T5: AppPropertyEditBlocks and @Inject ASO

Michael Capper
Summary: I seem to get a different ASO injected in the AppPropertyEditBlocks page than on the rest of my app.


Hi,
in my Database Users may save, amongst others, WeightMeasurements. When the user wants to view or edit the Measurements, I want to display the weight value in the user's preferred unit. I planned on wrapping the Double-Value of the weight in a Weight-object, and to automatically convert all the weight-value into the desired units when rendering the Grid/Bean etc.

for that i contributed following in my AppModule:
    public static void contributeDefaultDataTypeAnalyzer(MappedConfiguration<Class, String> configuration) {
        configuration.add(Weight.class, "weight");
    }
    public static void contributeBeanBlockSource(Configuration<BeanBlockContribution> configuration)
    {
    configuration.add(new BeanBlockContribution("weight", "AppPropertyEditBlocks", "weightEdit", true));
    }


and edited my AppPropertyEditBlocks.tml and .java to contain:
   <t:block id="weightEdit">
        <t:TextField t:id="weightEditField"/>
    </t:block>

    @Inject
    private CurrentSessionASO _currentASO;
    @Component(parameters = {"value=context.propertyValue", "translate=prop:weightTranslator"})
    private TextField _weightEditField;
    @Environmental
    private PropertyEditContext _context;
    public Translator getWeightTranslator()
    {
                System.out.println("Translator get CurrentASO.id="+_currentASO.getRandom());
                Translator transe = new Translator(){
        long userid = _currentASO.getLoggedinUser().getId();
        WeightUnit wu  = _conversionDAO.getWeightUnitFor(userid);

                public Class getType() {
                        System.out.println("Translator KG/LB: "+userid+" "+wu);
                        return Double.class;
                }

                public Object parseClient(String arg0, Messages arg1)
                                throws ValidationException {
                        Double w = Double.parseDouble(arg0);
                        if (wu==WeightUnit.LB)
                        {
                                w = lbTokg(w);
                        }
                        return new Weight(w);
                }

                public String toClient(Object arg0) {
                        Double w = ((Weight) arg0).getKg();
                        if (wu==WeightUnit.LB)
                        {
                                w = kgTolb(w);
                        }
                        return w.toString();
                }
    };
    return transe;
    }
etc.


Well, thing is, when i run my app, and log into my Site as some User, on the pages the users traverses I print out System.out.println("PageSomewhere get CurrentASO.id="+_currentASO.getRandom());
on several pages, just to debug, and they all return the same number, which is created randomly on construction of my currentASO-Object. But when i set the editMode of my bean with the Weight-object  to true, and the page with the editable bean is created, i get a different number. Also the Fields in the _currentASO are back to construction values. This of course results in a NullPointerException :)

Is this behavior, using a different Injected Object as my currentASO, intended? The Class and Template are in the same package as the rest of my app-pages, so i'd assume it ought to get the same Object.

If it is intended, could you hint at a solution to my problem, anybody?

Thanks for your time,
Michael
Reply | Threaded
Open this post in threaded view
|

Re: T5: AppPropertyEditBlocks and @Inject ASO

Michael Capper
My Bad! I Used @Inject for an ASO instead of the usual @ApplicationState... no wonder it did nothing.


Michael Capper wrote
Summary: I seem to get a different ASO injected in the AppPropertyEditBlocks page than on the rest of my app.