当我提交表单时,它应该调用另一个表单,以便我可以呈现它。我使用 primefaces,我希望它能像下面这样工作。但它抛出一个错误。
xhtml
<h:form id="from1">
<h:inputText=......
<h:outputText=....
<p:commandButton id="submit" actionlistener="#{bean.method}" value="submit" process="form2"/>
<h:form id="form2">
<h:outoutText value="it is working" render="#{bean.boolean}" />
</h:form>
错误
[Faces Servlet]] (http--127.0.0.1-8080-2) Servlet.service() for servlet Faces Servlet threw exception: javax.faces.FacesException: Cannot find component with identifier "form2" referenced from "form1_submit".
已更新
<h:form id="from1">
<h:inputText=......
<h:outputText=....
<p:commandButton id="submit" actionlistener="#{bean.method}" value="submit" update=":form1"/>
</h:form>
最佳答案
有两个错误:
相对组件客户端 ID 与最接近的父组件相关
UINamingContainer
组件(在您的情况下是<h:form id="form1">
)。客户端 ID“form2”不存在于“form1”上下文中的任何位置。您需要使用绝对客户端 ID,并以命名容器分隔符作为前缀,默认为:
。这将从 View 根开始搜索组件。process=":form2"
您无法通过提交一个表单来处理另一个表单。您需要处理的所有字段根本没有提交(请注意,这不是 JSF 限制,而是 HTML 限制)。只需将您需要处理的字段包含在与您需要提交的表单相同的表单中即可。
关于jsf - 从命令按钮调用另一个表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11766255/