0

我目前正在学习 JSF 2。我想实现的第一件事是以下场景:

我的页面上有一个 commandLink。单击此链接时,将呈现一个 h:panelGroup-Tag(取决于相应 ManagedBean 中的布尔属性 - 默认情况下为 false)。我希望在再次单击“打开”panelGroup的链接时不呈现该panelGroup(这已经有效),但我希望当用户在该panelGroup之外单击时也不会呈现panelGroup(这不起作用) .

ManagedBean 看起来像:

@ManagedBean
@SessionScoped
public class LocaleBean {

@PostConstruct
public void init(){
    locale = new Locale("de_DE");
    showLanguageDiv = false;
}

private boolean showLanguageDiv;

public boolean getShowLanguageDiv() {
    return showLanguageDiv;
}

public void setShowLanguageDiv(final boolean showLanguageDiv) {
    this.showLanguageDiv = showLanguageDiv;
}

public void switchShowDivStatus(ActionEvent e) {
    showLanguageDiv = !showLanguageDiv;
}

小面看起来像:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core">
<h:form>
    <div>
        <h:commandLink style="float: right;padding: 2px" actionListener="#{localeBean.switchShowDivStatus}" value="#{msg.language}" >
        </h:commandLink>
    </div>
    <h:panelGroup rendered="#{localeBean.showLanguageDiv}" style="clear:both;float:right;border:2px;border-style: solid" >
        <p><h:commandButton .... /></p>
        <p><h:commandButton .... /></p>
        <p><h:commandButton .... /></p>
    </h:panelGroup>
</h:form>
</ui:composition>

我已经尝试添加一个通过 javascript 单击的隐藏链接(当用户单击正文中的任何位置时),它将 ManagedBean 的布尔属性设置为 false,以便不呈现 panelGroup。这部分是因为 panelGroup 不再显示。但另一方面,单击链接以显示 panelGroup 在这样做之后不再起作用。

这是它的样子:

<h:body onclick="document.getElementById('invisibleform:invisiblelink').click()">
    .
    .
    .
    <h:form id="invisibleform">
        <h:commandLink id="invisiblelink" actionListener="#{localeBean.switchShowDivStatus}"></h:commandLink>
    </h:form>
</h:body>

那么我该如何解决这个问题呢?有没有做这样的事情的最佳实践?隐藏链接是正确的方法吗?从我目前所读到的内容来看,这似乎是应该通过javascript在客户端完成的事情。但是我发现的所有解决方案都是基于普通的 html 页面(非 JSF),我无法想象在使用 JSF 时应该如何完成。

感谢您的任何建议。

4

1 回答 1

0

你能在 JSF 中使用 Primefaces 吗?有一个组件<p:overlayPanel> See here for the show。也许这对你有用......

于 2013-08-20T20:39:59.707 回答