如何用 p:commandButton 更新 ah:inputHidden?

发布于 2024-12-21 15:10:11 字数 700 浏览 2 评论 0原文

我写了一个ajax请求来获取任何数据。但数据不适用于 h:inputHidden。 我认为这是 Primefaces 的一个错误。 但我现在不知道如何获取数据。

代码:

<h:inputHidden id="buttonData" value="#{buttonDataBean.buttonData}" />
...
<p:commandButton id="getData" action="#{buttonAction.getButtonData}" update="buttonData" />

当我单击命令按钮时, 的值不起作用。 但如果我使用 h:outputText,它就起作用了。

我的要求: 在单击 commandButton 之前,我已经动态创建了任何 html 按钮。我想单击 commandButton 并更新 html 按钮的名称和位置。所以我必须获取任何数据并使用 Javascript 更新 html 按钮。 我该怎么办?

如果我想使用JavaScript来获取ajax数据,该怎么做。我查看文档并找到两个方法:jsf.ajax.request()和Primefaces.ajax.AjaxRequest()。但我不知道如何使用这两种方法。例如:Primefaces.ajax.AjaxRequest("test.xhtml",,)。 “test.xhtml”如何请求TestAction的testMethod方法?

I writed an ajax request for any data. But the data don't work with h:inputHidden.
I think it's a bug of Primefaces.
But I don't know how to get the data now.

code:

<h:inputHidden id="buttonData" value="#{buttonDataBean.buttonData}" />
...
<p:commandButton id="getData" action="#{buttonAction.getButtonData}" update="buttonData" />

When I click the commandButton, the value of don't work.
But if I use the h:outputText, it worked.

My requirement:
Before click the commandButton, I have create any html buttons dynamically. I want to click the commandButton and update the name and position of html buttons. So that I must get any data and update the html buttons with Javascript.
how could I do about it?

If I want to use the JavaScript to get the ajax data, how to do it. I see the document and find two method: jsf.ajax.request() and Primefaces.ajax.AjaxRequest(). But I don't know how to use the two method. for example: Primefaces.ajax.AjaxRequest("test.xhtml",,). The "test.xhtml" how to request the method testMethod of TestAction?

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

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

发布评论

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

评论(3

执笔绘流年 2024-12-28 15:10:11

使用 firebug 检查 html 代码。你可以看到新的价值

<h:form id="form">
  <h:inputHidden  id="buttonData" value="#{buttonDataBean.buttonData}" />
  <p:commandButton id="getData" value="button"
                   action="#{buttonDataBean.buttonAction}" update="buttonData" />
</h:form>

use firebug to inspect html code. you can see new value

<h:form id="form">
  <h:inputHidden  id="buttonData" value="#{buttonDataBean.buttonData}" />
  <p:commandButton id="getData" value="button"
                   action="#{buttonDataBean.buttonAction}" update="buttonData" />
</h:form>
度的依靠╰つ 2024-12-28 15:10:11

如果你的问题用primefaces ajax没有解决,你可以使用jsf提供的原生ajax看看。它有效,我用它做了很多这样的事情。

If your problem does not get solved with primefaces ajax, you can use the native ajax provided by jsf have a look at it.It works, i have done many such things with it.

遮了一弯 2024-12-28 15:10:11

您可以利用 JSF 并使用 f:paramf:attribute,而不是使用隐藏输入。

阅读 BalusC 品牌下这篇非常精彩的文章:http://balusc .blogspot.com/2006/06/communication-in-jsf.html

Instead of using a hidden input you could take advantage of JSF and use a f:param or f:attribute.

Read this really fine article, under the brand of BalusC: http://balusc.blogspot.com/2006/06/communication-in-jsf.html .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文