T 5.3.2 ajaxform中的动态按钮

时间:2012-03-30 10:08:21

标签: tapestry

更新到Tapestry 5.3.2后,我的@ActivationRequestParameter不再有用了..

有这样的表格

<t:zone t:id="formZone" id="formZone" t:update="show">
    <form t:id="ajaxForm" t:type="form" t:zone="formZone" style="border: 2px solid #eee; padding: 15px">

        <input type="submit" id="sub" type="submit" value="Accept"/><br/><br/>

        <t:errors/>

        ${form}

    </form>
</t:zone>

试图像这样抓住输入的id

@ActivationRequestParameter("t:submit")
private String submitter;

void onSuccess() {
    logger.debug("onSuccess ," +submitter);

    if (request.isXHR()) {
        ajaxResponseRenderer.addRender(formZone);
    }
}

给我错误

org.apache.tapestry5.runtime.ComponentEventException
Input string '["sub","sub"]' is not valid; the character '[' at position 1 is not valid.

org.apache.tapestry5.ioc.internal.OperationException
Input string '["sub","sub"]' is not valid; the character '[' at position 1 is not valid.

java.lang.IllegalArgumentException
Input string '["sub","sub"]' is not valid; the character '[' at position 1 is not valid.

过滤堆栈帧堆栈跟踪

    org.apache.tapestry5.internal.services.URLEncoderImpl.decode(URLEncoderImpl.java:144)
    org.apache.tapestry5.internal.transform.ActivationRequestParameterWorker$2.handleEvent(ActivationRequestParameterWorker.java:128)
    org.apache.tapestry5.internal.services.ComponentInstantiatorSourceImpl$TransformationSupportImpl$1$1.invoke(ComponentInstantiatorSourceImpl.java:443)

期望的行为

实际上我的目标是能够通过

动态获取提交输入
<t:outputraw value="buttonHtml"/> 

public Object getButtonHtml(){

    ContentType contentType = new ContentType("text/plain");//responseRenderer.findContentType(this);
    MarkupWriter writer = factory.newPartialMarkupWriter(contentType);


    if(isFavorite){
        writer.element("input").attribute("type", "submit").attribute("class", "sButton")
        .attribute("id", ACTION_REMOVE).attribute("value", messages.get("button_removeFavorite"));
        writer.end();
    } else {
        writer.element("input").attribute("type", "submit").attribute("class", "sButton")
        .attribute("id", ACTION_ADD).attribute("value", messages.get("button_addFavorite"));
        writer.end();
    }


    return writer.toString();
}

热烈欢迎任何提示:D

2 个答案:

答案 0 :(得分:1)

我不知道为什么你可能想要使用原始输出创建一个按钮? 至少看看文档并制作一个custom component

查看Checklist组件的来源。它构建了一个可渲染对象列表( availableOptions 列表),然后在循环中呈现它们(如清单模板中所示)

此外,将输入按钮变为tapestry submit button至少应解决错误。

答案 1 :(得分:0)

使用

@Inject
private Request request;
..request.getParameter("t:submit");

为我做了伎俩