Composite vs. Bean CDI - how to access Bean methods

I am trying to create a component to receive the user profile picture. But for this I need to make the component access 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 primefaces:

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

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

Any direction on where am I going wrong?

Grateful,

Author: alacerda, 2017-04-05

1 answers

I believe that because it is not a @ManegedBean the JSF scopes did not work properly.

Try using any of the CDI scopes:

  1. ApplicationScoped-the state of the bean remains during the application lifecycle.
  2. SessionScoped-The Bean lifecycle is linked to the user session.
  3. RequestScoped - a new Bean will be created with each request.
  4. Dependent-depends on the scope of who injects the Bean.
  5. ConversationScoped-allows the Bean to transition between a RequestScoped and a SessionScoped lifecycle programmatically.

Obs.: These scopes are in the javax package.enterprise.context

 0
Author: Jefferson Borges, 2017-04-13 13:13:13