2014-04-11 80 views
0

我是新手到JSF當我試圖測試一個簡單的代碼時,我得到了這個errorJSF1091:沒有找到MIME類型

我有一個類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

回答

0

當您返回StringUIInput(在這種情況下,<h:commandButton>)調用的方法,String s應該是處理請求後要轉發的視圖的名稱。

如果您只是想測試該方法是否由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} 
+0

是否有可能表現出比其他其他在同一頁的字符串值。 – Scorpion

+0

@Scorpion的答案已更新。 –