3
votes

Here is the problem: actionlistener does not want to be fired

@ManagedBean(name="hotelsController")
@SessionScoped
   public class HotelsController implements Serializable {
      public void requestHotelAvail(ActionEvent event) {
         request = new Request(df.format(arrivalDate), df.format(departureDate));
      }
   }

and xhtml

<h:panelgroup id="rooms"/>
<h:form  id="hotelSearch">
            <p:commandButton actionListener="#{hotelsController.requestHotelAvail}" value="submit" update="rooms" />
</h:form>

I have tried everything I could search of changed @managedbean to @component set import to import javax.faces.event.ActionEvent;

But it still does not fire anything.

Form is in a p:accordion and when used with h:commandbutton it works fine

EDIT: sorry for mislead. rooms updates after click but actionListener is not fired. so rooms will not get any new data. Important code in requestHotelAvail needs to be fired before updating rooms and its not.

EDIT2: PrimeFaces 2.2.1 - I've read whole manual to primefaces but theres no explanation to this as I've done all that it states

I've tried using action instead of actionListener without ActionEvent but it never do anything. using <h:commandbutton action="#{hotelscontroller.requestHotelAvail}"/> works great but I want that ajax engine to refresh only that rooms panelgroup

UPDATE: Now it works. Form couldn't be in <p:accordion> but why and how to enable it there? Form now I'll work without it.

2
With "does not fire anything" do you actually mean 1) The method is not invoked (as confirmed by a debugger, logger or sysout), or 2) The rooms panelgroup is not updated? - BalusC
Does not resolve your problem but is a good practice to have the form component above all the other components as long as it doesn't interfere with other forms (avoid also inner forms) - spauny
Also, put some sysout's in that method to be sure or create another method in that class... in server log doesn't appear anything? Like could not find the bean, or action/property not found? If you use Netbeans be sure your class is correctly built... - spauny
What PrimeFaces version? Try action instead of actionListener and remove that ActionEvent argument which you aren't using anyway. - BalusC

2 Answers

3
votes

I suspect the different behavior from h:commandLink comes from ajax/non-ajax processing.

By default - if you don't use f:ajax - h:commandLink is non-ajax and entire page is rerendered. Primefaces p:commandLink is using ajax and you indicate rooms as component to be updated. In your case rooms is outside form so it should rather be addressed as :rooms (mind the colon) instead of just rooms.

update: have you tried ajax with h:commandLink? It would be:

<h:commandButton action="#{hotelscontroller.requestHotelAvail}" value="submit">
  <f:ajax render=":rooms"/>
</h:commandButton>

Also I'm not that familiar with primefaces but maybe you can try to explicitly indicate the component to process with additional process="@this" - although I would assume this to be default as in basic library.

0
votes

You try to inspect the response:

Open Chrome or Firefox -> Inspect Element -> Network and follow the ajax call.

enter image description here