如何通过控制器显示组件?

发布于 2024-12-06 20:55:18 字数 771 浏览 3 评论 0原文

我需要注册一个用户,然后我想调用 例如,用图标显示错误或成功消息。

<rich:popupPanel id="popup" modal="false" autosized="true" resizeable="false">
    <f:facet name="header">
        <h:outputText value="Simple popup panel" />
    </f:facet>
    <f:facet name="controls">
        <h:outputLink value="#"
            onclick="#{rich:component('popup')}.hide(); return false;">
                X
            </h:outputLink>
    </f:facet>
    <p>Any content might be inside this panel.</p>
</rich:popupPanel>

在我的控制器中验证注册过程后,我该如何做到这一点? 我可以调用 ,但我认为带有一些图标和状态消息的 popupPanel 更适合用户。

I need to register an user and after that I would like to call a <rich:popupPanel> for example to show the error or successful message with an icon.

<rich:popupPanel id="popup" modal="false" autosized="true" resizeable="false">
    <f:facet name="header">
        <h:outputText value="Simple popup panel" />
    </f:facet>
    <f:facet name="controls">
        <h:outputLink value="#"
            onclick="#{rich:component('popup')}.hide(); return false;">
                X
            </h:outputLink>
    </f:facet>
    <p>Any content might be inside this panel.</p>
</rich:popupPanel>

How do I do that after the validation of the register process in my controller ?
I could call a <h:message>, but I think a popupPanel with some icon and the status message would be more appropriate to the user.

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

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

发布评论

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

评论(1

我喜欢麦丽素 2024-12-13 20:55:18

一般来说,您只需在 bean 的操作方法中设置一些(布尔)切换或特定对象属性,然后在相关包含组件的 rendered 属性中使用该属性。下面是一个简单布尔值的示例:

private boolean success;

public void submit() {
    // ...

    success = true;
}

public boolean isSuccess() {
    return success;
}

with

<rich:popupPanel rendered="#{bean.success}">
     ...
</rich:popupPanel>

您还可以设置一些对象属性,然后检查它是否不为空或 null。例如,当User在注册后成功保存并因此从数据库获得ID时:

<rich:popupPanel rendered="#{not empty bean.user.id}">
     ...
</rich:popupPanel>

注意:在您的的特定情况下,您还可以使用 show 属性而不是 rendered 属性。

<rich:popupPanel show="#{bean.success}">
     ...
</rich:popupPanel>

唯一的区别是,当 showfalse 时,组件仍会呈现,但随后使用 CSS display:none; 使其在视觉上可见隐藏在 HTML DOM 树中,以便您只需使用 JavaScript 即可重新显示它。

另请参阅:

In general, you'd just set some (boolean) toggle or a specific object property in the bean's action method which is then used in the rendered attribute of the containing component in question. Here's an example with a simple boolean:

private boolean success;

public void submit() {
    // ...

    success = true;
}

public boolean isSuccess() {
    return success;
}

with

<rich:popupPanel rendered="#{bean.success}">
     ...
</rich:popupPanel>

You can also set some object property and then check if it is not empty or null. E.g. when the User is successfully saved after registration and thus got an ID from the DB:

<rich:popupPanel rendered="#{not empty bean.user.id}">
     ...
</rich:popupPanel>

Note: in the particular case of your <rich:popupPanel>, you can also use the show attribute instead of rendered attribute.

<rich:popupPanel show="#{bean.success}">
     ...
</rich:popupPanel>

The only difference is that when show is false, the component is still rendered, but then with CSS display:none; so that it is visually hidden in the HTML DOM tree, so that you can redisplay it with just JavaScript.

See also:

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