This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Call 2 managed bean passed as parameters to the same method of another class  RSS feed

 
daniele galassi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a class (X) method that accepts as a parameter manaded bean (Y) which calls the class (X) method and makes a call to a service and returns a user.

In another managed bean (Z) I have to do the exact same thing. Is there a way to abstract the parameter of the managed bean (Y) passed to the class (X) method ? In practice I not want to have to create a new method in the class (X) that accepts as a parameter the managed bean (Z)?
thanks
 
Tim Holloway
Bartender
Posts: 18703
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Daniele!

Classes don't have parameters. Methods do, but JSF action methods should not, as they get their "parameters" from the backing bean's properties and therefore don't need to have them explicitly passed.

You can certainly create a shared backing bean (session or application-scoped) that can then be injected as a ManagedProperty into other backing beans.
 
daniele galassi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Tim,
this is the code:

CertificatoreDB.class
public class CertificatoreBD{
...
public ResponseDTO getLavoratriceByCodiceFiscale(InserimentoCertificatoGravidanza inserimentoCertificatoGravidanza) throws CertificazioniWebException{
try{
//retrieves information of the worker as a function of the tax code
...
}
}

InserimentoCertificatoGravidanza.class
@ManagedBean
@ViewScoped
public class InserimentoCertificatoGravidanza extends Operazione{
...
public String conferma(){
...
ResponseDTO responseDTO = new CertificatoreBD().validazioneCertificatoDiGravidanza(this);
...
}
}

Here i have engineer new managed bean:
InserimentoCertificatoInterruzione.class
@ManagedBean
@ViewScoped
public class InserimentoCertificatoInterruzione extends Operazione{
...
public String conferma(){
...
ResponseDTO responseDTO = new CertificatoreBD().validazioneCertificatoDiInterruzione(???);
...
}
}
 
Tim Holloway
Bartender
Posts: 18703
71
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. You can make your code samples easier to read if you use our "Code" button on the editor. It preserves your formatting.

You are looking to include an object which requires an argument to construct it. JSF cannot manufacture such objects, although other systems such as the Spring Framework can.

Lacking such a framework, here's one possibility:


 
daniele galassi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Tim,
the since in my 2 managed Bean is not


but:




It's the same for your good solution?

another thing: if I do not step away from method getLavoratriceByCodiceFiscale of managed bean "InserimentoCertificatogravidanza" what happens?
 
Tim Holloway
Bartender
Posts: 18703
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The name and function of the method(s) invoked doesn't matter. What I was attempting to illustrate was the structure. You have a shared bean that is initialized from logic in one bean and used by logic in another bean. Because this shared bean is a ManagedBean, JSF will automatically construct it and inject it into the 2 beans that use it as a ManagedProperty.
 
daniele galassi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tks Tim i understand it
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!