我是jsf和richfces的新手。我想在intellij idea中使用richfces 4在Tomcat7上编写一个简单的web应用程序。问题是命令按钮和链接按钮没有显示在结果页面中。这是我的应用程序代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>org.richfaces.skin</param-name>
<param-value>blueSky</param-value>
</context-param>
</web-app>
这是视图代码:(index_sample2.xhtml)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<head>
<style type="text/css">
.outhello {
font-weight: bold;
}
</style>
</head>
<body>
<h:form>
<h:panelGrid columns="3">
<h:outputText value="Name:" />
<h:inputText value="#{user.name}" />
<a4j:commandButton value="Say Hello" render="out" execute="@form" />
</h:panelGrid>
</h:form>
<a4j:outputPanel id="out">
<h:outputText value="Hello #{user.name} !"
rendered="#{not empty user.name}" styleClass="outhello" />
</a4j:outputPanel>
</body>
</html>
faces-config.xml:
<?xml version='1.0' encoding='UTF-8'?>
<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>user</managed-bean-name>
<managed-bean-class>demo.User</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>name</property-name>
<property-class>java.lang.String</property-class>
<value></value>
</managed-property>
</managed-bean>
</faces-config>
和用户bean:
public class User {
private String name="";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
a4j适用于outputPanel,但不适用于命令链接和按钮。他们的表演毫无意义!!
此外,我在网络应用程序中设置了皮肤blueSky。但它缝合了,这也没有加载。你能帮帮我吗?
渲染属性是
指示是否应渲染此组件的布尔值
在你的代码
<h:outputText value="Hello #{user.name} !"
rendered="#{not empty user.name}" styleClass="outhello" />
默认值为true,这意味着组件将出现
但是
您为其分配一个字符串值
注意:除true外的任何值都被评估为false
这意味着当我们写一个这个代码
rendered="#{not empty user.name}"
这相当于
rendered="false"
然后您的组件将不会出现