在JSF中,如何使h:commandButton只发送一个字段?
在 JSF2 中,我有一个命令按钮,它应该只发送一个字段:
<h:inputHidden id="dirty" value="#{bean.dirty}" />
<h:commandButton value="Back" immediate="true"
action="#{bean.backIfClean}">
<f:ajax execute="dirty" />
</h:commandButton>
此代码不起作用。我通过 JavaScript 更改隐藏字段值,然后我想将其发送到服务器。然而,它甚至没有在 bean 上设置(setDirty
没有被调用)。
如果我删除 immediate="true"
验证就会被触发,在这种情况下我想避免这种情况。
我可以以某种方式避免验证并发送脏字段值吗?
In JSF2 I have a command button, which should send only one field:
<h:inputHidden id="dirty" value="#{bean.dirty}" />
<h:commandButton value="Back" immediate="true"
action="#{bean.backIfClean}">
<f:ajax execute="dirty" />
</h:commandButton>
This code doesn't work. I change hidden field value by JavaScript, then I want to send it to server. However, it is not even set on bean (setDirty
is not called).
If I remove immediate="true"
validation is triggered, which I want to avoid in this case.
Can I somehow avoid validation and send dirty
field value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
那是行不通的。如果将立即放在命令按钮上,则永远不会设置输入组件的值。如果你问我的话,这是框架中的一个主要不便。
您唯一的解决方案是自己从请求中检索值。
我不明白的是为什么你不能只执行。通常,在这种情况下只应验证“脏”。这不是你想要的吗?
That won't work. If you put immediate on a command button, the values for the input components never get set. This is a major inconvenience in the framework if you ask me.
The only solution you have is to retrieve the value yourself from the request.
What I don't get is why yu can't do with just the execute. Normally, only 'dirty' should be validated in that case. Isn't that what you want?
当您将
immediate="true"
放在UICommand
组件上时,仅的UIInput
字段还有immediate="true"
将被处理。另请参阅此摘要。因此,将
immediate="true"
添加到h:inputHidden
中。(注意:未经与
f:ajax
结合测试,这是纯理论)When you put
immediate="true"
on anUICommand
component, then only theUIInput
fields which also haveimmediate="true"
will be processed. See also this summary.So, add
immediate="true"
to theh:inputHidden
.(note: untested in combination with
f:ajax
, this is pure theory)您可以使用以下方法发送/检索一个值:
Backing Bean 代码:
You can use the following approach to send/retrieve one value:
Backing Bean code: