-3

What I want is to hide the login and register section of the html after user logs in with his account, but it doesn't seem to be working.

Here is the HTML and JavaScript code:

<div class="u lf " id="checkviewuser">
  <span>
    <a id="numero2" href="/RIDOApp/login.xhtml">login</a><b> | </b>
    <a id="numero1" href="/RIDOApp/registraction.xhtml">register</a>  
  </span>
</div>

<div class="lf">
  <h:outputText value="&#160;&#160;Welcome Back, #{userBean.firstName} &#160;&#160;" rendered="#{userBean.isLogin}" />
  <p:commandLink value="logout" rendered="#{userBean.isLogin}" action="#{userBeanController.logout}" />
</div>

<script type="text/javascript">
  if (('' + #{
      userBean.firstName
    } + 0) == 0) {
    $("#yhzx").hide();
    $("#checkviewuser").show();

  } else {
    $("#yhzx").show();
    $("#checkviewuser").hide();
  }
</script>
charliebrownie
  • 5,777
  • 10
  • 35
  • 55
Francis
  • 11
  • 4

1 Answers1

0

You could use a panelGroup to wrap all the elements that are not visible when the user is logged in, and use the rendered attribute, like you did with the commandLink to tell JSF whether to show them or not. No javascript necessary.

Something like this:

<h:panelGroup rendered="#{not userBean.isLogin}">
    <div class="u lf " id="checkviewuser">
        <span><a id="numero2" href="/RIDOApp/login.xhtml">login</a><b> | </b>
        <a id="numero1" href="/RIDOApp/registraction.xhtml">register</a> </span>
    </div>
</h:panelGroup>
Ángela
  • 1,405
  • 18
  • 24