0

I have an ajax request which outputs me a dataTable and form each row i also want to execute a button.Sadly no event gets invoked and i think it is because the second button is on a different level than the first search button. JSF looks something like that:

<h:from>
   <h:inputText id="search" 
                value="#{profileController.searchName}"/>
   <h:commandButton value="Search by name" 
                    action="#{profileController.searchProfileWithName(profileController.searchName)}">
      <f:ajax execute="search" 
              render="output">
      </f:ajax>
   </h:commandButton>

   <h:dataTable  id="output" 
                 value="#{profileController.searchResultList}" 
                 var="p">
                <h:column>
                    <f:facet name="header">Name</f:facet>
                    <h:outputText value="#{p.name}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">Action</f:facet>
                    <h:commandButton value="Invite"
                                     action="#{trainingController.inviteProfile(p)}">
                                <f:ajax/>
                     </h:commandButton>
                </h:column>
   </h:dataTable
</h:form>

JSF Managed Bean (requestScoped):

public String searchProfileWithName(String name) {
    searchResultList = profileBean.findProfilesWithName(name);
    return null;
}

ProfileBean (stateless):

public List<Profile> findProfilesWithName(String name) {
    Query query = em.createNamedQuery("findProfilesWithName");
    query.setParameter("name", "%" + name.replace(" ", "%") + "%");
    return query.getResultList();
}

Anyone ideas in this?

perotom
  • 851
  • 13
  • 33
  • Have you checked http://stackoverflow.com/questions/2118656/commandlink-commandbutton-backing-bean-action-method-not-invoked/2120183#2120183 ? – Smutje Oct 07 '14 at 10:38
  • yes i checked it. Doesn´t help me – perotom Oct 07 '14 at 15:47
  • Why are you passing `trainingController.currentTraining` via EL, if `currentTraining`is already in the backing bean? Why not just use it from the backing bean and pass `p` only?. You should also post your backing bean here, to show how you're populating that list. *Something* from the list @Smutje posted must apply to you. Everything possible is covered in that post. – kolossus Oct 09 '14 at 00:40
  • First question: because i want to use the function inviteProfile on different trainings later on. See edit – perotom Oct 09 '14 at 13:10
  • 1
    You can't have `searchResultList` in an `@RequestScoped` bean and expect to be able to act on it with `inviteProfile`. The data won't survive because of the requestscope. Your explanation for `inviteProfile` doesn't make sense: the variable is in the backing bean already, why are you passing it from EL? Why can't you have overload the method and use the appropriate one from within the view? – kolossus Oct 09 '14 at 22:38
  • As you see searchResultList is only used for output the table. Ok you are right with the overload. Totally oversaw it. one for that! But the problem is still there. The action won´t get called – perotom Oct 10 '14 at 05:53

1 Answers1

0

The answer to this problem is the datasource. this is the link to the problem:

h:commandButton not working inside h:dataTable

Community
  • 1
  • 1
perotom
  • 851
  • 13
  • 33