How to call managed bean methods with parameters via JavaScript

后端 未结 2 1759
感动是毒
感动是毒 2020-12-09 06:53

I am developing a web application and I use JSF and PrimeFaces frameworks and external Geo Map API.

The Map API gives me POI_id when I clicked on a POI

2条回答
  •  误落风尘
    2020-12-09 07:43

    Just to add to Kishor's (halfway) answer, you need to have a to-be-updated component in your view (popup window as you call it) and ajax-update it after the request has been successfully completed.

    You can use remote command to send the AJAX request with an extra parameter attached and ajax-update the JSF component responsible to be a popup window. Like so (for PrimeFaces 3.x):

    
    ...
    
    ...
    ... ...(display other information)

    with

    String address;
    public void listen(){
        String poi_id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("poi_id");
        address = getAddress(poi_id);
    }
    

    The alternative to using a remote command is to have a hidden form with a hidden input that will be used to transmit the parameter to the backing bean, that could be separated from other beans to handle the retrieval of necessary information based on your poi_id:

    
        
        
    
    
    ...
    ... ...(display other information)

    with

    @ManagedBean
    @RequestScoped
    public class PoiBean {
    
        private String poi;//getter+setter
        private String address;//getter
        //other properties
    
        public void listen(){
            address = getAddress(poi);
            //other properties
        }
    
    }
    

提交回复
热议问题