Composite vs. Bean CDI - How to access bean methods

2

I'm trying to create a component to receive the photo from the user's profile. But for this I need to make the access component the methods within the CDI Bean of the page in question. I'm doing something like this:

Creating the component:

<composite:interface displayName="profilePhoto">
<composite:attribute name="mBean" type="br.com.fm.modelo.abstracts.ProfilePhoto" required="true"
shortDescription="Bean que gerencia esta página." />
</composite:interface>

<composite:implementation>
[...cut...]
<p:commandButton action="#{cc.attrs.mBean[fecharFotoDialog]}"/>
[...cut...]
</composite:implementation>

Creating the Bean:

@Named
@ViewScoped
public class CadastroUsuario extends ProfilePhoto implements Serializable {
public void fecharFotoDialog() {
System.out.println("Entrei nesse treco aqui...");
}
}

Calling the component in the firstfaces:

<t:profilePhoto mBean="#{cadastroUsuario}"/>

What do I expect to happen? That by clicking on the button that is in the component the fecharFotoDialog() method is called.

Some direction on where I'm going wrong?

Thank you,

    
asked by anonymous 05.04.2017 / 16:30

1 answer

0

I believe that because it was not a @ManegedBean the JSF scopes did not work correctly.

Try using one of the CDI scopes:

  • ApplicationScoped - The state of the bean remains during the application lifecycle.
  • SessionScoped - The Bean lifecycle is bound to the user session.
  • RequestScoped - A new Bean will be created for each request.
  • Dependent - Depends on whoever injects the Bean.
  • ConversationScoped - Allows the Bean to pass between a RequestScoped and a SessionScoped lifecycle programmatically.
  • Note: These scopes are in the javax.enterprise.context package

        
    13.04.2017 / 15:00