Tue, 10 Feb 2009

3:03 PM - Dojo Bug

I've been fighting with Dojo for the last 24 hours over a very stupid bug.  The TextArea widget doesn't appear to work properly with data from an ItemFileReadStore. So setValue didn't give an error, but it didn't put anything in the box either.  Very odd. Here is an excert from the code.  This version works because of the ' ' + .  When that is removed from setValue, the call appears to do nothing.

    function projselect(id)
    {
        var myurl = "admin_invoices_json.php?id=" + dijit.byId('project').valueNode.value;
        //var value = document.forms.frmNewInvoice.project.options[id].value;
        var store = new dojo.data.ItemFileReadStore({url: myurl });
        var newValue = store.fetch(
        {
            query: {project_id: "*"} ,
            onComplete: function(items, request) {                      
                dijit.byId('billingaddress').setValue(' ' + items[0].billing_address);
                dijit.byId('billingperson').setValue(items[0].billing_person);          
            }
        });
    }

<tr>
<td class="formlabel" width="200">Billing Person</td>
<td><input name="billingperson" type="text" id="billingperson" size="45" maxlength="45" value="" dojoType="dijit.form.ValidationTextBox" trim="true" required="true" /></td>
</tr>
<tr>
<td class="formlabel" valign="top">Billing Address</td>
<td><textarea id="billingaddress" name="billingaddress" cols="50" rows="10" dojoType="dijit.form.Textarea"></textarea></td>
</tr>

The JSON

{ identifier: 'project_id', label: 'project_id', items:[{"project_id":"74","billing_person":"Billing Guy","billing_address":"1111 Test St Test County, MI 48108"}]}

tags: bug html dojo json

()

Sat, 30 May 2009

10:14 PM - JSON in Java

I've been using JSON with Dojo Data Grids lately in PHP.  Now, I want to use something similar on this site.  I decided on the json-simple library.  It's actually quite easy to use.

Encoding examples:

http://code.google.com/p/json-simple/wiki/EncodingExamples 

<%@ page contentType="text/json;charset=UTF-8" language="java"%>

<%@ page import="com.justjournal.model.User" %>

<%@ page import="org.apache.cayenne.DataObjectUtils" %>

<%@ page import="org.apache.cayenne.access.DataContext" %>

<%@ page import="org.apache.cayenne.query.SelectQuery" %>

<%@ page import="org.json.simple.JSONObject" %>

<%@ page import="java.util.*" %>

<%@ page import="org.json.simple.JSONArray" %>

<%

    out.clearBuffer();

    SelectQuery query = new SelectQuery(User.class);

    query.addOrdering(User.USERNAME_PROPERTY, true);


    DataContext context = DataContext.getThreadDataContext();

    List users = context.performQuery(query);

    JSONObject obj = new JSONObject();

    JSONArray list1 = new JSONArray();


    Iterator it = users.iterator();

    while (it.hasNext()) {

        Map map = new HashMap();

        User u = (User) it.next();

        if (u.getUsername().length() > 2 && !new com.justjournal.User(u.getUsername()).isPrivateJournal())

        {

            map.put("id", DataObjectUtils.intPKForObject(u));

            map.put("username", u.getUsername());

            map.put("name", u.getName());

            map.put("since", u.getSince());

            list1.add(map);

        }

    }

    obj.put("items", list1);

    obj.put("label","id");

    obj.put("identifier", "id");

    obj.writeJSONString(out);

 

tags: cayenne json dojo java

()