JSF/Richfaces partial table render with subtable - jsf

Is partially rendering a single column in a collapsibleSubTable using #rows in RichFaces 4 possible?
For example this works with a single datatable.
List<Integer> updatedRows
render="myForm:myTable:#rows(updatedRows):id"
I'm not sure how to do this dynamically With a collapsibleSubTable.
render="myForm:myTable:#rows(updatedRows):mySub:#rows(updatedSubRows):id
Is it possible to pass the current iteration of updatedRows into updatedSubRows? Something along the lines of.
render="myForm:myTable:#rows(updatedRows):mySub:#rows(updatedSubRows(currentUpdatedRow)):id
Where currentUpdatedRow is updatedRows[0], updatedRows[1] and so on.
Or maybe using a HashMap<Integer, HashSet<Integer>>()?

Related

How to bind dynamic row data on dynamic datatable in Primefaces?

I have created a data model in backingbean as shown at the image.
binded-data-model
And I created this ValueExpression:
tabla.setValueExpression("value", context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(), "#{pc_BackingBean.listaDeTablas[" + String.valueOf(getListaDeTablas().size() - 1) + "]}", List.class));
However the row data is not changing when the form is submited.
I already make the string reference for the binding using recursive code (tested).
#{pc_BackingBean.listaDeTablas[" + String.valueOf(getListaDeTablas().size() - 1) + "]}"
but the next step that binds the row var with the data model does not work.
tabla.setVar("criterio");
"#{criterio.puntos}"
How can I properly bind the row/column data value with the correct variable in backingbean?
Edit:
The datatable is created in the backingbean.
I resolved the issue it seems is there a bug on the primefaces datatable method setColumns. When you use it the binding does not work properly.
Instead of use setColumns(columns) use getChildren().addAll(columns);

Why does Table Component in ADF iterates many times over method bound to value attribute [duplicate]

This question already has answers here:
Why JSF calls getters multiple times
(9 answers)
Closed 6 years ago.
In my ADF project , I have a table component on JSF page whose value attribute is bound to method in Managed bean which returns List type object . I am able to show the data on the table but i can see the method being executed as many as 22 times ! Why the method is being called this many times and does the same thing happens with business components as well when we expose them through Data control? TIA
Edit : JSPX code :
<af:table var="row" rowBandingInterval="1"
autoHeightRows="10"
binding="#{backingBeanScope.backing_ForEachExample.t2}"
id="t1" partialTriggers=":::cb1"
styleClass="AFStretchWidth"
value="#{backingBeanScope.backing_ForEachExample.test2}">
<af:column sortable="false" headerText="col1" id="c3">
<af:outputText value="#{row}" id="ot2"/>
</af:column>
</af:table>
Bean Method is :
public List<String> gettest2(){
/* Unique values are derived */
List<String> tab=new ArrayList<String>();
for(String s:uniqueValues){
System.err.println("? Unique Value is : "+s);
tab.add(s);
}
return tab;
}
when you are using ADF BC, data is displayed from you VO which is exposed in AM through a data control, you can specify VO tuning properties, which determine how many records are fetched from database in one round trip. this is named in batches of. you can specify iterator's range size in sync with how many records you are fetching from database in one go and how many you need to dispay in table at UI. af:table has an attribute called fetchSize, if you set this attribute to some value equal to iterator range size say 20, and VO > Tuning > in batches of = 20, it would query only once. by default, VO in batches of is equal to 1, in that case, if you display a table with autoheightrows = 20, in this case table will query data multiple times from database.

Create and add f:selectItems to HtmlSelectOneRadio programmatically

