Composite vs. Bean CDI - How to access bean methods

Asked

Viewed 74 times

2

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 on the primefaces:

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

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

Any direction where I’m going wrong?

Grateful,

  • So it doesn’t work? action="#{cadastroUsuario.fecharFotoDialog()}"

  • @Douglas you mean put that where? In the implementation of Composite or in the <t:profilePhoto component>?

  • In implementation.

  • @Douglas, it doesn’t work. But even so, Composite cannot have the name of Bean hardcoded, it has to receive this at the time of component implementation.

  • I’ve tried this too: <Composite:attribute name="mbean" required="true" shortDescription="Bean that manages this page."/>

  • The answers seem simple to this question, but they don’t really work. Nor does an exception appear. You have this example: http://stackoverflow.com/questions/24018539/passing-a-backing-bean-instance-as-parameter-to-composite-component

Show 1 more comment

1 answer

0

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

Try using one 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 for each request.
  4. Dependent - Depends on the scope of who injects the bean.
  5. Conversationscoped - Allows the Bean to transition between a Requestscoped life cycle and a Sessionscoped programmatically.

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

  • He’s my friend, it doesn’t work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.