开发者

How to show a component by the controller?

开发者 https://www.devze.com 2023-04-07 00:45 出处:网络
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.

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" autosiz开发者_开发问答ed="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.


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:

  • Conditionally displaying JSF components
0

精彩评论

暂无评论...
验证码 换一张
取 消