Tuesday, November 28, 2006

How to issue a query from simple methods?

I am tasked with what seems like a simple form: 20 checkboxes based on a database lookup that updates a different database table.

So, first step is to see if I can create a simple method that gets me a list of maps that represents all of the rows in my table. Gotta stop saying "table". Tables are called entities in OFBIZ. The entity is Pmu and contains the fields PmuId, ecmId, and label.

Simple question. How do I do a query " Select * from Pmu " ?
the closest thing to a sql query is something called entity-condition:
<simple-method name="getPmus" description="get pmu list">
<entity-condition name="Pmu">

so, how do I do something like " Select * from Pmu where ecmId = 5 " ?

<simple-method name="getPmus" description="get pmu list">
<entity-condition name="Pmu">
<condition-expr name="ecmId" env-name="parameters.ecmId" operator="equals">

where in the heck does the parameters object come from?
well, in this documentation of minilang, it states that by default, the incoming context will be mapped to the "parameters" variable. Nice. So ecmId will come in with the context and everything will be fine.

After I add the above code to simple-methods.xml, I will have available to me a List object containing a bunch of objects of type Pmu. In my next post I will try and make use of those Pmu objects in my form widget!

No comments: