admin管理员组文章数量:1331890
I'm looking for a way to show/hide an arbitrary RichFaces ponent. In this case, I have a <rich:dataTable>
that contains several rows. Each row needs to have it's own, independent Show/Hide link, such that when you click "Show details", two things happen:
- The "Show details" link is re-rendered as "Hide details"
- The associated detailsColumns should bee visible (starting from a state of
rendered="true"
butstyle="display: none;"
).
I don't want to write my own JavaScript functions if it's not absolutely necessary. I also don't want to have a server-side bean keep track of which detailColumns are being displayed, and subsequently re-render everything over AJAX: this should be purely client-side behavior. I'm not sure how to acplish that.
The following pseudo-code (hopefully) illustrates my goal:
<rich:column>
<a href="#" onclick="#{thisRow.detailsColumn}.show();" rendered="">Show details</a>
<a href="#" onclick="#{thisRow.detailsColumn}.hide();" rendered="">Hide details</a>
</rich:column>
<rich:column>
<h:outputText value="#{thisRow.someData}" />
</rich:column>
<rich:column id="detailsColumn" colspan="2" breakBefore="true">
<h:outputText value="#{thisRow.someMoreData}" />
</rich:column>
I'm looking for a way to show/hide an arbitrary RichFaces ponent. In this case, I have a <rich:dataTable>
that contains several rows. Each row needs to have it's own, independent Show/Hide link, such that when you click "Show details", two things happen:
- The "Show details" link is re-rendered as "Hide details"
- The associated detailsColumns should bee visible (starting from a state of
rendered="true"
butstyle="display: none;"
).
I don't want to write my own JavaScript functions if it's not absolutely necessary. I also don't want to have a server-side bean keep track of which detailColumns are being displayed, and subsequently re-render everything over AJAX: this should be purely client-side behavior. I'm not sure how to acplish that.
The following pseudo-code (hopefully) illustrates my goal:
<rich:column>
<a href="#" onclick="#{thisRow.detailsColumn}.show();" rendered="">Show details</a>
<a href="#" onclick="#{thisRow.detailsColumn}.hide();" rendered="">Hide details</a>
</rich:column>
<rich:column>
<h:outputText value="#{thisRow.someData}" />
</rich:column>
<rich:column id="detailsColumn" colspan="2" breakBefore="true">
<h:outputText value="#{thisRow.someMoreData}" />
</rich:column>
Share
edited May 3, 2010 at 13:49
Dolph
asked Apr 30, 2010 at 20:21
DolphDolph
50.7k13 gold badges65 silver badges92 bronze badges
1 Answer
Reset to default 5To the point, you need to grab the generated HTML element from the DOM in JavaScript and then toggle its CSS display
property between block
and none
. As far as I know, RichFaces doesn't provide out-of-the-box scripts/facilities for this, but it is basically not that hard:
function toggleDetails(link, show) {
var elementId = determineItSomehowBasedOnGenerated(link.id);
document.getElementById(elementId).style.display = (show ? 'block' : 'none');
}
with
<h:outputLink onclick="toggleDetails(this, true); return false;">show</h:outputLink>
<h:outputLink onclick="toggleDetails(this, false); return false;">hide</h:outputLink>
本文标签: javaShowHide RichFaces component onclick clientside (without AJAX)Stack Overflow
版权声明:本文标题:java - ShowHide RichFaces component onclick client-side? (without AJAX) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742266416a2443480.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论