0

i have a controller and in this controller i get some results from the db

This is the function which i get results

 public DataModel getFts() {

        this.session = HibernateUtil.getSessionFactory().getCurrentSession();

        List<FinancialTransactions> ftList = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from FinancialTransactions where Date='" + beginDate + "'");
            ftList = (List<FinancialTransactions>) q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ftDataModel = new ListDataModel(ftList);
    }

This controllers name is ftController

in jsf

   <h:form styleClass="jsfcrud_list_form">
                <h:dataTable value="#{ftController.ftDataModel}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Title"/>
                        </f:facet>
                        <h:outputText value="#{item.id}"/>
                    </h:column>
                </h:dataTable>
                <br/>
                 <h:commandButton type="submit" action="#{ftController. getFts()}"  id="searchButton"  value="Search"  />
            </h:form>

i have above code. This jsf's name is financialTransactions but it gives below error:

Unable to find matching navigation case with from-view-id '/financialTransactions.xhtml' for action '#{ftController. getFts()}' with outcome 'javax.faces.model.ListDataModel@32ee7cee'

What's wrong?

Aritz
  • 30,971
  • 16
  • 136
  • 217
user2232205
  • 17
  • 1
  • 9

2 Answers2

0

Basically, JSF expects a navigation result as the method return. You have to differ in JSF between getters and action methods.

  • A getter returns something to display in the page you're actually rendering.

  • An action method can perform some action in your bean and return a
    navigation result as an String, or a void or empty String if you want to keep the current page.

You're calling a getter method as an action method and JSF expects you will return a navigation result, however it finds a javax.faces.model.ListDataModel Object.

See more about implicit navigation in JSF 2.

It looks that what you want is to load a list taking search parameters into account. Then what you can do is to call a real action method:

<h:commandButton value="Search" action="#{ftController.loadFts}" />

Where loadFts method will load the search results in your list.

Aritz
  • 30,971
  • 16
  • 136
  • 217
0

In action attribute of commandButton, a return navigation string is expected, which may be a logical outcome string OR an implicit navigation string (Directly the name of the next page you want to navigate to). But here your action method is returning a DataModel object whose toString() doesn't make any sense for the navigation model of JSF. Give the name of the JSF file there to which you want to navigate to.

Korem
  • 11,383
  • 7
  • 55
  • 72