0

Ricfaces を使用してレンダリングされたテーブルの現在選択されている行を強調表示しようとしていますが、機能していません。これが私のコードです:

フェイスレット:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core"
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" template="templates/main.xhtml">

<ui:define name="body">
    <h:form>
        <fieldset>
            <legend>
                <h:outputText value="#{msg['result.legend']}" />
            </legend>

            <rich:dataTable id="resultTable" onRowMouseOver="this.style.backgroundColor='#f1f1f1'" 
                onRowMouseOut="this.style.backgroundColor=''"
                value="#{searchController.result}" var="row">
                <c:forEach items="${searchController.headers}" var="headr"
                    varStatus="status">
                    <rich:column>
                        <f:facet name="header">
                            <h:outputText value="#{headr}" />
                        </f:facet>
                        <h:outputText value="#{row[status.count-1]}" />
                    </rich:column>
                </c:forEach>
            </rich:dataTable>

        </fieldset>
    </h:form>
</ui:define>

テンプレート全体 (main.xhtml) のソース コードを貼り付けることができません。これは h : body タグの内容です (理由がわかりました :-) ):

<rich:panel styleClass="mainPanel">
    <ui:include src="../common/header.xhtml"></ui:include>
    <ui:insert name="body"></ui:insert>
</rich:panel>

pom の依存関係:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.richfaces</groupId>
            <artifactId>richfaces-bom</artifactId>
            <version>4.2.2.Final</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.9</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.1</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

    <dependency>
        <groupId>org.richfaces.ui</groupId>
        <artifactId>richfaces-components-ui</artifactId>
    </dependency>
    <dependency>
        <groupId>org.richfaces.core</groupId>
        <artifactId>richfaces-core-impl</artifactId>
    </dependency>
    <!--dependency> <groupId>javax.faces</groupId> <artifactId>javax.faces-api</artifactId> 
        </dependency -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
    </dependency>
    <dependency>
        <groupId>com.sun.facelets</groupId>
        <artifactId>jsf-facelets</artifactId>
        <version>1.1.14</version>
    </dependency>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
</dependencies>

searchController.headers は List< String > であり、searchController.result は List< List< String > > です。テーブル自体は正しく表示されます。

ここで何が欠けていますか?

私は Richfaces 4.2.2.Final を使用しており、Eclipse Indigo で開発しています。

4

1 に答える 1

0

実際、この質問は重複していません。これは、リッチフェイスがこれをプレーンな jsf とは少し異なる方法で処理するためです。

そのタスクのために、アプリケーションで 2 つの js 関数を作成しました。

function mouseOutRichRow(row) {
    if (row.highlight != true) {
        row.style.backgroundColor=row.oldColor;
    }
}
function mouseOverRichRow(row) {
    if (row.highlight != true) {
        row.oldColor=row.style.backgroundColor;
        row.style.backgroundColor='#FFFF8A';
    }
}

これらは onRowMouse イベントにバインドされています。

<rich:dataTable
    onRowMouseOver="mouseOverRichRow(this);"
    onRowMouseOut="mouseOutRichRow(this);"
    ....>

実際、Luiggi Mendoza のコメントは間違っています。Richfaces はこれらのパラメーターを各行に適用するためthis、正しいスコープを持っています。

編集: これでもうまくいかない場合は、使用しないでくださいc:forEach。これは古い jsp 方式であり、jsf ライフサイクルではうまく機能しません。代わりにui:repeatまたはを使用してください。a4j:repeat

于 2012-07-05T14:56:48.783 に答える