a4j:actionparam equivalent

UI Components for JSF
r.a.
Posts: 2
Joined: 12 Sep 2011, 17:26

12 Sep 2011, 17:40

Hi,

I had this code working (RichFaces):

There is a map with some elements mapped:

Code: Select all

<map name="image_diagramMap" id="image_diagramMap">
       <area shape="rect" class="diagelem" coords="260,224,350,284"  onclick="myFunction('code_parameter');" />
</map>
When you click the element it calls the following function:

Code: Select all

<a4j:jsFunction name="myFunction" action="#{MyClass.refreshElements}" oncomplete="#{rich:component('popupElement')}.show();" reRender="popupElement">
            <a4j:actionparam name="code" assignTo="#{MyClass.codeParam}"  />                  
</a4j:jsFunction>

I'm trying to do it using PrimeFaces but I can't find a way to set "MyClass.codeParam" with "code_parameter"



Thank you.

r.a.
Posts: 2
Joined: 12 Sep 2011, 17:26

15 Sep 2011, 20:05

Well, I solved my problem this way:

Code: Select all

<map name="image_diagramMap" id="image_diagramMap">
       <area shape="rect" class="diagelem" coords="260,224,350,284"  onclick="myFunction('code_parameter');" />
</map>

Code: Select all

<script type="text/javascript">
		function myFunction(parameter) {
		   document.getElementById("#{p:component('inputHiddenID')}").value = parameter;
		   remoteCommandName();
	    }
</script>

Code: Select all

<h:form>
        <h:inputHidden id="inputHiddenID" value="#{MyClass.codeParameter}"/>	 	
        <p:remoteCommand  name="remoteCommandName" actionListener="#{MyClass.myAction}"  oncomplete="popup.show();" update="popupElemento">      
        </p:remoteCommand>
</h:form>

faisalgeek
Posts: 29
Joined: 28 Mar 2010, 14:45

16 Sep 2011, 09:01

That's great solution. In fact I was faced the same problem. Thanks for sharing your stuff.
MyEclipse for Spring 9.0 , Tomcat 6.0, Jboss 6.0, PrimeFaces 3.0.RC2 , Mojarra 2.1.4 (JSF 2.1) - http://www.javaplex.com

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

16 Sep 2011, 12:36

i think i will implemented this feature in primefaces-extensions. Something like:

Code: Select all

<pe:remoteCommand name="test" update="something" ...>
      <pe:remoteCommandParameter name="val1" applyTo="#{bean.val1}" />
      <pe:remoteCommandParameter name="val2" applyTo="#{bean.val2}" />
</pe:remoteCommand>
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

16 Sep 2011, 13:28

Thomas, I like your idea. I think we can do that even better. If parameter is plain (string, number, etc.) ==> no changes for your approach (only conversion should be usefull too, e.g. is you pass time as long and convert to java.lang.Date). If parameter is a complex JS object ==> convert it into JSON string and deserialize service-side in Java object (DWR-like approach). I have done similar tasks many times. We have then

Code: Select all

<pe:remoteCommand name="test" update="something" ...>
      <pe:remoteCommandParameter name="paramPlain" applyTo="#{bean.paramPlain}" />
      <pe:remoteCommandParameter name="paramComplex" applyTo="#{bean.paramComplex}" />
</pe:remoteCommand>
where "paramComplex" is e.g. an JS array / object client-side. Server-side it's an Java array or JavaBean.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

16 Sep 2011, 13:38

Thanks Oleg.
Is there an example available how to convert it?
Should we also implement support for converter childs? (e.g. f:converter)
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

16 Sep 2011, 13:53

Hi Thomas,

Support for f:converter would be great. I use Gson for JavaScript-Java conversion. There are some related posts in my blog

http://ovaraksin.blogspot.com/2011/05/j ... asses.html
http://ovaraksin.blogspot.com/2011/05/t ... ation.html

but you can implement only plain object support at first. I will add a support for complex objects later.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

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

16 Sep 2011, 14:21

Code: Select all

<pe:remoteCommand name="test" update="something" ...>
      <pe:remoteCommandParameter name="val1" applyTo="#{bean.val1}" />
      <pe:remoteCommandParameter name="val2" applyTo="#{bean.val2}" />
</pe:remoteCommand>
can be implemented as;

Code: Select all

<p:remoteCommand name="test" />

Code: Select all

test({val1:'#{bean.val1}', val2:'{bean.val2}'});
for dynamic params, for static params you can use f:param already. I'd provide val1 and val2 as converted from backing bean instead, less tags more java.

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

16 Sep 2011, 14:56

Writing of

Code: Select all

test({val1:'#{bean.val1}', val2:'{bean.val2}'});
is not quite intuitive. Declarative way seems to be better. That's as we write f:ajax / p:ajax in JavaScript instead of using these tags. Furthemore built-in JSON support for passing complex objects is not available in p:remoteCommand.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

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

16 Sep 2011, 15:07

Code: Select all

test({val1:'#{bean.val1}', val2:'{bean.val2}'});
I like it, still you can use f:param tags inside remoteCommand. Both approaches are supported.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 27 guests