如何仅在单击提交按钮时调用表单操作
在没有任何查询参数的情况下向页面发送JSF参数时,使用以下JSF代码:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsf="http://xmlns.jcp.org/jsf">
<head>
<title>Search for Word</title>
</head>
<body>
<div>
<form method="get" action="#{dictionary.search()}" id="search">
<input jsf:id="keyword" value="#{dictionary.keyword}" />
</form>
<button type="submit" form="search" value="Submit">Submit</button>
</div>
</body>
</html>
Action Dictionary.Search()
即使无需单击“提交”按钮,也总是会调用。但是,直到单击提交按钮,就不会调用该操作。
问题:如何更改JSF代码而没有任何其他额外的标签库,但只有提供的JSF TAB lib,即通行元素,以便托管的bean方法dictionary.method()< /代码>仅在单击提交按钮时才调用?
When sending a jsf request without any query parameters to the page with the following jsf code:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsf="http://xmlns.jcp.org/jsf">
<head>
<title>Search for Word</title>
</head>
<body>
<div>
<form method="get" action="#{dictionary.search()}" id="search">
<input jsf:id="keyword" value="#{dictionary.keyword}" />
</form>
<button type="submit" form="search" value="Submit">Submit</button>
</div>
</body>
</html>
the action dictionary.search()
is always invoked even without clicking the submit button. However, the action is not expected to be invoked until the submit button is clicked.
Question: How to change the jsf code without any other extra tag libraries but only the provided jsf tab lib, i.e. the pass-through element so that the managed bean method dictionary.method()
is invoked only when the submit button is clicked?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终自己找到了答案:
这里的实质是生成由
h:commandButton
生成的等效组件树基于jsf 2.2教程8.5 HTML5 友好标记,
整个表单必须作为 jsf 组件 传递到 jsf,即
也是如此;
和I eventually found the answer myself:
The nitty-gritty here is the generation of the equivalent component tree of that generated by
h:commandButton
Based on the jsf 2.2 tutorial 8.5 HTML5-Friendly Markup,
the whole form has to passed through to jsf as a jsf component, the
<form>
element has to be like this<form jsf:id="form">
, where the value of theid
actually could be at randomThe same goes with both the
<input>
and<button>
element and, as to the<input>
element thetype
attribute has to be assigned with a value, here istext
首先 - 您的提交按钮必须位于表单标签内。然后尝试在按钮上设置操作,而不是在表单上设置操作,以避免提交。
希望这有帮助。
根据@BalusC 的评论,我最好的是:
但只有在 form 和 input 这两个标签上放置 jsf:action ,才有可能使其工作。
也许@BalusC 可以向我们展示正确的方法。
First - your submit button must be inside the form tag. And then try to set the action on the button, not on the form to avoid the submit.
Hope this helps.
Up to @BalusC comment my best is:
But only putting jsf:action on both tags, form and input, was possible make it work.
May be @BalusC can show us the correct way.