I'm using JSF to create a questionnaire and therefore I need to create my whole xhtml pragmatically because there are different types of questions and the number of them is not predefined.
All I have is a h:panelGrid on my view and the rest is generated in my backing bean.
I have no problem creating HtmlOutputText and HtmlInputText. For that purpose I create them using getApplication e.g. like this:
getApplication().createComponent(HtmlOutputText.COMPONENT_TYPE);
and then add the component to my grid like this:
grid.getChildren().add(questionnumber);
where "grid" is my panelGrid element.
So I put my questions in a loop and based on the type of question from the db I decide what type of component to create. If the question is a normal text question I can easily use a HtmlInputText. But I have multiple choice questions too. Therefore I need to create SelectOneRadio menus and add SelectItems in them.
I can create a HtmlSelectOneRadio using the same createComponent method that I mentioned above. But I'm unable to add options to it (selectitem components). Is there a way that I can do this? Do we have a UIComponent for this that I am missing?
I found the solution myself. I had to use UISelectItems and add it to my SelectOneMenu like this:
final UISelectItem select = (UISelectItem) getApplication().createComponent(UISelectItem.COMPONENT_TYPE);
List<SelectItem> items = new ArrayList<SelectItem>();
for (int k = 0; k < options.length; k++){
items.add(new SelectItem(options[k]));
}
UISelectItems selectItems = new UISelectItems();
selectItems.setValue(items);
selectOneRadio.getChildren().add(selectItems);
grid.getChildren().add(selectOneRadio);

Binding an edit box within a custom control to a form field programatically

I have a notes form with a series of fields such as city_1, city_2, city_3 etc.
I have an XPage and on that XPage I have a repeat.
The repeat is based on an array with ten values 1 - 10
var repArray = new Array() ;
for (var i=1;i<=10;i++) {
repArray.push(i) ;
}
return(repArray) ;
Within the repeat I have a custom control which is used to surface the fields city_1 through city_10
The repeat has a custom property docdatasource which is passed in
It also has a string custom property called cityFieldName which is computed using the repeat
collection name so that in the first repeat row it is city_1 and in the second it is city_2 etc..
The editable text field on the custom control is bound using the EL formula
compositeData.docdatasource[compositeData.cityFieldName]
This works fine but each time I add new fields I have to remember to create a new custom property and then a reference to it on the parent page.
I would like to be able to simply compute the data binding such as
compositeData.docdatasource['city_' + indexvar]
where indexvar is a variable representing the current row number.
Is this possible ? I have read that you cannot use '+' in Expression Language.
First: you wouldn't need an array for a counter. Just 10 would do (the number) - repeats 10 times too. But you could build an array of arrays:
var repArray = [];
for (var i=1;i<=10;i++) {
repArray.push(["city","street","zip","country","planet"]) ;
}
return repArray;
then you should be able to use
#{datasource.indexvar[0]}
to bind city,
#{datasource.indexvar[1]}
to bind street. etc.
Carries a little the danger of messing with the sequence of the array, if that's a concern you would need to dig deeper in using an Object here.
compute to javascript and use something like
var viewnam = "#{" + (compositeData.searchVar )+ "}"
return viewnam
make sure this is computed on page load in the custom control
I was never able to do the addition within EL but I have been very successful with simply computing the field names outside the custom control and then passing those values into the custom control.
I can send you some working code if you wish from a presentation I gave.

Find by String in a GWT ListBox

I would like to find the index of an item inside a GWT Listbox by specifying a String value.
For example, if I had a GWT ListBox comprising the following items: "Randy", "Bob" and "Helen", the method i'm looking to implement would return the value 1 if I called it with parameter "Bob".
From what i'm seeing in the ListBox javadoc, ther does not seem to be any quick method to do this.
Any ideas?
Thanks in advance!
My idea of implementation as TextBox doesn't provide this out of the box. Store all the items in a list and in the order you want them to be part of ListBox.
List<String> orderedItems=new ArrayList<String>
orderedItems.add(0,"Randy");
orderedItems.add(1,"Bob");
orderedItems.add(2,"Helen");
//adding items in the same order as they are in List is the key
for(String item:items)
{
lb.addItem(item);
}
then you can find the index using List's indexOf(..) method

Resources