Customizing af:listView to get list element

This is our use case: By clicking on an element in a listView we trigger a master-detail view on the right hand of the page. This section labeled the master row in top displaying an unspecified amount of elements in an af:listView underneath it with a ratingGauge next to the labeled component –list selection should be disabled due to improved usability. Clicking on a ratingGauge triggers a valueChangeEvent instantly committing the new value.
employeManagement
The employee management -On the left hand we fetch every employee on the right hand we show the managed ones

We experienced the problem that we did not know which row was triggered because row selection was disabled. So we tried to customize the id of the ratingGauge component extending it with the following expression #{item.bindings.EmployeeId}. Unfortunately the id attribute does not support EL Expression.

So how can we solve this problem?

By adding a custom attribute!

Just with adding customId=“#{item.bindings.EmployeeId}“ to the ratingGauge we can access this attribute in the triggered valueChangeEvent. Let’s take a look at that.

[code language=“java“]public void ratingChanged(ValueChangeEvent valueChangeEvent) {
if (!valueChangeEvent.getComponent().getAttributes().containsKey("customId")) {
showMessage("I have no attribute called ‚customId‘.");
} else {
String id = valueChangeEvent.getComponent().getAttributes().get("customId").toString();
StringBuilder strbu = new StringBuilder();
strbu.append("I am No. " + id + " ");
strbu.append("My id is " + valueChangeEvent.getComponent().getAttributes().get("id").toString());
showMessage(strbu.toString());
/**
* Now we can access the row with the specified employeeId to change its rating
* and commit this
*/
}
}
[/code]
So if there is no attribute called customId given we will show a message that there is something missing respectively handle this case as it’s needed.
If we can access the attribute value we will show it in a message together with the id which we tried to customize with the EL Expression as well –to see it does not work.

id
So this message will appear. 146 means the employeeId we set in the customId attribute and we see the id of the component did not change.

 

 

 

Hopefully this will help you and solve some problems.

 

An example application can be downloaded below.
ListViewExample.zip (Just remove the .docx ending)

Kommentar verfassen

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.

%d Bloggern gefällt das: