是否有可能在同一個應用程序一起使用這兩種隱性& bean的聲明,我的意思是@ManageBean和明確的管理bean中faces-config.xml中,我知道這是很少使用,但我覺得試了一下,好奇心讓我失望,最終得到了空值,任何燈光都流露出來,相當讚賞。隱與顯bean聲明可以一起
更新:抱歉,沒有與代碼片斷備份我的問題。
開始了與managedbean:
package pck;
import javax.faces.bean.*;
import java.io.*;
@ManagedBean
public class SimpleController implements Serializable{
private String message="";
public String getMessage() {
return(message);
}
public void setMessage(String message) {
this.message = message;
}
public String doNavigation() {
if (message.trim().length() < 2) {
return("too-short");
} else {
String[] results = { "page1", "page2", "page3" };
return(RandomUtils.randomElement(results));
}
}
}
faces-config.xml中的東西:
<?xml version="1.0"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<managed-bean>
<managed-bean-name>messageHandler</managed-bean-name>
<managed-bean-class>
pck.SimpleController
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>*</from-view-id>
<!-- <navigation-case>
<from-outcome>too-short</from-outcome>
<to-view-id>/error-message.xhtml</to-view-id>
</navigation-case> -->
<navigation-case>
<from-outcome>page1</from-outcome>
<to-view-id>/result-page-1.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>page2</from-outcome>
<to-view-id>/result-page-2.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>page3</from-outcome>
<to-view-id>/result-page-3.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>too-short</from-outcome>
<to-view-id>/error-message.xhtml</to-view-id>
</navigation-case>
</faces-config>
歡迎的facelet:
<h:form>
<!-- If I used implicit bean declaration, It heads to error-page.xhtml, however I insert
more-than-letter word -->
<h:inputText value="#{messageHandler.message}"/>
<br/>
<!-- If I used implicit bean declaration along with condition above, It heads successfully to
a random result page, But with a null expression value -->
<h:commandButton value="Show Results" action="#{messageHandler.doNavigation}"/>
</h:form>
結果的facelet:
與頁面強制t表達式值,但這次使用顯式bean聲明
<h2>Your message: "#{messageHandler.message}"</h2>
它工作的很好如果使用了隱式或顯式的bean聲明。
當然這應該只是工作。你的問題是其他地方引起的只要你沒有詳細描述具體問題,就很難回答。 – BalusC
是的,有什麼問題? '#{messageHandler.doNavigation()}'不工作? –