Call another form from the command button

ぃ、小莉子 提交于 2019-12-18 13:27:42

问题


When I submit a form it should call another form so that I can render it. I use primefaces and I want it to work something like below. But it is throwing an error.

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>

error

[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".

Updated

<h:form id="from1">
    <h:inputText=......
    <h:outputText=....
    <p:commandButton id="submit" actionlistener="#{bean.method}" value="submit" update=":form1"/>
</h:form>

回答1:


There are two mistakes:

  • Relative component client IDs are releative to the closest parent UINamingContainer component (which is in your case thus the <h:form id="form1">). The client ID "form2" does not exist anywhere within the context of "form1". You need to use an absolute client ID instead, prefixed with the naming container separator character which defaults to :. This will search for components from the view root on.

    process=":form2"
    
  • You cannot process another from by a submit of one form. All of the fields which you need to be processed are not been submitted at all (note that this is not a JSF limitation, but a HTML limitation). Just enclose the fields which you need to process in the very same form as you need to submit.




回答2:


There is another solution with p:remoteCommand and JS with onclick described HERE.



来源:https://stackoverflow.com/questions/11766255/call-another-form-from-the-command-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!