h:dataTable 提交后丢失所选行的 styleClass

发布于 2024-10-20 12:07:38 字数 3914 浏览 2 评论 0原文

在我的数据表中,当单击一行时,它会被标记为某种颜色。但随后这个标记就消失了,因为发生了提交。但我只重新渲染页面的其他部分而不是表格,那么为什么会发生这种情况呢?我该如何解决这个问题? 代码:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:p="http://primefaces.prime.com.tr/ui"
  template="/templates/mainLayout.xhtml">

<ui:define name="header">
    <h1>Persons List</h1>
</ui:define>

<ui:define name="content">
    <h:form id="mainForm">
        <h:outputStylesheet name="tableStyle.css" library="css" target="body"/>

        <h:panelGroup id="personPanel">
            <h:outputText value="#{msgs.fName}"/>
            <h:inputText value="#{personController.person.firstName}" maxlength="20"/>

            <h:outputText value="#{msgs.lName}"/>
            <h:inputText value="#{personController.person.lastName}" maxlength="20"/>

            <h:outputText value="#{msgs.phone}"/>
            <h:inputText value="#{personController.person.phone}" maxlength="20"/>
        </h:panelGroup>

        <h:commandButton value="#{msgs.save}" >
          <f:ajax execute="@form" render="personsTable personPanel" listener="#{personController.savePerson}"/>
        </h:commandButton>
        <h:dataTable id="personsTable" value="#{personController.persons}" var="bean" 
            styleClass="order-table" headerClass="order-table-header" rowClasses="order-table-odd-row,order-table-even-row" rules="none" >
            <h:column>
                <f:facet name="header">
                    <h:outputText value="First Name" />
                </f:facet>
                <h:commandLink value="#{bean.firstName}" >
                    <f:ajax execute="@this" render="personPanel" >
                        <f:setPropertyActionListener target="#{personController.person}" value="#{bean}" />
                    </f:ajax>
                </h:commandLink>
            </h:column>
            <h:column>
                <f:facet name="header">
                    <h:outputText value="Last Name" />
                </f:facet>
                <h:commandLink value="#{bean.lastName}" >
                    <f:ajax execute="@this" render="personPanel">
                        <f:setPropertyActionListener target="#{personController.person}" value="#{bean}" />
                    </f:ajax>
                </h:commandLink>
            </h:column>
            <h:column>
                <f:facet name="header">
                    <h:outputText value="Phone" />
                </f:facet>
                <h:commandLink value="#{bean.phone}" >
                    <!-- f:ajax execute="@this" render="personPanel">
                        <f:setPropertyActionListener target="#{personController.person}" value="#{bean}" />
                    </f:ajax-->
                </h:commandLink>
            </h:column>
        </h:dataTable>
    </h:form>
</ui:define>

<ui:define name="footer">
    <script type="text/javascript">
        $(document).ready(function(){
            $(".order-table tr").mouseover(function(){
                $(this).addClass("over");
            });
            $(".order-table tr").mouseout(function(){
                $(this).removeClass("over");
            });
            $(".order-table tr").click(function(){
                $(".order-table tr").removeClass("choose");
                $(this).addClass("choose");
            });
        });
    </script>
</ui:define>
</ui:composition>

In my dataTable when a row is clicked it gets marked with some color. But then this mark disappears because submit occurs. But i re-render only some other part of the page and not the table, so why does it occur? How can i fix this?
The code:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:p="http://primefaces.prime.com.tr/ui"
  template="/templates/mainLayout.xhtml">

<ui:define name="header">
    <h1>Persons List</h1>
</ui:define>

<ui:define name="content">
    <h:form id="mainForm">
        <h:outputStylesheet name="tableStyle.css" library="css" target="body"/>

        <h:panelGroup id="personPanel">
            <h:outputText value="#{msgs.fName}"/>
            <h:inputText value="#{personController.person.firstName}" maxlength="20"/>

            <h:outputText value="#{msgs.lName}"/>
            <h:inputText value="#{personController.person.lastName}" maxlength="20"/>

            <h:outputText value="#{msgs.phone}"/>
            <h:inputText value="#{personController.person.phone}" maxlength="20"/>
        </h:panelGroup>

        <h:commandButton value="#{msgs.save}" >
          <f:ajax execute="@form" render="personsTable personPanel" listener="#{personController.savePerson}"/>
        </h:commandButton>
        <h:dataTable id="personsTable" value="#{personController.persons}" var="bean" 
            styleClass="order-table" headerClass="order-table-header" rowClasses="order-table-odd-row,order-table-even-row" rules="none" >
            <h:column>
                <f:facet name="header">
                    <h:outputText value="First Name" />
                </f:facet>
                <h:commandLink value="#{bean.firstName}" >
                    <f:ajax execute="@this" render="personPanel" >
                        <f:setPropertyActionListener target="#{personController.person}" value="#{bean}" />
                    </f:ajax>
                </h:commandLink>
            </h:column>
            <h:column>
                <f:facet name="header">
                    <h:outputText value="Last Name" />
                </f:facet>
                <h:commandLink value="#{bean.lastName}" >
                    <f:ajax execute="@this" render="personPanel">
                        <f:setPropertyActionListener target="#{personController.person}" value="#{bean}" />
                    </f:ajax>
                </h:commandLink>
            </h:column>
            <h:column>
                <f:facet name="header">
                    <h:outputText value="Phone" />
                </f:facet>
                <h:commandLink value="#{bean.phone}" >
                    <!-- f:ajax execute="@this" render="personPanel">
                        <f:setPropertyActionListener target="#{personController.person}" value="#{bean}" />
                    </f:ajax-->
                </h:commandLink>
            </h:column>
        </h:dataTable>
    </h:form>
</ui:define>

<ui:define name="footer">
    <script type="text/javascript">
        $(document).ready(function(){
            $(".order-table tr").mouseover(function(){
                $(this).addClass("over");
            });
            $(".order-table tr").mouseout(function(){
                $(this).removeClass("over");
            });
            $(".order-table tr").click(function(){
                $(".order-table tr").removeClass("choose");
                $(this).addClass("choose");
            });
        });
    </script>
</ui:define>
</ui:composition>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

所谓喜欢 2024-10-27 12:07:38

您可以使用 Firefox 和“firebug”插件实时检查元素以了解发生了什么情况。可能是您的更新中的某些内容破坏了样式的继承......

You can use firefox and "firebug" plugin to inspect the element in real time to find out what's going on. It could be that something about your update is breaking the inheritance of the style...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文