2

When edit is selected, the backing bean is called but the form fields are not pre filled with the data.

<h:form id="EmpDetails">
   <h:inputText value="#{empBean.fName}">
      <f:validateBean disabled="#{param[skipBeanValidation]}"/>
    </h:inputText>

<h:dataTable> 
 <h:column>
    [<h:commandLink value="Edit" immediate="true">
      <f:ajax execute="@form" render="@form" listener="#{empBean.edit}"/>
     </h:commandLink>  ]
     Changed to 
     <h:commandLink value="Edit" action="#{empBean.edit}">
       <f:param name="skipValidation" value="true"/>
     </h:comamndLink>
  </h:column>     
 </h:dataTable>

<h:commandLink value="#{empBean.addEmployee}"/>
<h:commandLink value="#{empBean.continue}"/>
</h:form>
user679526
  • 845
  • 4
  • 16
  • 39

1 Answers1

3

This isn't how HTML forms are supposed to work. A single HTML form should surround all input elements and buttons which all participate in the same form.

Put the related form elements together in the same form. If you encounter a problem with it, then it has to be solved differently. For example, by using partial submits in ajax.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I have updated the code to use only one form. The edit functionality is not working as required. – user679526 Nov 02 '12 at 18:21
  • Remove the `immediate="true"` and `execute="@form"`. If that didn't solve your concrete problem, then you'd have to tell a bit more than "not working". In any way, you may find this CRUD example helpful: http://stackoverflow.com/a/3180885 – BalusC Nov 02 '12 at 18:33
  • That's exactly why you should *also* remove the `execute="@form"`. It defaults then to `@this`. – BalusC Nov 02 '12 at 19:09
  • Removing immediate="true" & execute="@form" the listener is not called. – user679526 Nov 02 '12 at 19:13
  • And with them, it *is* called? – BalusC Nov 02 '12 at 19:16
  • Yes, adding those attributes, there is a call to the listener. – user679526 Nov 02 '12 at 19:20
  • I find it hard to believe. Do you have the complete code as shown in your question also running in your test page? Or does your question represent a simplified (and untested) version of it? In any way, have you given the kickoff CRUD example in http://stackoverflow.com/a/3180885 a try? It's copy'n'paste'n'runnable. – BalusC Nov 02 '12 at 19:26
  • I tried something similar to the CRUD example, but because of different requirements (placement of buttons) I had to use a single form instead of two forms for edit and save button. – user679526 Nov 02 '12 at 19:27
  • Okay, let's assume that your example is incomplete and that you really need the immediate attribute for some unclear reason, can you please describe how exactly it "is not working"? – BalusC Nov 02 '12 at 19:29
  • I have updated the code, now I use f:param to pass in a attribute whether or not to validate the fields. – user679526 Nov 05 '12 at 21:02