Page 1 of 2
a4j:actionparam equivalent
Posted: 12 Sep 2011, 17:40
by r.a.
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.
Re: a4j:actionparam equivalent
Posted: 15 Sep 2011, 20:05
by r.a.
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>
Re: a4j:actionparam equivalent
Posted: 16 Sep 2011, 09:01
by faisalgeek
That's great solution. In fact I was faced the same problem. Thanks for sharing your stuff.
Re: a4j:actionparam equivalent
Posted: 16 Sep 2011, 12:36
by tandraschko
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>
Re: a4j:actionparam equivalent
Posted: 16 Sep 2011, 13:28
by Oleg
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.
Re: a4j:actionparam equivalent
Posted: 16 Sep 2011, 13:38
by tandraschko
Thanks Oleg.
Is there an example available how to convert it?
Should we also implement support for converter childs? (e.g. f:converter)
Re: a4j:actionparam equivalent
Posted: 16 Sep 2011, 13:53
by Oleg
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.
Re: a4j:actionparam equivalent
Posted: 16 Sep 2011, 14:21
by cagatay.civici
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
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.
Re: a4j:actionparam equivalent
Posted: 16 Sep 2011, 14:56
by Oleg
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.
Re: a4j:actionparam equivalent
Posted: 16 Sep 2011, 15:07
by cagatay.civici
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.