0

I have a form and inside a tabView. I have two buttons in one of the tabs, which call an action method on a RequestScoped bean. However, the action method is not being called.

search.xhtml:

<h:form>
    <p:inputText id="search-query" value="{searchController.searchQuery}"/>
    <p:commandButton value="#{txt['global.search']}"
                     id="search-button"
                     action="#{searchController.search}"
                     update=":search-results"/>

</h:form>
<h:form id="search-results">
    <p:tabView id="search-results-tab"
                       dynamic="false"
                       cache="false">

                <p:tab id="tab-persons" rendered="#{not empty searchController.persons}">
                    <ui:include src="person-table.xhtml"/>
                </p:tab>
    </p:tabView>
</h:form>

person-table.xhtml

<p:outputPanel styleClass="search-results-paginator">

    <p:commandButton id="personsPrevious" value="Prev" action="#{searchController.personResultPrevious}"/>

    <p:commandButton id="personsNext" value="Next" action="#{searchController.personResultNext}"/>

</p:outputPanel>

SearchController.java

@Named("searchController")
@RequestScoped
public class SearchController {

    private List<PersonDTO> persons;        
    private String searchQuery;        

    public String search() {

        persons = searchService.search(searchQuery);
        return null;

    }

    public String personResultNext() {

        loadPersons(searchQuery, ++personResultPage);
        return null;

    }

    public String personResultPrevious() {

        if(personResultPage - 1 > 0) {
            loadPersons(searchQuery, --personResultPage);
        }

        return null;
    }

}

What am I doing wrong? I don't see any error.

Filip Majernik
  • 7,700
  • 13
  • 45
  • 53
  • I've edited the question. As you can see on the search page I have two forms - one with the input and a button and another one with results (I have also tried with everything in one form, but the same result). The click on the search button works, however the later clicks on the previous or next button don't. The request is sent but the method won't get called. There is no validation or any error in the response - just some normal jsf partial update... The bean was first in ConversationScope and it worked, but I need to refactor it to request scope. – Filip Majernik Oct 01 '15 at 09:29
  • Still, is that the whole code for person-table.xhtml? – Jaqen H'ghar Oct 02 '15 at 13:16
  • It was simplified. However, I have discovered the problem. The problem is when using RequestScoped bean. As there is not state preserved on the bean (cause it is created for every request) any rendered attribute that checks some property of the class (like rendered='not empty searchController.persons') will evaluate to false in the RestoreView phase (I suppose) and the values come first in later phases. That's why JSF cannot associate no action with the button, because it actually isn't rendered. At least, this is how i understand it. Correct me if you think it's wrong. – Filip Majernik Oct 02 '15 at 14:27
  • Related: http://stackoverflow.com/q/2118656 (point 5). For future questions, read http://stackoverflow.com/tags/jsf/info for hints how to provide the right code snippet. – BalusC Oct 02 '15 at 14:32
  • Hmmmm in my initial comment there was a link which contains _" Abusing a @RequestScoped bean for view scoped data would make view scoped data to be reinitialized to default on every single (ajax) postback, causing possibly **non-working forms (see also points 4 and 5 here)**."_ If you'd read it you'd have known _"It was simplified."_ No wonder I was not able to replicate, but due to your reaction I did not want to reply with a new comment. Never ever **over**simplify things to the extend that it is not reproducible anymore. It takes to much time from people. – Kukeltje Oct 02 '15 at 14:38

0 Answers0