JSF1091:找不到mime类型

时间:2014-04-11 14:37:26

标签: java jsf

我是JSF的新手,当我尝试测试一个简单的代码时,我得到了这个error

我有一个班级Person.java(ManagedBean): -

@ManagedBean
public class Person {

    private String firstName;
    private String lastName;
    private int age;

    // Setters/Getters for firstName, lastName, age

    public String concatMyInfo(){
        return "My name is : " + firstName + " " + lastName + " ... and my age is :" + age;  
    }

}

我有一个名为test.xhtml的文件: -

<h:form>
        FirstName :
            <h:inputText value="#{person.firstName}" /><br/>
        LastName :
            <h:inputText value="#{person.lastName}" /><br/>
        Age :
            <h:inputText value="#{person.age}" /><br/>
        <h:commandButton value="click me" action="#{person.concatMyInfo}" />
</h:form>

我收到了这个错误: - WARNING: JSF1091: No mime type could be found

1 个答案:

答案 0 :(得分:0)

当您从String调用的方法返回UIInput时(在本例中为<h:commandButton>),String应该是要转发的视图的名称处理完请求后。

如果您只是想测试JSF是否正在执行该方法,那么请改用简单的System.out.println并将方法更改为void。例如:

public void concatMyInfo() {
    System.out.println("My name is : " + firstName + " " + lastName + " ... and my age is :" + age);
}

如果要更新将在下一个视图中向用户显示的值,请在托管bean中使用新字段并返回视图的名称。例如:

@ManagedBean
public class Person {

    private String firstName;
    private String lastName;
    private int age;
    private String resultMessage;

    // Setters/Getters for firstName, lastName, age and resultMessage

    public String concatMyInfo() {
        resultMessage = "My name is : " + firstName + " " + lastName + " ... and my age is :" + age;
        return "result";
    }
}

然后,创建一个新页面result.xhtml

<!--
    Boilerplate code not added here. The page should contain
    <html>, <h:head>, etc. No need of a <h:form>
-->
<h:body>
    Hello! #{person.resultMessage}
</h:body>

如果要在同一页面中显示数据,则不要从方法中返回任何内容。使用void方法时,JSF将刷新当前视图。代码应该是:

public void concatMyInfo() {
    resultMessage = "My name is : " + firstName + " " + lastName + " ... and my age is :" + age;
}

然后,在您的视图中,将消息添加到任何位置,可能位于底部:

<h:form>
        FirstName :
            <h:inputText value="#{person.firstName}" /><br/>
        LastName :
            <h:inputText value="#{person.lastName}" /><br/>
        Age :
            <h:inputText value="#{person.age}" /><br/>
        <h:commandButton value="click me" action="#{person.concatMyInfo}" />
</h:form>
<br />
Result: Hello! #{person.resultMessage}