• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Rendered primefaces button not calling the method in actionlistener

 
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am currently working on a project which has JSF + Spring + Primefaces 5.3 + Maven + Hibernate. I created a page which has create and edit action in the same panel and it has a table below.

the panel is as follows:


the edit button in the table is an ajax button and it is as follows

I hide the create button and show the edit button. When i click on edit button after it is rendered, it doesn't even reach the method. I don't have any idea how this doesn't work. Can some one explain this?
Sorry for the bad indentation.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a couple of red lights in this example. You're apparently setting up a table, but you're not using the dataTable tag. You're using an actionListener, but that attribute has been almost entirely obsolete since JSF webt mainstream. And you're essentially coding logic (the propertyActionListener) to push a value into a backing bean when you could probably be using JSF's built-in Controllers to do so.

All of the elements you're using work, but it's like travelling from Delhi to Kolkata by way of Capetown. It's the long, hard way around and you apparently missed a flight on the way. Your example never defines the variable named "sessions", and that didn't help any.

Rather than using raw HTML and obscure/obsolete JSF elements, consider doing this as a dataTable with associated DataModel value. The DataModel helps make the dataTable control able to "pass parameters" from one action to another without having to pass them from server to client and back again, which saves bandwidth, is more secure, and is simpler to code in JSF.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:You're apparently setting up a table, but you're not using the dataTable tag.



Tim sorry for that. I am actually using a <p:datatable /> inside that at the last column named "Action", I have two buttons edit and delete.



Tim Holloway wrote:You're using an actionListener, but that attribute has been almost entirely obsolete since JSF webt mainstream.


We were actually using action but for test purposes we left it with actionListener. This means we should be using action not actionListener. Am I right?

Tim Holloway wrote:And you're essentially coding logic (the propertyActionListener) to push a value into a backing bean when you could probably be using JSF's built-in Controllers to do so.


Yes you are right.

Tim Holloway wrote:Your example never defines the variable named "sessions", and that didn't help any.


I am lost here. Does this mean my bean doesn't have a variable named "sessions". If you are pointing at this, yes my bean doesn't have such variable.

Tim Holloway wrote:Rather than using raw HTML and obscure/obsolete JSF elements, consider doing this as a dataTable with associated DataModel value. The DataModel helps make the dataTable control able to "pass parameters" from one action to another without having to pass them from server to client and back again, which saves bandwidth, is more secure, and is simpler to code in JSF.


Yes you are right, I will have to start using Data Models. I haven't used them because people who taught me jsf didn't teach me about that. Can you give me some examples?
 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim,
I was seeing the lazy model example from primefaces site here . The following lines show that even if you are using ajax. it reaches the bean and then uses a function there and returns the value to the dialog.


This means the request will reach the method onRowSelect in bean in the server and get back the response and then use it in the dialog. Am I right? If I am wrong can you explain this to me?

Also you have mentioned that

Tim Holloway wrote:The DataModel helps make the dataTable control able to "pass parameters" from one action to another without having to pass them from server to client and back again, which saves bandwidth, is more secure, and is simpler to code in JSF.


Can you please give me an example of this?
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One note. "sessions" is not a bean property in your example. It's expected that it's a bean name in its own right. There are no anonymous "default beans" for JSF, so the first level of object qualification is always the name of a bean object in application, session or request scope (or one one the JSF-specific scopes that use one of these as a basis).

JSF DataModels are actually quite easy to understand. They are wrapper classes for UI model data collections that decorate that data with extra properties and functions that make it easier for JSF's Controllers to do their work. There are several stock DataModel types, corresponding to popular data collection types (List, Array, and so forth).

So let's say you have a List of MyRowType items, each item of which will be a row in your table. Wrap that List in a ListDataModel. You can do this in a single step:


Once wrapped, any changed in the underyling data (myList), whether within a row or by adding/removing rows, will be reflected in the wrapper. You only need change wrapping if you do later something like attach a complely different List object to the Model.

Now expose "myListTable" as a public property on the backing bean (define a public "get" method. No "set" method is required, since it's read-only). Reference that property from the dataTable. That is:


Important note: DataModel objects, like SelectItem objects, must be defined in a backing bean that has a multi-request scope. Request scope won't work, because the DataModel maintains state between requests and Request scope destroys and creates a new DataModel on each request.

OK, now the magic begins. If you define a command action method (or, for that matter, an actionListener), you can tell precisely which row of the table the button or commandLink was clicked to fire the action by using one of the two following methods:


So now you know what row you are working with and you never actually had to set up anything on the View Template (h:dataTable) to do so!

This is also true, incidentally, if you are using an AJAX action listener method.
>
 
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic