仅自JSF 2.0 起才支持<f:param>
内部<h:commandButton>
,但您使用的是 JSF 1.2。然后<f:param>
仅支持<h:commandLink>
.
<h:commandLink action="#{myBean.myAction}" value="Send">
<f:param name="myFlag" value="true" />
</h:commandLink>
还有其他选择,例如<h:inputHidden>
or <f:setPropertyActionListener>
or <f:attribute>
or 在这种情况下可能只是普通<input type="hidden">
的(隐藏的输入组件和动作侦听器只会在更新模型值期间设置它们的值,这比验证阶段晚;属性标签最好设置在调用验证器的组件)。由于功能要求不明确,因此无法提出最佳替代方案。
根据评论进行更新,显然您只需要知道是否按下了特定按钮;在这种情况下,只需给它和父表单一个固定的 ID
<h:form id="form">
<h:commandButton id="send" ...>
这样,它将有一个固定的请求参数名称,form:send
您可以在验证器中检查它:
if (externalContext.getRequestParameterMap().containsKey("form:send")) {
// Send button is pressed.
}
顺便说一句,您还可以在required
验证器中进行如下检查:
<h:inputText ... required="#{not empty param['form:send']}" />
也可以看看: