Best practice to send parameters to RemoteCommand

UI Components for JSF
Post Reply
jasje
Posts: 16
Joined: 03 Aug 2010, 07:53

03 Aug 2010, 08:06

I have a gallery component that loads thumbnails in a <ui:repeat> control.
Now when I click on the thumbnail, I need to call a bean method, but with a parameter (in this case the image ID to retreive the image details)

In all samples, a textinput is used which is bound to a bean property, but in this case I will need to set the property directly through javascript.

Anyone who can point me to the right direction?

Thanks a lot

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

03 Aug 2010, 11:27

I think you need to use the client side api instead of remoteCommand. User's Guide has a section on how to use PrimeFaces.ajax.* javascript api. Third parameter of this function takes a parameters as a javascript hash. You can use it to send custom parameters.

p:remoteCommand also supports f:param tag, but it will be created once with those specific parameters and not possible to change it. So using javascript api directly would be easy.

eitch
Posts: 5
Joined: 13 Jul 2010, 12:45

07 Sep 2010, 15:00

If I would want to use the javascript api, how could I then know what the URL for an bean method is?

I have a page where I have an SVG graphics and I want to do drag and drop. So I have java script running which detects the drop, but I don't know how to notify a bean of the value selected. I would then also have to set a value on the bean so that I know which object was dropped where.
Primefaces 2.0.2
Mojarra JSF 2.0.2-FCS
Tomcat 6.0.26

User avatar
kwintesencja
Posts: 316
Joined: 08 Feb 2010, 20:33
Location: Brazil

02 Sep 2011, 15:57

Hi there,

i do need to pass parameter via javascript to remoteCommand, how can i do that?

here some code:

Code: Select all

<script type="text/javascript">

   function onload() {
    var x = someParamReturnedByAnotherFunction;
     lazyLoad(x);//here i want to pass the param to remoteCommand
   }

</script>

<p:remoteCommand name="lazyload" update="lazypanel" action="#{managedBean.test(param)}">  
      
    </p:remoteCommand>  


Managed Bean
public class managedBean{

     public void test(string x) {
        System.out.println(x);
     }
}

thanks in advance;
Att,

--

Rafael Mauricio Pestano


Primefaces 5.x + JavaEE7(Glassfish 4.x and Wildfly 8)
Conventions Framework
Blog
@realpestano

User avatar
kwintesencja
Posts: 316
Joined: 08 Feb 2010, 20:33
Location: Brazil

02 Sep 2011, 20:59

can anyone tell me if its possible:

Code: Select all

function startApplet() {
    var x = "test"
    lazyload({param:x});
}
 
<p:remoteCommand name="lazyload" update="lazypanel" actionListener="#{authenticationController.test}"/>
     
mbean
public void test(ActionEvent event) {
    String param = (String) event.getComponent().getAttributes().get("param");
    System.out.println(param );
}
the mbean method is not being called, and no js errors are displayed in firebug.

using PF 3.0M2, Mojarra 2.1
Att,

--

Rafael Mauricio Pestano


Primefaces 5.x + JavaEE7(Glassfish 4.x and Wildfly 8)
Conventions Framework
Blog
@realpestano

ertiop93
Posts: 97
Joined: 29 May 2011, 16:14

02 Sep 2011, 21:15

Hi kwintesencja,

A few days back I was looking out for a similar solution. Though I could find out a way to pass parameters into remoteCommand but I figured out a way, (from BalusC's blog) that you could use a hidden input field submit that was set by javascript and hence pass your parameter from js to JSF. My code for this follows:-

I would really appreciate if someone can look at this and kindly let us know, if this is the best way to pass parameters from js to JSF.


Code: Select all

<script>
    function prepareForShowingDetails(idOfSelected) {
        document.getElementById('selectedItemId_in').value = idOfSelected;                  //setting the hidden input field with the parameter required to be passed .....
        showDetails();                                                                                                 // calling remoteCommand to show the content details
    }
    </script>

    <h:form prependId="false" >
        <h:inputHidden id="selectedItemId_in" value="#{list.selected}"/>
        <p:remoteCommand name="showDetails" process="selectedItemId_in" update="detailsPanel" oncomplete="detailsDialog.show()"/>
    </h:form>
****************************
Using Primefaces 3.4 Snapshot with JSF(Myfaces) 2.1.8

****************************

baspet
Posts: 37
Joined: 18 Jan 2011, 14:53

03 Sep 2011, 00:36

Hi,

i am doing exactly what you proposed :D

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 24 guests