0

I'm having trouble understanding why a action method on my ConversationScope'd bean doesnt fire. The bean is:

package org.work;

import java.io.Serializable;
import javax.enterprise.context.ConversationScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Named;

@Named
@ConversationScoped
public class NewClass implements Serializable {

    private static final long serialVersionUID = 6470665657635110586L;
    private boolean b1;

    public boolean isB1() {
        return b1;
    }

    public void setB1(boolean b1) {
        this.b1 = b1;
    }

    public void preRenderView(ComponentSystemEvent evt) {
    }

    public String peformAction() {
        return null;
    }
}

and my XHTML is:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <f:view>
        <h:head>

        </h:head>
        <f:metadata>
            <f:viewParam name="b1"
                         value="#{newClass.b1}" />
            <f:event type="preRenderView"
                     listener="#{newClass.preRenderView}"/>
        </f:metadata>
        <h:body>
            <h:form>
                <h:commandLink action="#{newClass.setB1(!newClass.b1)}"
                               style="background-color:  #{newClass.b1 ? 'darkorchid' : 'aquamarine'};"
                               value="btn3"/>
                <h:panelGrid rendered="#{newClass.b1}"
                             columns="1">
                    <h:commandLink value="edit"
                                   action="#{newClass.peformAction()}" />
                </h:panelGrid>
            </h:form>
        </h:body>
    </f:view>
</html>

The performAction() method is not fired after I press the commandLink that should invert the boolean making the other commandLink rendered. When debugging I can see that the boolean is set to true, but it seems to me the "rendered" attribute is evaluated before the viewparams is set. Is this true? The example works fine with @ManagedBean and @javax.faces.bean.ViewScoped.

mkjmkjmkj
  • 21
  • 4

1 Answers1

0

I think that you don't have long-running conversation. You could read more information on this site: http://docs.oracle.com/javaee/6/api/javax/enterprise/context/ConversationScoped.html

If you have transient conversation this bean is recreated after every request

  • The bean is correctly created on each conversation, and correctly stays instanciated until the conversation is over. This I've observed by debugging the constructor and a @PostConstruct method. – mkjmkjmkj Apr 16 '14 at 13:39
  • Injecting a Conversation interface and getting isTransient() says true all the time through the debugging process. – mkjmkjmkj Apr 16 '14 at 13:39
  • Am I to use the begin() and end() methods in the Conversation object to manually start and stop the long running bean? Shouldnt the container control this? – mkjmkjmkj Apr 16 '14 at 13:42
  • This is the beauty of conversation, that you control it. You must specify on which page it starts and on which page it ends. Container will automaticly destroy the bean when conversation will end. – Peter Wroblewski Apr 17 '14 at 12:06