Tapestry5 Ajaxformloop row limit

I am trying to limit the number of lines a user can add to the ajaxformloop.

A short example:

For example the loop is found in tapestry 5 documentation: http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/corelib/components/AjaxFormLoop.html

If, for example, I would like the user to be able to enter 3 phone numbers, how can this be done?

What I have tried:

1) I tried to return null from the onAddRow event, this will cause the exception page and the exception report to be displayed - these events should not return null, I don't think so.

2) I tried to add my own add row button like this:

<p:addRow>
    <t:addrowlink>Add another</t:addrowlink>
</p:addRow>

      

And then putting t: if around it, like this:

<t:if test="canAddMorePhones()">    
    <p:addRow>
        <t:addrowlink>Add another</t:addrowlink>
    </p:addRow>
</t:if>

      

In this case, "add another" reverts to the default Add Row button and the Add Row link is not displayed.

3) I tried to move this t value: if inside, it produced similar results.

--------------------------

I'm sure this is a pretty general goal, is there an easy way to do this? Maybe someone can provide an example, and if possible this can help with the documentation, as I'm sure I'm not going to be the only one trying to do this.

Note. I also asked the T5 users mailing list and got one answer, but I can't seem to get it to work after the answer from Lance (which I'm sure is probably correct, but I'm not sure how to use the AjaxResponseRenderer as per my answer last week. this is probably due to my own technical limitations or my understanding of some parts of T5).

http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/Ajaxformloop-add-row-link-max-size-tt5730840.html

+3


source to share


1 answer


I also tried to use ajaxResponseRenderer.addRender

as in your mailing list code but it doesn't work because it seems like Tapestry has some issues related to updating a component busy updating another component . However, it AjaxResponseRenderer

also supports JavaScript execution. Using this approach in the example AjaxFormLoop

in the docs, specify addrowlink

as follows:

<p:addrow>
    <t:if test="canAddMorePhones()">
        <t:addrowlink id="addRowLink" t:id="addRowLink">Add another</t:addrowlink>
    </t:if>
</p:addrow>

      

Then add the following code in front return phone;

of onAddRowFromPhones()

:



ajaxResponseRenderer.addCallback(new JavaScriptCallback() {
    public void run(JavaScriptSupport javascriptSupport) {
        if (!canAddMorePhones()) {
            javascriptSupport.addScript("document.getElementById('addRowLink').style.display = 'none';");
        }
    }
});

      

This example has been successfully tested in Tapestry 5.3.7.

+1


source







All Articles