• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tks Tim i understand it
reply
    Bookmark Topic Watch Topic
  • New Topic