如果您使用的是 JSF 2,那么您可以通过 ajax 提交和更新表单。这允许部分更新视图。
<h:form>
<h:messages />
...
<h:commandButton ...>
<f:ajax execute="@form" render="@form" />
</h:commandButton>
</h:form>
<h:form>
<h:messages />
...
<h:commandButton ...>
<f:ajax execute="@form" render="@form" />
</h:commandButton>
</h:form>
或者,如果您因为某些不明显的原因不能/不想使用 ajax,或者仍在使用旧版 JSF 1.x,请检查是否已提交rendered
所需表单的属性。<h:messages>
<h:form binding="#{form1}">
<h:messages rendered="#{form1.submitted}" />
...
<h:commandButton ... />
</h:form>
<h:form binding="#{form2}">
<h:messages rendered="#{form2.submitted}" />
...
<h:commandButton ... />
</h:form>
顺便说一句,不应该有这个<h:message>
问题,这与你在问题中暗示的相反。