SetAttribute

1
Hi, I'm trying to set an attribute from a custom widget I'm creating, but I don't seem to be doing it right. I'm trying to look in the documentation and the API docs, but for some reasons I'm finding it really hard to find what I look for and on Google I got nothing as well. For example, this method "mx.processor.getObject();". There is examples on it. Here is how my code looks like: imgObj = mx.processor.getObject(); imgObj.setAttribute("cropHistoryX","1,2"); imgObj.save({ callback : dojo.hitch(this, function (imgObj) { this.afterSave(imgObj); }, imgObj), error : dojo.hitch(this, function (imgObj) { logger.error('Could not save object: '+imgObj); }, imgObj) }); imgObj.commit(); but I'm getting imgObj is undefined. Anyone has any idea? Plus,it would be really helpful if you can guide me to some resources on the net where I can find such simple examples. I have many other questions in mind, but don't seem to know where to get started. Thanks!!!
asked
2 answers
7

Hi Issam

http://apidocs.mendix.com/client/

The method "getObject()" is deprecated since version 3.1, thus imgObj is undefined because mx.processor.getObject() is (evaluates to) undefined.

I usually reference the apidocs link above or this forum as resources.

Also refer to the widget tutorial if you have not already: Widgets - Quick Start

answered
0

Seems your attribute setting is correct (although it's bad practice to hard-code attribute names, you can easily make these configurable). I sugegst replacing setAttribute with the new set(attr, val) for 3.0. You can find all the methods that a Mendix object in the client has here.

You seem to be lacking the object. I'd advise you look at the Quick start that Marlo linked first. Especially this part is good to start with Widget base. These attributes and methods can be used in every widget you make. The startup and update methods are placeholders you can overwrite to start your widget.

I'm assuming you already have a postCreate (the pre-3.0 version) or startup call. This is used to start your widget. You can either start your widget from here, or you can wait for the update() to be called if you require an actual object to work with (make sure to always call the callback at the end).

Side note: the mx.processor.getObject uses multiple arguments and is deprecated since 3.0. You can now retrieve your own objects using mx.processor.get().

answered