在我的xhtml页面中,第一次页面看起来不错,但是当我点击h:commandLink发送ajax请求时 当它重新加载页面css和jquery没有加载。因此颜色和表格视图已更改。 我的表是:
<table width="100%" cellspacing="1" cellpadding="1" border="0" class="role_detail_section">
<thead><tr>
<th>Relationship-Type Name</th>
<c:forEach items="#{manageRelationBean.languageList}" var="languageName" >
<th>#{languageName}</th>
</c:forEach>
<th>Edit | Deactivate</th>
</tr>
</thead>
<tbody>
<c:forEach items="#{manageRelationBean.languageRelList}" var="languageRelDTO">
<tr>
<td>
#{languageRelDTO.relationName}
</td>
<c:forEach items="#{languageRelDTO.languageList}" var="relationValues">
<td>#{relationValues.relationValue}</td>
</c:forEach>
<td>
<span><h:commandLink value="Edit" class="edit_icon" action="#{relationBean.editRelationByRelationType}" immediate="true" >
<f:setPropertyActionListener target="#{relationBean.relationType}" value="#{languageRelDTO.relationName}" />
</h:commandLink></span>
<span> </span>
<span><p:commandLink rendered="#{manageRelationBean.findRelationStatus(languageRelDTO.country.countryCode,languageRelDTO.relationName) eq 1}" value=" Activate " action="#{manageRelationBean.activateRelation(languageRelDTO.relationName)}" update="@form" process="@this" >
<f:setPropertyActionListener target="#{relationBean.relationType}" value="#{languageRelDTO.relationName}" />
</p:commandLink>
<p:commandLink rendered="#{manageRelationBean.findRelationStatus(languageRelDTO.country.countryCode,languageRelDTO.relationName) eq 3}" value=" Deativate " action="#{manageRelationBean.softDeactivateRelation(languageRelDTO.relationName)}" update="@form" process="@this">
<f:setPropertyActionListener target="#{relationBean.relationType}" value="#{languageRelDTO.relationName}" />
</p:commandLink>
</span>
</td>
</tr>
</c:forEach></tbody>
</table>
和用于表着色的jquery是
$(document).ready(function(){
$(".role_detail_section tr:odd").addClass("activity_white");
$(".role_detail_section tr:even").addClass("activity_blue");
});
答案 0 :(得分:1)
使用delegate() or on()将处理程序绑定到在运行时重新生成的元素。
代表:Attach a handler to one or more events for all elements that match the selector, now or in the future
答案 1 :(得分:0)
我通过在jsf commandLink中添加一个onComplete
的属性来解决这个问题onComplete="addCSS()"
和写的函数
function addCSS(){
$(".role_detail_section tr:odd").addClass("activity_white");
$(".role_detail_section tr:even").addClass("activity_blue");
}