Managed Bean method not called by menuitem?!

UI Components for JSF
Post Reply
Verhaag, G.C.H.M.
Posts: 103
Joined: 09 Oct 2012, 12:55
Location: Netherlands

05 Mar 2013, 13:50

Hi,

I'm experiencing strange behaviour in relation to a menu!

Setting up a menu is rather trivial like:

Code: Select all

<p:menubar>
<p:menuitem value="Logout" action="#{loginBean.logout}" icon="ui-icon-power" ajax="false"/>
                </p:menubar>
However the "loginBean" (RequestScoped) method "logout" seems not to be called, when pressing the Logout menubutton!

The method looks like:

Code: Select all

public String logout() {
        
        System.out.println("Logging out!");
        if (loggedIn) {
            loggedIn = false;
        }
        return "login";
    }
The GlassFish server log never shows the "Logging out!" phrase!

Probably I'm missing something very basic here?!

Regards,
Verhaag, G.C.H.M.
PrimaFaces 3.5, JSF 2.1, GlassFish server 3.1.2

rubus
Posts: 517
Joined: 01 Oct 2010, 09:41
Location: Belgium

05 Mar 2013, 15:05

Hello,

Is the menuBar enclosed by a form element?

Do you see the HTTP post in the 'console' of the browser?

Rudy
PrimeFaces version 3.5, Tomcat 7, Mojarra 2.1.13
PrimeFaces version 4.0, Glassfish 4.0
PrimeFaces version 5.0, WLS 12.1.2
If you haven't read the forum rules read them now : viewtopic.php?f=3&t=1194

Verhaag, G.C.H.M.
Posts: 103
Joined: 09 Oct 2012, 12:55
Location: Netherlands

05 Mar 2013, 15:30

Hi,

Yes it is enclosed within a form tag like:

Code: Select all

<ui:composition>
            <h:form id="menubar">
               <menubar>....</menubar>
             </h:form>
         </ui:composition>
This code fraction is part of a menubar.xhtml, which is loaded by the layout.xhtml that contains the following:

Code: Select all

<p:layout fullPage="true" >

            <p:layoutUnit position="north" size="50" >
                <ui:insert name="menubar" >
                    <ui:include src="/menuBar.xhtml" />
                </ui:insert>
            </p:layoutUnit>
            .....
         </p:layout>
This latter page (layout.xhtml) is displayed after the login to the application was successfull!

Regards,
Verhaag, G.C.H.M.
PrimaFaces 3.5, JSF 2.1, GlassFish server 3.1.2

rubus
Posts: 517
Joined: 01 Oct 2010, 09:41
Location: Belgium

05 Mar 2013, 15:53

Hello,

Don't know if that is the reason but your mixing a few concepts of templating I think.

ui:insert -> used in the template file. Will be replaced by the section in the actual page defined with a ui:define
ui:include -> To include a HTML fragment (so don't use it in the combination with ui:composition)
ui:composition -> Used for templating, not needed for ui:include (in menubar.xhtml)

So I would make

menubar.xhtml

Code: Select all

<h:form id="menubar">
               <menubar>....</menubar>
             </h:form>
(without the ui:composition)


And the layout.xhtml

Code: Select all

<p:layout fullPage="true" >

            <p:layoutUnit position="north" size="50" >
                    <ui:include src="/menuBar.xhtml" />
            </p:layoutUnit>
            .....
         </p:layout>
form and full page layout -> Looks ok, a layoutUnit shouldn't be included inside a form.

Rudy
PrimeFaces version 3.5, Tomcat 7, Mojarra 2.1.13
PrimeFaces version 4.0, Glassfish 4.0
PrimeFaces version 5.0, WLS 12.1.2
If you haven't read the forum rules read them now : viewtopic.php?f=3&t=1194

Verhaag, G.C.H.M.
Posts: 103
Joined: 09 Oct 2012, 12:55
Location: Netherlands

05 Mar 2013, 16:18

Hi,

Thanks for your advice, and I'm indeed afraid that I don't grasp some basic concepts!

However, removing the <ui:composition> from the menubar.xhtml doesn't help, the "logout" method is still not being called!

Might it have something to do with the fact that the file layout.xhtml is loaded from the result of the login method from the managed bean "loginBean"?

Regards,
Verhaag, G.C.H.M.
PrimaFaces 3.5, JSF 2.1, GlassFish server 3.1.2

Ksharp
Posts: 118
Joined: 12 Sep 2012, 08:58
Location: China

06 Mar 2013, 07:19

Was your manage bean SessionScoped ? or try process="@this"




Ksharp
PrimeFace 3.4.2 | GlassFish 3.1.2 | JSF 2.0 | NetBeans 7.1

Verhaag, G.C.H.M.
Posts: 103
Joined: 09 Oct 2012, 12:55
Location: Netherlands

06 Mar 2013, 11:16

Hi,

No, managed bean was requestscoped, but changing it to sessionscope doesn't help!

What about process=@this, where to put that?

Regards,
Verhaag,G.C.H.M.
PrimaFaces 3.5, JSF 2.1, GlassFish server 3.1.2

Verhaag, G.C.H.M.
Posts: 103
Joined: 09 Oct 2012, 12:55
Location: Netherlands

06 Mar 2013, 13:11

Hi,

I'm really in need of a solution to this basic issue!

Let me try to explain the problem in some detail. I've an initial window which gives the user the possibility to login. When the credentials are correct the current window is replaced by the main window of the application with a menubar at the top.

This is accomplished with:

Code: Select all

<p:commandButton id="loginButton" value="Login" action="#{loginBean.login}......
The login method returns redirects the user to the new window. This is working as aspected.

Now when clicking the Logout button, available from this main window, the logout method seems not to triggered?
The managed bean now runs in sessionscope!

When I initiate the application without the login, just starting with the main window, the logout button works as aspected!

That is something I don't understand! Can anybody explain that to me, please!

Regards,
Verhaag, G.C.H.M.
PrimaFaces 3.5, JSF 2.1, GlassFish server 3.1.2

linen
Posts: 66
Joined: 22 Jun 2011, 19:01

17 Apr 2013, 00:58

Verhaag, G.C.H.M. wrote: ....
What about process=@this, where to put that?
....
Inside the menuItem tag...

Code: Select all

<p:menuitem process="@this" .... />

I made this inclusion and it solved my problem, same as yours, the actionListener method wasn't being called.
Java 6 -- JSF Mojarra 2.2.1 -- PrimeFaces 4.0 -- Tomcat 7.0.34
Eclipse Juno Java EE -- Mac OS X 10.8.5 -- Safari 6.1.2 -- Chrome 35.0.1916

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 14 guests