Tapestry 5.2 中是否有一些本地方法可以将 eventLink 转换为按钮

发布于 2024-11-30 22:54:12 字数 928 浏览 4 评论 0原文

我的问题很简单。我想使用按钮作为事件链接。

tml 中的表单内部存在基于 AJAX 的事件链接。事件链接具有动态更新表单某些部分的功能:

<t:eventlink t:event="editPlace" t:zone="dialogZone" class="jqModal place editPlace"
 t:context="placeId">${message:editPlace}</t:eventlink>

我希望 eventLink 成为一个按钮,如下所示:

<t:eventButton t:event="editPlace" t:zone="dialogZone" class="jqModal place editPlace"
 t:context="placeId">${message:editPlace}</t:eventButton>

但自然这样的东西不存在。我认为有一些第三方库可以做到这一点,但感觉有点矫枉过正。

我还尝试通过以下方式欺骗 eventLink 用 javascript 触发:

<button type="button" onclick="jQuery(this).next('a').click();">
  ${message:editPlace}
</button>
<t:eventlink t:event="editPlace" t:zone="dialogZone" class="jqModal place editPlace" 
 t:context="placeId">${message:editPlace}</t:eventlink>

正确找到了锚点,但不起作用。还有其他选择吗?

编辑:使问题更清楚。

My problem is simple. I want to use button as an event link.

There exists AJAX-based event link inside a form in tml. The event link has functionality that updates some parts of the form dynamically:

<t:eventlink t:event="editPlace" t:zone="dialogZone" class="jqModal place editPlace"
 t:context="placeId">${message:editPlace}</t:eventlink>

I would like that eventLink to be a button, something like this:

<t:eventButton t:event="editPlace" t:zone="dialogZone" class="jqModal place editPlace"
 t:context="placeId">${message:editPlace}</t:eventButton>

But naturally such thing does not exist. I think there are some 3rd party libraries to do it, but it feels kind of overkill.

I also tried to trick the eventLink to be triggered with javascript in following way:

<button type="button" onclick="jQuery(this).next('a').click();">
  ${message:editPlace}
</button>
<t:eventlink t:event="editPlace" t:zone="dialogZone" class="jqModal place editPlace" 
 t:context="placeId">${message:editPlace}</t:eventlink>

The anchor is correctly found but does not work. Are there any other options?

Edit: Made the question more clear.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不寐倦长更 2024-12-07 22:54:12

如果我理解正确的话,您希望通过单击按钮来更新区域。您不需要任何自定义组件来执行此操作,通常的 FormSubmitZone 组件就可以了。

只需在模板中使用按钮创建一个表单并设置其 zone 参数即可:

<div t:type="Zone" t:id="dialogZone" id="dialogZone" />

<form t:type="Form" t:id="myForm" t:zone="dialogZone" t:context="placeId">
    <input type="submit" t:type="Submit" value="Click me" />
</form>

在页面类文件中,设置事件侦听器来侦听表单提交并返回区域的正文:

@Inject
private Request request;

@InjectComponent
private Zone dialogZone;

@OnEvent(component="myForm", value=EventConstants.SUCCESS)
Object linkClicked(String placeId) {
    //your code here

    if (this.request.isXHR()) {
       return this.dialogZone.getBody();
    } else {
       return this;
    }
}

瞧!

--编辑:

因此,由于这在其他表单中不起作用,因此我们将尝试其他方法。

click() 的问题在于它不是本机事件,并且不会馈送到 Prototype 的事件管道中。您可以手动触发区域更新,如下所示:

var actionLink = jQuery(this).next('a');
Tapestry.findZoneManager(actionLink).updateFromURL(actionLink.href);

If I understand you correctly, you want to update a zone from the click of a button. You won't need any customized components to do this, the usual Form, Submit and Zone components will do just fine.

Just create a form with the button in your template and set its zone parameter:

<div t:type="Zone" t:id="dialogZone" id="dialogZone" />

<form t:type="Form" t:id="myForm" t:zone="dialogZone" t:context="placeId">
    <input type="submit" t:type="Submit" value="Click me" />
</form>

And in your page class file, you set your event listener to listen to the form submission and return the zone's body:

@Inject
private Request request;

@InjectComponent
private Zone dialogZone;

@OnEvent(component="myForm", value=EventConstants.SUCCESS)
Object linkClicked(String placeId) {
    //your code here

    if (this.request.isXHR()) {
       return this.dialogZone.getBody();
    } else {
       return this;
    }
}

Ét voilà!

--Edit:

So, as that won't work inside another form, we'll try something else.

The problem with the click() is that it is not a native event and does not feed into Prototype's event pipeline. You could instead trigger the zone update manually, like this:

var actionLink = jQuery(this).next('a');
Tapestry.findZoneManager(actionLink).updateFromURL(actionLink.href);
是伱的 2024-12-07 22:54:12

您可以在事件链接的主体中嵌套一个按钮。

<t:eventlink event="doIt"><button>Do it</button></t:eventlink>

或者您可以使用 CSS 将链接样式设置为看起来像按钮。例如,如果您使用 twitter-bootstrap 的 CSS,您可以执行以下操作:

<t:eventlink event="doIt" class="btn btn-primary">Do it</t:eventlink>

You can just nest a button in the body of the eventlink.

<t:eventlink event="doIt"><button>Do it</button></t:eventlink>

Or you can use CSS to style the link to look like a button. For instance if you are using twitter-bootstrap's CSS you could do the following:

<t:eventlink event="doIt" class="btn btn-primary">Do it</t:eventlink>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文