On Jun 30, 2011, at 9:41 AM, Ruffy Collado wrote:

> 1.    Example I have a password field connected to the datasource and
> datafield in a MySQL table. I also have another field which is a confirm
> password, this one is of course no connected to the datasource. On the OnHit
> method of a button, I called in the self.Form.save(). I did some validations
> on empty fields and it works just like in the tutorial. But I never got the
> way to compare if the two password fields match each other using the
> validateRecord() Method of the Bizobj. By the way, I was following the
> Create application from start tutorial using my own tables. So, how can I
> get the value of the confirm password textbox using the bizobj? Should I
> create another method to validate it, using the Form as the caller of a
> Bizobj method passing the two textboxes values as parameters? Or should I
> just use the self.Application.ui way?


        There are probably many ways of doing this; I would suggest the 
following: add the textbox for the password confirmation to the form, and then 
bind its ValueChanged event to a new handler you'll create on the form. If 
you're using the Class Designer, just add this code to the onValueChanged() 
method of the textbox:

def onValueChanged(self, evt):
    self.Form.setConfirmPassword(self.Value)

        Note that in general, UI controls should be fairly dumb; they don't 
know about bizobjs, databases, etc.; all they know about is their Parent 
container, their Form, and perhaps some sibling controls. So the textbox simply 
tells the form that its value has changed.

        Then add the method to the form:

def setConfirmPassword(self, val):
    self.PrimaryBizobj.confirmPassword = val

        The form knows about its bizobjs, so it sets that attribute of the 
bizobj. You should also initialize that attribute in the bizobj class to an 
empty value. Now your validateRecord() code can simply compare the value of the 
main password field with the 'confirmPassword' attribute to see if they match.

        Is that explanation clear enough? If not, let me know what's confusing 
and I can get into more detail.

> 2.    In CodeIgniter a PHP MVC Web Framework, I use the Model to handle
> all the queries, I write my input and output queries in methods like
> add_new_user(data) and get_selected_members(data). Then this methods pass
> the result of the query or the dataset back to the Controller. That way when
> some SQL guy decides to change my queries for optimization, he can play with
> it while I do the business logic. Is there anyway to this in Dabo? I was
> thinking of using the db Folder as the storage for my Model Classes. Oh and
> I would also like to write my own SQL queries rather than the alchemy
> stuffs.


        While Dabo and MVC both have three "tiers", they work very differently, 
and if you try to approach Dabo with an MVC mindset, you'll probably trip 
yourself up.

        The DB layer in Dabo is essentially an interface to the underlying 
datastore; very little application logic, if any, ever gets written there. The 
business object, or bizobj, is where everything is handled.

        If you have some custom SQL that needs to be executed for specific 
tasks, normally you would use the bizobj's executeSafe() method, passing in the 
desired SQL. If you wanted to keep that SQL code separate from the bizobj code 
so that your SQL guys don't screw it up, you could always create a separate 
file that the bizobj imports, and define your SQL there. Let's say you add the 
file "queries.py" to the db folder; then in your bizobj, you would add the line:

import dabo.db.queries as queries

...and then in your bizobj code, you would write something like:

sql = queries.getSelectedMembersSQL()
crs = self.executeSafe(sql)
members = crs.getDataSet()

        The queries.py file would simply be a series of methods like this:

def getSelectedMembersSQL():
        return "select field1, field2 from mytable"


> 3.    Lastly, for now. Let's say have a table which has a ID, Name,
> Address, Image and Status as fields. Of course I wouldn't show my ID but
> dabo already takes care of this. I would also not show my status field cause
> I update them according to events or user choices. How can I do that in the
> bizobjs? When I call self.Form.save() I won't be able to access it through
> the self.Record.Status cause it is not in the form. Should I use a query in
> the validateRecord to fetch the chosen user? Or could I still access the
> self.Record.Status without it being included in my Form?

        You can (and should) have the column in the bizobj, but simply not 
display it in the UI. It sounds like you are using the AppWizard to create your 
app; in that case, include the status column when running the wizard, and then 
afterwards edit the UI code to remove the display of that column (or set it 
read-only, if that's appropriate). Your bizobj can now reference 
self.Record.status, and can update it accordingly.

> Sorry for the long questions. It may be the most pointless one in the whole
> mail list. I just wanted to clarify these things, it really gets confusing
> when coming from a web app background and a web MVC architecture.

        These are excellent questions; not pointless at all. We deliberately 
chose not to use an MVC architecture because it didn't make as much sense in a 
desktop framework, but having used both, I know how you can easily confuse the 
two when switching back and forth.

        Feel free to ask more questions, or ask for elaboration on any of these 
answers.



-- Ed Leafe



_______________________________________________
Post Messages to: Dabo-users@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: 
http://leafe.com/archives/byMID/67ff0a4e-91c8-4e49-a3b2-694167ae6...@leafe.com

Reply via email to