6

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>
cezar
  • 11,616
  • 6
  • 48
  • 84
Coool Awesome
  • 145
  • 1
  • 5
  • 16
  • Also see my answer from your previous question - http://stackoverflow.com/questions/11656218/jsf-forms-when-submit – Catfish Aug 01 '12 at 21:19

2 Answers2

15

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • i have tested your note1, but i still have same issue. Can you tell me what i am doing wrong here? – Coool Awesome Aug 01 '12 at 20:28
  • 1
    That's answered by the second point. In other words: you ain't going to get this to work without changing the forms. – BalusC Aug 01 '12 at 20:46
  • @BalusC i am also stuck in same situation i have oneform in which i have one hidden field which i want to validate from secondform's submit button what should i do any best answer please help – Mohsin AR Sep 09 '15 at 08:29
  • This is a big problem i faced when i wanted to process value inside a form from a commandButton inside a ribbon which should be placed at a header of my html page – Nwawel A Iroume Oct 07 '15 at 21:50
6

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

Plutoz
  • 694
  • 9
  • 13