6
votes

I am getting the following error : Unable to find matching navigation case with from-view-id '/index.xhtml' for action '#{medcontroller.getMedGeneric}' with outcome 'javax.faces.model.ListDataModel@7a652236'

I am new to jsf and I'm really clueless about solving this error. I have a ManagedBean with the following code:

MedController.java

@ManagedBean(name = "medcontroller")
@SessionScoped

public class MedController implements Serializable {
    int startId;
    String gName;
    int endId;
    DataModel medNames;
    //DataModel medGeneric;
    MedicineHelper helper;
    private int recordCount = 1000;
    private int pageSize = 10;
    private Medicine current;
    private int selectedItemIndex;

    public MedController() {
        helper = new MedicineHelper();
        startId = 1;
        endId = 10;
    }

    public MedController(int startId, int endId) {
        helper = new MedicineHelper();
        this.startId = startId;
        this.endId = endId;
    }

    public Medicine getSelected() {
        if (current == null) {
            current = new Medicine();
            selectedItemIndex = -1;
        }
        return current;
    }

    public DataModel getMedNames() {
        if (medNames == null) {
            medNames = new ListDataModel(helper.getMedNames(startId, endId));
        }
        return medNames;
    }

    public String getgName()
        {
        return gName;
    }

    public void setgName(String gName)
        {
        this.gName = gName;
    }

    public DataModel getMedGeneric() {
        if (medNames == null) {
            medNames= new ListDataModel(helper.getMedGeneric(gName));
        }
        return medNames;
    }

    void recreateModel() {
        medNames = null;
    }

    public boolean isHasNextPage() {
        if (endId + pageSize <= recordCount) {
            return true;
        }
        return false;
    }

    public boolean isHasPreviousPage() {
        if (startId-pageSize > 0) {
            return true;
        }
        return false;
    }

    public String next() {
        startId = endId+1;
        endId = endId + pageSize;
        recreateModel();
        return "index";
    }

    public String previous() {
        startId = startId - pageSize;
        endId = endId - pageSize;
        recreateModel();
        return "index";
    }

    public int getPageSize() {
        return pageSize;
    }

   public String prepareView(){
        current = (Medicine) getMedNames().getRowData();
        return "browse";
    }
   public String prepareList(){
        recreateModel();
        return "index";
    }

}

And here is my JSF file

index.xhtml

<ui:define name="body">
    <h:form styleClass="jsfcrud_list_form">
    <h:commandLink action="#{medcontroller.previous}" value="Previous #{medcontroller.pageSize}" rendered="#{medcontroller.hasPreviousPage}"/> 
    <h:commandLink action="#{medcontroller.next}" value="Next #{medcontroller.pageSize}" rendered="#{medcontroller.hasNextPage}"/> 
    <h:dataTable value="#{medcontroller.medNames}" var="item" border="1" cellpadding="15" cellspacing="10" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
    <h:column>
        <f:facet name="header">
            <h:outputText value="BrandName"/>
        </f:facet>
            <h:outputText value="#{item.brandName}"/>
    </h:column>
    <h:column>
        <f:facet name="header">
            <h:outputText value="Generic"/>
        </f:facet>
            <h:outputText value="#{item.generic}"/>
    </h:column>
    <h:column>
        <f:facet name="header">
            <h:outputText value=" "/>
        </f:facet>
            <h:commandLink action="#{medcontroller.prepareView}" value="View"/>
    </h:column>
    </h:dataTable>

    <h:inputText value="#{medcontroller.gName}" />
    <h:commandButton value="Submit" action="#{medcontroller.getMedGeneric}" />
    </h:form>
</ui:define>

Please help me solve the error. Also, I do not have a faces-config.xml file. I am using netbeans ide 7.1.2 web application with jsf and hibernate framework.

Thank you in advance.

3
You forgot to tell what exactly you want to happen when you press that "submit" button.BalusC
Careful with get prefix. It is very generic for getters only. You don't "get" something from a database, if it is not a backing bean properry. JSF can maybe see that otherwise. Better use fetchMedGeneric(), including the braces.Roland
And also, if you have an error, please always include the complete back-trace.Roland
And you use @ManagedBean which is deprecated JSF 2.0.Roland

3 Answers

8
votes

The <h:commandButton action> must point to a method which invokes some business logic and returns either void or a String representing the target page you'd like to (re)display. However you returned a whole ListDataModel which isn't making any sense to JSF navigation handler and hence this error.

Something like this should do:

public String getMedGeneric(){ 
    // Do your business logic here.

    return "someViewId";
}

This will navigate to someViewId.xhtml. However, if you intend to stick on the same view, just let it return void (or null) and it will redisplay the same view.

public void getMedGeneric(){ 
    // Do your business logic here.
}

By the way, it's really a poor naming convention to prefix action method names with get. This is confusing and makes your code not self-documenting. Rather name it loadMedGeneric() or so. I'm merely guessing as you didn't tell anywhere about the concrete functional requirement, what exactly that button should be doing.

0
votes

getMedGeneric should return java.lang.String which represent navigation to another page described in faces-config.xml. In your case it return some model so it will not work unfortunatell. Let try to put getMedGeneric() action to actionListener and then in action put navigation String. i.e:

action="navString" actionListener="#{medcontroller.getMedGeneric}"
-2
votes

you should try just

actionListener="#{medcontroller.getMedGeneric}"