You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Otho <ta...@googlemail.com> on 2009/02/10 22:55:40 UTC

Re: [T5] Something like GlazedLists for T5?

I tried different approaches now.
The smartclient widgets do exactly what I want, but since I have no
experience whatsoever with GWT and learning 2 new frameworks is
unfortunately beyond my resources at the moment, I want to stick with Tap5.

But how can I trigger an update of the grid component after filtering the
list?

I use the OnEvent(keyup) mixin on the textfield and filter the list which is
used for the grid instead. With a full page refresh everything works as
intended, but I want the grid to update itself on typing. As far as I can
see there is no possibility to do so, but still something is nagging me
along the lines that I didn't see something obvious.

Any hints would be appreciated.

Regards,
Otho

2009/1/27 Otho <ta...@googlemail.com>

> Thanks for all the info!
>
> Again a lot to read up and try out :)
>
> Regards,
> Otho
>
> 2009/1/27 Robert, Brice <Br...@alliancebernstein.com>
>
> I also use T5 grid and its Ajax feature, by static I meant fixed number
>> of rows retrieve with GridDataSource (using Pager). I really like this
>> T5 feature since in T4 I had to create my own component to allow data
>> pagination through JPA/Hibernate.
>>
>> Lazy rendering doesn't need a Pager widget, scrolling through the page
>> using arrows retrieves the back end data.
>>
>> SmartClient has more Grid Ajax features that my customer wanted
>> yesterday that I don't have the time to develop :(
>>
>>
>> -----Original Message-----
>> From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com]
>> Sent: Tuesday, January 27, 2009 2:44 PM
>> To: Tapestry users
>> Subject: Re: [T5] Something like GlazedLists for T5?
>>
>> Em Tue, 27 Jan 2009 15:34:57 -0300, Robert, Brice
>> <Br...@alliancebernstein.com> escreveu:
>>
>> > but I am mostly at the beginning and I must be sure if fits my need
>> > since SmartGwt uses lazy rendering compare to T5 grid wich uses static
>> > pagination.
>>
>> Tapestry's Grid, with its inplace parameter set to true, loads data via
>>
>> AJAX. If you pass a GridDataSource to the Grid, instead of a list, only
>>
>> the objects that are going to be shown now are retrieved. If this is
>> dynamic pagination, please enlighten me. :)
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Independent Java consultant, developer, and instructor
>> http://www.arsmachina.com.br/thiago
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>> -----------------------------------------------------------------------------------
>> The information contained in the linked e-mail transmission and any
>> attachments may be privileged and confidential and is intended only for
>> the use of the person(s) named in the linked e-mail transmission. If you
>> are not the intended recipient, or an employee or agent responsible for
>> delivering this message to the intended recipient, you should not
>> review, disseminate, distribute or duplicate this e-mail transmission or
>> any attachments. If you are not the intended recipient, please contact
>> the sender immediately by reply e-mail and destroy all copies of the
>> original message. We do not accept account orders and/or instructions
>> related to AllianceBernstein products or services by e-mail, and
>> therefore will not be responsible for carrying out such orders and/or
>> instructions. The linked e-mail transmission and any attachments are
>> provided for informational purposes only and should not be construed in
>> any manner as any solicitation or offer to buy or sell any investment
>> opportunities or any related financial instruments and should not be
>> construed in any manner as a public offer of any investment
>> opportunities or any related financial instruments.  If you, as the
>> intended recipient of the linked e-mail transmission, the purpose of
>> which is to inform and update our clients, prospects and consultants of
>> developments relating to our services and products, would not like to
>> receive further e-mail correspondence from the sender, please "reply"
>> to the sender indicating your wishes.  Although we attempt to sweep
>> e-mail and attachments for viruses, we will not be liable for any
>> damages arising from the alteration of the contents of this linked e-mail
>> transmission and any attachments by a third party or as a result of any
>> virus being passed on. Please note: Trading instructions sent
>> electronically to Bernstein shall not be deemed accepted until a
>> representative of Bernstein acknowledges receipt electronically or by
>> telephone. Comments in the linked e-mail transmission and any
>> attachments are part of a larger body of investment analysis. For our
>> research reports, which contain information that may be used to
>> support investment decisions, and disclosures, see our website at
>> www.bernsteinresearch.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>

Re: [T5] Something like GlazedLists for T5?

Posted by Otho <ta...@googlemail.com>.
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;
    }
}

Re: [T5] Something like GlazedLists for T5?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Make sure all your Ajax requests have the header "X-Requested-With" =
"XMLHttpRequest". Tapestry most probably will think that requests
without that header are traditional HTTP requests and then it doesn't
allow you to return a Block or Zone in an event handler method.

-- 
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Something like GlazedLists for T5?

Posted by Otho <ta...@googlemail.com>.
If I trigger an event or redirekt to an eventlink in the page class, the
event handler method is obviously not allowed to return a Block.

The code below doesn't work, though the onUpdateGrid is called.

When I comment the lines from "Link..." to "response..." out and click an
eventlink on the page the same eventhandler gets called and it does update
the grid in the AJAX way without any problem..

Is there any way to trigger an EvenLink or ActionLink programmatcally, so
that the eventhandler method is allowed to return a Block?

The stacktrace yields this as cause:

Caused by: java.lang.RuntimeException: A component event handler method
returned the value Block[filterBlock within products/ProductList, at
classpath:de/kcv/jbookz/pages/products/ProductList.tml, line 67, column 29].
Return type org.apache.tapestry5.internal.structure.BlockImpl can not be
handled.  Configured return types are java.lang.Class, java.lang.String,
java.net.URL, org.apache.tapestry5.Link,
org.apache.tapestry5.StreamResponse, org.apache.tapestry5.runtime.Component.

Code:
    @OnEvent(component = "filterfield", value = "keyup")
    void onKeyUpFromFilterField(String context) throws IOException
    {
        ..... (Here the filtered list is constructed)

        Link c = resources.createEventLink("updateGrid");
        c.addParameter("zone", "filterZone");
        response.sendRedirect(c);
    }

    Object onUpdateGrid()
    {
        log.info("In update Grid Event");
        return filterBlock;
    }