jsf - Preprocess/postprocess a bean action method from p:remoteCommand inside composite -
i have following scenario:
jsf composite component complex javascript, i'd refresh partially javascript new values backing bean (backing bean of page uses composite component, not backing component @facescomponent
). i don't want make full update because it's complex javascript plugin , unacceptably break ux.
i values backing component @facescomponent
using primefaces's <p:remotecommand>
callback described here best method passing data java/jsf2 bean javascript/jquery components
i know it's abuse of jsf encapsulate functionality in single unit , don't mess jax-rs if can advice nice solution how encapsulate such complex jquery plugin (for sake of clarity talking fullcalendar, know primefaces has own implementation of component functionality insufficient requirement so, need make own implementation) highly related on ajax callbacks parameters you're highly welcome share here.
my question how update values in backing component @facescomponent
backing bean using javascript? involved in following chain of events:
calling javascript
<p:remotecommand>
parameters passed backing component@facescomponent
dispatched later inajaxbehaviorevent
javascript:
refreshevents([ {name:'start', value:start.format()}, {name:'end', value:end.format()} ]);
jsf code:
<p:remotecommand name="refreshvalues" oncomplete="loadvalues()" action="#{cc.refreshlocal()}" process="@this"/>
parameters passed stored in backing component using
getstatehelper().put(...);
jquery event dispatched composite component following javascript code:
var hiddenfield = $(document.getelementbyid(variables.hiddenid)); hiddenfield.trigger("keypress");
in composite component's overridden method
public void queueevent(facesevent event)
addajaxbehaviorevent
property stored before, in 1st step , dispatch forward.dispatched event composite component "captured" in page composite component nested , performed
process
on component:<p:ajax event="refreshevent" process="@this" listener="#{bean.refreshevents}"/>
in
#{bean.refreshevent}
method perform request@ejb
bean , load data.on callback step 1 called again
loadvalues()
<p:remotecommand name="loadvalues" action="#{cc.getlocaldata()}" oncomplete="updatevalues(xhr, status, args);"/>
in backing component's method
#{cc.getlocaldata()}
add callback parameter using:requestcontext.getcurrentinstance().addcallbackparam("param", ...);
function
updatevalues(xhr, status, args)
step 5 inargs
param's values , performs actual update.
so, general question possible simplify process , how?
thank you.
this indeed little overcomplicated. in total 3 ajax requests perform action , backing component passing data forth , via view state.
your primary goal appears able declare bean action method composite component attribute should invoked <p:remotecommand>
inside composite , return desired model entity based on passed-in parameters, preferably pre- , post-processing.
you can use <cc:attribute method-signature>
in composite interface declare method expression attribute:
<cc:interface componenttype="yourcomposite"> <cc:attribute name="eventlistener" method-signature="com.example.entity method(java.lang.string, java.lang.string)" required="true" /> </cc:interface>
which can used in template client below:
<my:composite ... eventlistener="#{bean.eventlistener}" />
public entity eventlistener(string start, string end) { // ... return entity; }
the composite implementation can this:
<cc:implementation> ... <p:remotecommand name="refreshevents" process="@this" action="#{cc.processeventlistener}" oncomplete="updatevalues(xhr, status, args)" /> ... </cc:implementation>
the #{cc.processeventlistener}
method can obtain eventlistener
attribute methodexpression
, invoke below, along pre- , post-processing:
public void processeventlistener() { string start = getrequestparameter("start"); string end = getrequestparameter("end"); // ... methodexpression method = (methodexpression) getattributes().get("eventlistener"); entity entity = (entity) eventlistener.invoke(getfacescontext().getelcontext(), new object[] { start, end }); // ... addcallbackparam("param", entityasjson); }
now it's 1 ajax request "as usual".
Comments
Post a Comment