0

I just upgraded my primefaces library from 3.1.1 to 3.4.1, but unfortunately not able to get the parameter from request parameter map from FacesContext in my bean.

Below are my code snippet.

xhtml file:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui">

<h:head>
    <title>Facelet Title</title>
</h:head>   
<h:form>
    <p:remoteCommand name="setData" actionListener="#{serviceClass.setrealData()}"/>
</h:form>
 <script>
        $(document).ready(function(){
            setData({codes:'J203,J200,J212,J211,J210',fields:'SNAME,SPOT,PERC,POINTS'});
        });
 </script>
</html>

Bean:

@ManagedBean
@SessionScoped

public class ServiceClass {

    /** Creates a new instance of ServiceClass */
    public ServiceClass() {
    }

    public void setrealData(){
        FacesContext fc = FacesContext.getCurrentInstance();
        Map map2 = fc.getExternalContext().getRequestParameterMap();
        String newCodes = (String) map2.get("codes");
        System.out.println("New codes ::"+newCodes);
    }
}
Paul Fleming
  • 22,772
  • 8
  • 65
  • 107
user595226
  • 89
  • 3
  • 10
  • the `remoteCommand` component can be triggered with custom client side script and can call backing bean methods, do partial updates, etc. [RemoteCommand](http://www.primefaces.org/showcase/ui/remoteCommand.jsf). Is this code worked in 3.1.1? – Akos K Oct 31 '12 at 20:22

1 Answers1

0

The parameters passed to the setData javascript function is incorrect. You seem to have misplaced the braces separating each key value pair.

Should have been:

<script>
    $(document).ready(function(){
        setData([{codes:'J203,J200,J212,J211,J210'} , {fields:'SNAME,SPOT,PERC,POINTS'}]);
    });
</script>

With this format you should be able to retrieve (codes and fields) from the request map. Code should yield a String "J203,J200,J212,J211,J210" while fields should yield "SNAME,SPOT,PERC,POINTS"

Tyler Hyndman
  • 1,352
  • 3
  • 16
  • 24
Olofu Mark
  • 19
  • 1