3

I'm facing the following problem:

The Primefaces remoteCommand is not executing, does it depend on the lifecycle of my portlet?

 <h:form id="controllayer">
 .
 .
 .
 <p:remoteCommand name="updatePageId" actionListener="#{formView.updatePageId}" />
 </h:form>
 <script>   
    var pageID;

    Liferay.on('eventFire', function(event)
     {
      console.log("Recieved");
      console.log(event.name);
      pageID = event.name;
      update();
     });

    function update() {

      console.log("Recieved PageID: " + pageID);
      updatePageId({newPageId: pageID});
    }

 </script>

I also tried it without a parameter but even this isn't working.

@SessionScoped
@ManagedBean(name="formView")
public class MainViewBean implements PagesUploadCallback, PageUploadCallback, PageActionCallback, Serializable
{
 .
 .
 .
 public void updatePageId()
 {
  LOG.info("Update Page ID");
  String pageIdString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("newPageId");
  long pageId = Long.valueOf(pageIdString);
  LOG.debug("Setting Page: " + pageId);
  pageService.setActivePage(pageId);
 }
.
.
.
}

My JavaCode is never called.

Erythrozyt
  • 802
  • 6
  • 21
  • 1
    _"does it depend on the lifecycle of my portlet?"_ No idea, try an [mcve] in a plain servlet container – Kukeltje Jan 07 '16 at 11:27
  • 1
    I believe that the JS method name `update` should match the value (`updatePageId`) of ``. You could create `updatePageId()` as JavaScript method and change the `actionListener` to something else like `updatePageIdBean` to differentiate both as well, might that be causing issue! – Parkash Kumar Jan 08 '16 at 07:11
  • See [***remoteCommand***](http://www.primefaces.org/showcase/ui/ajax/remoteCommand.xhtml) – Parkash Kumar Jan 08 '16 at 07:15
  • 3
    @Erythrozyt, I tried your code and everything is working fine for me. Did `Recieved` or `Recieved pageID:` show up in the JS console? Do you have any javascript errors? What code fires the `'eventFire'` event? **Note:** I fired the the event via this `p:commandButton`: `` – stiemannkj1 Jan 11 '16 at 14:11
  • 1
    Are there other inputs in the h:form that are possibly invalid and prevent the actionListener? Is the update() script ever invoked? Any error in JavaScript console? See also this for additional analyzis: [commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated](https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value) – Selaron Aug 30 '19 at 07:46
  • @Kukeltje hello people, I think the problem here might be the scope of the app, did you try viewscoped? – BugsForBreakfast Sep 03 '19 at 22:16
  • @BugsForBreakfast: a scope is more often too short instead of too long. The link posted by Selaron shout be inspected – Kukeltje Sep 03 '19 at 22:23

1 Answers1

2
<p:remoteCommand name="docheck" 
         process="@form,box1,box2"
         update="box1,box2"
         action="#{testBean.myAction()}" />

this is an example how u need to change your code so. This will fix your issue. For Further reference refer the link below:

https://forum.primefaces.org/viewtopic.php?p=61733&sid=bf526834599e119a2d8a4e0f9a6989fb#p61733