Board index JavaServer Faces General a4j:actionparam equivalent

a4j:actionparam equivalent

Components, Ajax Framework, Utilities and More.

Post 12 Sep 2011, 17:40

Posts: 2
Hi,

I had this code working (RichFaces):

There is a map with some elements mapped:

<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:

<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.

Post 15 Sep 2011, 20:05

Posts: 2
Well, I solved my problem this way:

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


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


<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>

Post 16 Sep 2011, 09:01

Posts: 29
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

Post 16 Sep 2011, 12:36
tandraschko PrimeFaces Core Developer

Posts: 2160
Location: Bavaria, DE

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

<pe:remoteCommand name="test" update="something" ...>
      <pe:remoteCommandParameter name="val1" applyTo="#{bean.val1}" />
      <pe:remoteCommandParameter name="val2" applyTo="#{bean.val2}" />
</pe:remoteCommand>
Always Bet On Prime (+ Extensions)!

PrimeFaces Extensions: https://github.com/primefaces-extensions
OpenWebBeans: http://openwebbeans.apache.org/
DeltaSpike: http://deltaspike.apache.org/
Personal Blog: http://tandraschko.blogspot.de/

Post 16 Sep 2011, 13:28
Oleg User avatar
Expert Member

Posts: 3701
Location: Russia, Siberia => Germany, Black Forest
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

<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 4.x, 5.x, Mojarra 2.2.x, JBoss WildFly, WebSphere, Windows 8.1, IntelliJ IDEA
PrimeFaces Cookbook: http://ova2.github.com/primefaces-cookbook/ PrimeFaces Extensions on GitHub: http://primefaces-extensions.github.com/

Post 16 Sep 2011, 13:38
tandraschko PrimeFaces Core Developer

Posts: 2160
Location: Bavaria, DE

Thanks Oleg.
Is there an example available how to convert it?
Should we also implement support for converter childs? (e.g. f:converter)
Always Bet On Prime (+ Extensions)!

PrimeFaces Extensions: https://github.com/primefaces-extensions
OpenWebBeans: http://openwebbeans.apache.org/
DeltaSpike: http://deltaspike.apache.org/
Personal Blog: http://tandraschko.blogspot.de/

Post 16 Sep 2011, 13:53
Oleg User avatar
Expert Member

Posts: 3701
Location: Russia, Siberia => Germany, Black Forest
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 4.x, 5.x, Mojarra 2.2.x, JBoss WildFly, WebSphere, Windows 8.1, IntelliJ IDEA
PrimeFaces Cookbook: http://ova2.github.com/primefaces-cookbook/ PrimeFaces Extensions on GitHub: http://primefaces-extensions.github.com/

Post 16 Sep 2011, 14:21

Posts: 15042
Location: Cybertron

<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;

<p:remoteCommand name="test" />


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.
PrimeFaces Lead

Post 16 Sep 2011, 14:56
Oleg User avatar
Expert Member

Posts: 3701
Location: Russia, Siberia => Germany, Black Forest
Writing of

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 4.x, 5.x, Mojarra 2.2.x, JBoss WildFly, WebSphere, Windows 8.1, IntelliJ IDEA
PrimeFaces Cookbook: http://ova2.github.com/primefaces-cookbook/ PrimeFaces Extensions on GitHub: http://primefaces-extensions.github.com/

Post 16 Sep 2011, 15:07

Posts: 15042
Location: Cybertron

test({val1:'#{bean.val1}', val2:'{bean.val2}'});


I like it, still you can use f:param tags inside remoteCommand. Both approaches are supported.
PrimeFaces Lead

Next

Return to General