4

I have a form that I want to submit with JSF/Richfaces.

To execute the form action, I need to be sure a data from another form is valid.

So my question is, how can I submit a form with data come from another form ?

My code is like this:

<h:form id="form1" >
<h:inputText id="data" validator="#{myBean.validateData}" />
</h:form>
<h:form id="form2" >
<h:inputText id="data2" validator="#{myBean2.validateData2}" />
<a4j:commandLink id="button" 
    action="#{bandeauTarifController.recalculer}" ajaxSingle="true" 
    process="data" >
Test link
</a4j:commandLink>
</h:form>

I thought the "process" attribute could do this but not.

Someone have an idea about that ?

Thanks.

Kiva
  • 9,193
  • 17
  • 62
  • 94
  • Place a hidden (`style="display:none"`) button inside `` and click on it with jquery `$('#form1\\:myButtonID').click();` that the only way to execute the form from outside – Daniel Aug 02 '12 at 13:43
  • Ok it works with that but how to stop the second request (from the button from form2) if the data is invalid ? – Kiva Aug 02 '12 at 13:52

1 Answers1

3

Place a hidden (style="display:none") button inside <h:form id="form1" > and click on it with jquery $('#form1\\:myButtonID').click();

in order to stop the second request (from the button from form2) if the data is invalid... You can make a third button and call the first one from form1 , than check the data and in case its valid click on the second button from form2

Daniel
  • 36,833
  • 10
  • 119
  • 200
  • 1
    Thanks, it works. I'm not very fan to use javascript to do that but it's ok for my problem. – Kiva Aug 03 '12 at 09:49