简体   繁体   English

Tapestry5 Ajaxformloop限制行数

[英]Tapestry5 Ajaxformloop limit number of rows

I am trying to limit the number of rows that a user can add in an ajaxformloop. 我试图限制用户可以在ajaxformloop中添加的行数。

Short example: 简短的例子:

For example, the loop found in the tapestry 5 documentation here: http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/corelib/components/AjaxFormLoop.html 例如,在tapestry 5文档中找到的循环: http//tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/corelib/components/AjaxFormLoop.html

If for example I would only like the user to be able to enter 3 phone numbers, how can that be done? 例如,如果我只希望用户能够输入3个电话号码,那该怎么办呢?

What I have tried: 我尝试过的:

1) I tried returning null from the onAddRow event, this causes an exception and the exception report page to display - these events shouldn't return null I don't think. 1)我尝试从onAddRow事件返回null,这会导致异常和异常报告页面显示 - 这些事件不应该返回null我不认为。

2) I tried adding my own add row button like this: 2)我尝试添加我自己的添加行按钮,如下所示:

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

And then putting at:if around it, like this: 然后把它放在:如果它周围,像这样:

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

In this case, the "add another" reverts to the default "Add row" button and my add row link doesn't show. 在这种情况下,“添加另一个”将恢复为默认的“添加行”按钮,并且我的添加行链接不会显示。

3)I tried moving that t:if inside the , this had similar results. 3)我试着移动它:如果在里面,这有类似的结果。

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

I am sure that this is a fairly common aim, is there any simple way to do it? 我相信这是一个相当普遍的目标,有没有简单的方法呢? Perhaps someone can provide an example, and if possible this can help to go in the documentation as i'm sure i'm not going to be the only one trying to do this. 也许有人可以提供一个例子,如果可能的话,这有助于进入文档,因为我确信我不会是唯一一个尝试这样做的人。

Note: I did also ask on the T5 users mailing list and had one answer but I can't seem to get it working after the response from Lance (Which I am sure is probably correct, but i'm not sure how to use the AjaxResponseRenderer as per my reply last week, this is probably due to my own technical limitations or understanding of some parts of T5). 注意:我也在T5用户的邮件列表上询问并得到了一个答案,但是在Lance的回复之后我似乎无法让它工作(我肯定这可能是正确的,但我不知道如何使用AjaxResponseRenderer根据我上周的回复,这可能是由于我自己的技术限制或对T5某些部分的理解)。

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

I also tried using ajaxResponseRenderer.addRender as you did in your mailing list code, but it doesn't work because it seems that Tapestry has some problems dealing with updating a component that's busy updating another component . 我也尝试使用ajaxResponseRenderer.addRender就像你在邮件列表代码中所做的那样,但它不起作用,因为看起来Tapestry在处理更新正在忙于更新另一个组件的组件时遇到了一些问题 However, AjaxResponseRenderer also supports execution of JavaScript. 但是, AjaxResponseRenderer还支持JavaScript的执行。 Taking this approach on the AjaxFormLoop example in the docs, specify the addrowlink as follows: 在文档中的AjaxFormLoop示例中使用此方法, addrowlink按如下所示指定addrowlink

<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 right before return phone; 然后在return phone;之前添加以下代码return phone; in onAddRowFromPhones() : onAddRowFromPhones()

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

This example was tested successfully in Tapestry 5.3.7. 此示例已在Tapestry 5.3.7中成功测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM