Ok, I solved it finally. The solution is quite simple, but the way to there
was rocky :)

I found the base of the solution here:

http://www.webdeveloper.com/forum/showthread.php?t=172865

Including the Javascript in the final posting enables every link in the page
to get programmatically "clicked". From the onKeyUp event handler I return a
JSONObject wich contains the id of the the ActionLink to be used

In the onCompleteCallBack of the onEvent mixin from chenillekit I trigger
the ActionLink and the grid updates itself just fine. Below the relevant
parts of the template and the class. These are not generalized in any way,
since I just wanted to get it working first.

**************************************************************************
The page tml:

<div>
    <form t:type="form" t:id="filterForm">
        <t:textfield t:id="filterfield"
                     t:mixins="ck/onEvent"
                     event="keyup"
                     onCompleteCallback="onFilterFieldCompleteFunction"/>
    </form>
    <a t:type="eventlink" t:id="updateGrid" zone="filterZone"/> <!--Invisble
Link-->
    <t:zone t:id="filterZone">
        <t:delegate to="filterBlock"/>
    </t:zone>
</div>
<t:block t:id="filterBlock">
    <table t:type="grid"
           t:id="filterGrid"
           source="displayList"
           row="currentProduct"
           exclude="version"
           reorder="id,alias,name,price,created,lastchange"
           inPlace="true">
    </table>
</t:block>

<script type="text/javascript">
    function onFilterFieldCompleteFunction(response)
    {
        document.getElementById(response.actionLinkId).click();
    }
</script>

**********************************************************

The class:

@IncludeJavaScriptLibrary("context:js/util.js") // This contains the snippet
from above mentioned forum.
public class ProductList
{
    @Inject
    @Service("dynamicDao")
    private DynamicDao dao;

    @Inject
    private Logger log;

    @Property
    @Persist
    private List<Product> productList;

    @Property
    @Persist
    private List<Product> displayList;

    @Property
    private Product currentProduct;

    @Property
    private String filterField;

    @Inject
    @Property
    private Block filterBlock;

    Object setupRender()
    {
        if (productList == null)
        {
            productList = dao.getAll(Product.class);
            displayList = productList;
        }
        return null;
    }

    @OnEvent(component = "filterfield", value = "keyup")
    Object onKeyUpFromFilterField(String context)
    {
        context = context.toLowerCase();

// The filtering is very simplistic. There are certainly better ways to do
it. Especially with large datasets.

        List<Product> newList = new ArrayList<Product>();

        for (Product p : productList)
        {
            if (p.getAlias().toLowerCase().contains(context)
                    || p.getName().toLowerCase().contains(context))
            {
                newList.add(p);
            }
        }
        displayList = newList;

        return new JSONObject().put("actionLinkId", "updateGrid");
    }

    Object onUpdateGrid() throws IOException
    {
        log.debug("In onUpdateGrid event");
        return filterBlock;
    }
}

Reply via email to