user2683519
user2683519

Reputation: 767

How can I call a method with requestParameterMap from other controller

I want to call a method with requestParameterMap from other controller. How can I call this method. I want to reuse the method without modifying.

First controller:

public void visualizarPartida(){
 refNumPart ='data'
 estado = 'data'
 //ETC.........
 partidaDirectaController.visualizarPartidaDetalle(?????????) /*doubt*/

 }

Second controller:

@ManagedBean
@SessionScoped
public class PartidaDirectaController {

public void visualizarPartidaDetalle() {
    Map<String, String> params = FacesContext.getCurrentInstance()
   .getExternalContext().getRequestParameterMap();
    PartidaDirectaResultBean obj = new PartidaDirectaResultBean();
    obj.setRefNumPart(params.get("refNumPart"));
    obj.setEstado(params.get("estado"));
       //ETC...
    }

Upvotes: 1

Views: 93

Answers (1)

BalusC
BalusC

Reputation: 1108632

Just refactor the code you'd like to reuse from other method(s) into a new method taking the data as arguments, so that you can invoke it from both methods.

public void visualizarPartida() {
    refNumPart = "data"; // Please write code which compiles. Also in questions!
    estado = "data";
    partidaDirectaController.visualizarPartidaDetalle(refNumPart, estado);
}
public void visualizarPartidaDetalle() {
    Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
    visualizarPartidaDetalle(params.get("refNumPart"), params.get("estado"));
}

public void visualizarPartidaDetalle(String refNumPart, String estado) {
    PartidaDirectaResultBean result = new PartidaDirectaResultBean();
    result.setRefNumPart(refNumPart);
    result.setEstado(estado);
    // Etc...
}

Upvotes: 1

Related Questions