0

I'm new in jsf and richfces. I want to write a simple web application using richfces 4, on Tomcat 7 in intellij idea. The problem is that commandbutton and link button re not shown in result page. This is my app code:

<?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>

and this is the view code: (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>

and User bean:

public class User {

    private String name="";

    public String getName() {

        return name;

    }

    public void setName(String name) {

        this.name = name;

    }
}

a4j worked for outputPanel, but it does not work for command link and button. Their display is none!!

In addition I set the skin blueSky in web app. But it seams this is not loaded, too. Would you please help me?

4

1 回答 1

-1

渲染属性是一个
布尔值,指示是否应渲染此组件
并在您的代码中

<h:outputText value="Hello #{user.name} !"
                  rendered="#{not empty user.name}" styleClass="outhello" />   

默认值为true表示组件将出现

您为其分配了一个字符串值
注意:除true之外的任何值都被评估为false
这意味着当我们编写此代码时

rendered="#{not empty user.name}"  

这相当于

rendered="false"

然后您的组件将不会出现

于 2013-02-12T13:01:16.803 回答