How to update backend bean with multiple rows selected in prime faces sheet - jsf-2.2

I am using primefaces 6.2.3 sheet component. I am trying to update the backing bean when the user selects multiple rows and clicks on context menu. I am not able to retrieve the rows selected in my bean. The primefaces extension example uses JavaScript to remove the rows selected from UI without calling the backing bean.

As #Kukeltje has stated simply use a primefaces p:remoteCommand and you can use that in your Javascript code to executing backing bean methods.

Related

Ajax call in JSF 2.2 for dynamically created rows in DATATABLE

Iam dynamically creating new rows in dataTable by clicking on ADD ROW button in jsf 2.2. I need to do ajax call to particular column. Iam invoking AJAX action method but the values are not passing to backing bean.

JSF 2.0 f:ajax listener is not invoked when controller is request scoped

I am facing very weird issue with JSF2.0 Ajax Tag. Below are the steps that causes an issue for me
My project uses JSF2.0 and Spring 3.0. The JSF is wired to spring controller and life cycle is managed by Spring.
My Controller is Request Scoped.
Everything works fine till this point
i have a selectOne dropdown and on selection of a value on drop down it renders bottom portion of screen which has another dropdown. I use a rendered attribute on a parent panelgroup to show and hide this drop down.
However for the newly rendered drop down on selection of a value the ajax listener(F:ajax tag defined inside it) is not getting invoked. I see the following happening
The bean is reintialized as it is request scope.I see my postconstruct getting executed.
i see success message in the data object in client.
Only thing missing is that the listener method is not invoked.
Is there anyway to debug the life cycle and find what is going wrong?
If the rendered attribute of one of the parent components of <f:ajax> evaluates false during processing the ajax request, then the ajax action listener won't be invoked.
A request scoped bean is recreated on every single request, so all its properties would be resetted to default, unless initialized otherwise in the (post)constructor. If the property behind the rendered attribute isn't properly reinitialized based on some request parameters, then it would evaluate false like as on the initial request.
To fix it, you'd need to do proper initialization in bean's (post)constructor based on request parameters or just put the bean in the JSF view scope.
See also:
How to choose the right bean scope?
commandButton/commandLink/ajax action/listener method not invoked or input value not updated

Dependent Dropdown in JSF fails validation

I have two dependent dropdowns on a JSF page that work fine. I use a valueChangeListener on the first dropdown that populates the List backing the second dropdown.
However when I try to submit my form it's failing JSF validation. From testing I think the problem is that when the page loads my dependent dropdown list is empty, then I populate it after the first dropdown has a selection made. However none of the values now in the dependent list were in the list when the page loaded so it's fails validation. I have confirmed this by using a constructor to set up the list with all the possible values when the page loads and it makes my problem go away however this isn't a possible solution as loading up all the values would kill the performance of my page.
Any ideas how I can get it working?
Regards,
Kevin.
This is EXACTLY the use case for a view scoped bean. Using a request scoped bean in such case is going against the grain of JSF (possible, but painful - like using a hedgehog as a bath sponge).
If there are any problems with such solutions, then tell us, there should be a way of mitigating them; the point is, you should use the view scope and solve any problems you might have with that, and not try to run away from it.

JSF 2.0 Dynamically Remove Components

As a follow on to an answered question on Adding Components Dynamically in JSF 2.0 (see link below), I like the approach of using a dataTable, but what about Removing one of the added components?
How to dynamically add JSF components
Based on the code snippet in the other question you linked, you need to do the following changes:
Add a column with a delete button to the table.
<h:column><h:commandButton value="delete" action="#{bean.delete}" /></h:column>
Add a DataModel<Item> property to the bean and wrap the list of items in it so that you will be able to obtain the table row where the button was clicked.
private DataModel<Item> model = new ListDataModel<Item>(items);
(don't forget the getter, note that you can also instantiate this in bean constructor or postconstruct)
Use this in the datatable instead.
<h:dataTable value="#{bean.model}" var="item">
Add a delete method to the bean.
public void delete() {
items.remove(model.getRowData());
}
See also:
Benefits and pitfalls of #ViewScoped - contains JSF 2.0 CRUD table example

JSF - force UIInput components to refresh

I'm currently working on a JSF 1.2 project (IBM implementation and a "company layer").
PROBLEM
Here's the situation (numbers of items are just for the example), simple CRUD
List item
I have a list of items
I click on item 2 to see detail
I click on modify, the modification page displays values of item 2
Back to the list with a button "Back" and immediate="true" (because we don't want to submit the modifications)
Detail of item 4
Modify item 4 > Values of item 2 are displayed
BUT
if I set the "immediate" attribute of the "Back" button to false, values of item 4 are OK.
if I set the "disabled" attibute of an inputText component to true, value of item 4 is OK.
if I use <h:outputText value="#{item4.myValue}/> (UIOutput) instead of <h:inputText value="#{item4.myValue}/> (UIInput)
Also, I checked in debug mode that the bean I wanted to display was "item 4" and it was.
WHAT I FOUND
After some research on Google I found that this problem comes from the lifecycle of JSF, although the documentation and solutions found are for specific implementations of JSF.
So I guess it's because the value is populated with "localValue" instead of "submittedValue" (#see EditableValueHolder interface could help understanding), and there are some solutions from these pages
Apache wiki
IceFaces forum
RESULT
It doesn't work (I wouldn't be here, I swear ^^).
The "Refresh" solution is ineffective.
The "Erase input" is scary. I can't admit that I need to reference every input field! Plus I didn't find the setSubmittedValue() method on the UIInput in my IBM JSF.
The "Clear" method is ineffective. I tried on one element, and on the complete component tree with this code
public void cleanAllChildren(List<UIComponentBase> list){
for(UIComponentBase c : list){
this.cleanAllChildren(c.getChildren());
c.getChildren().clear();
}
}
But without success. So here I am.
Did I miss something? is there a nice tricky solution I didn't see? I'm not really familiar with the JSF lifecycle.
Put the bean with request scoped data in request scope, not in session scope.
You probably have the entire list in session to "save" DB calls and all the work to retain values in the subsequent requests inside the same session. You can use a separate session scoped bean for that, e.g. DataManager. Then you should have a request scoped bean to represent the selected item, e.g. DataItem. You can familarize the both beans with help of managed property injection.

Resources