I have an asyncTable in my page CAF, last column contain an inputText, and I wanna disable this controle for some rows of my table,
I use this code inside my condition javascript :
if (condition on this row){
document.getElementById("#{caf:cid('defaultForm:asyncTable:__row0:htmlOutputText28')}").disabled=true;
}
But it disabled just the inputText of the first row.
do you have to disable the control for only the row the user is interacting with or for all the rows on the table?
If it’s just for the one the user is interacting with then just add a script control that will trigger for whatever condition you need (change, click, …) on whatever control you specify, add it a parameter, param, (for the control you have to disable) and call param.setDisable(true) inside the script.
MWS while rendering the table will resolve the param to the closest to the script. Exactly as you want.
my script in in page loading, i wanna disable controles for some rows of my table, rows that respect a condition, so i have a list of rows, if i want disable one row i can index it, but i want disable some cotrole something like .
If your condition is simple, you may be able to just use an expression in the ‘Disabled’ property of the input control. This could be simpler, since you would not need any custom script.
For example, something like this as the value of the ‘Disabled’ property: #{row.color == ‘red’ ? true : false}
/* get the table model */
var tableModel = CAF.model("#{caf:cid('defaultForm:asyncTable')}");
/* list of rows */
var rowModels = tableModel.list();
/* loop through the rows */
for (var r=0; r < rowModels.length; r++) {
var rowModel = rowModels[r];
/* calculate the id of the input control inside the row */
var inputId = rowModel.getControlId("htmlInput1");
/* get the model for the input control */
var inputModel = CAF.model(inputId);
var condition = true; //TODO: calculate condition value
inputModel.setDisabled(condition);
}
Thank you Eric for your help
I try your solution but there is some problem, bellow my table how is looks :
For the rows in orange, i wanna keep the input “Comment” and the button “save” shown
For the other normal rows, i want hide or disable the input and the button.
form name: defaultForm
table name : asyncTable
input name : htmlOutputText
button name : htmlCommandButton
and bellow the code to make rows in orange :
if(dev!=int || prep!=prod || int!=prep || dev!=prod) //si difference entre les env
{
arrayLignes[i].style.backgroundColor = "#EE7600";
}
and :
var arrayLignes = document.getElementById("#{caf:cid('defaultForm:asyncTable')}").rows;
Well, I think combining parts of my earlier example with your code should work. Something like this:
if(dev!=int || prep!=prod || int!=prep || dev!=prod) //si difference entre les env
{
arrayLignes[i].style.backgroundColor = "#EE7600";
} else {
/* get the model for the row */
var rowModel = CAF.model(arrayLignes[i]);
/* calculate the id of the control inside the row */
var inputId = rowModel.getControlId("htmlOutputText");
/* get the model for the input control */
var inputModel = CAF.model(inputId);
/* calculate the id of the control inside the row */
var buttonId = rowModel.getControlId("htmlCommandButton");
/* get the model for the input control */
var buttonModel = CAF.model(buttonId);
/* disable them */
inputModel.setDisabled(true);
buttonModel.setDisabled(true);
}
Another last little question and sorry for the inconvenience cuz i’m not strong enough in javascript with CAF components.
How can I get some cells value of my current row, I have a button save for every row, when I click on this button, i want sent some cells value of my current row and persist them in a table of my database.
example :
every row has his “save” button, i want for example save some infos in the third row, how can i get the value of cell “NAME” and the value of the “Comment” cell when clicking on “save”, of current row
Well, the JSF framework will automatically position the table content provider to the row that contained the command button that the user clicked on.
So, on the server side, you could pull values from the current row in your action handler java method. For example, something like this:
public void myTableRowAction() {
//TODO: get your table content provider object
ITableContentProvider tableContentProvider = getTableProvider();
//the current row will be the row containing the action the user clicked on
Object row = tableContentProvider.getCurrentRow();
//TODO: cast the row object to your row java type and use it directly.
//Or, you can use the generic getValue() call to lookup specific properties of the row
Object field1Value = tableContentProvider.getValue("field1");
}
I tried this but i didn’t got the result using controle ID, the returned object is null and can’t be casted
I added i hidden standard column to my asycTable with and input that contains 2 values concateneted (Name&Comment) (firstCell&lastCell) so i atached my input to a data named rowID :
my table content provider is getDouaneResultProvider()
public java.lang.String getRowID() {
Object row = getDouaneResultProvider().getCurrentRow();
//TODO: cast the row object to your row java type and use it directly.
//Or, you can use the generic getValue() call to lookup specific properties of the row
Object field1Value = tableContentProvider.getValue("txtName").toString();
Object field2Value = tableContentProvider.getValue("txtComment").toString();
rowID = field1Value&field1Value;
return rowID;
}
my Object struct is :
public class packagesStruct implements java.io.Serializable
{
private java.lang.String name;// the name i want to get
private java.lang.String versionDev;
private java.lang.String timeDev;
private java.lang.String versionInt;
private java.lang.String timeInt;
private java.lang.String versionPrep;
private java.lang.String timePrep;
private java.lang.String versionPrep2;
private java.lang.String timePrep2;
private java.lang.String versionProd;
private java.lang.String timeProd;
private java.lang.String versionProd2;
private java.lang.String timeProd2;
private java.lang.String comment;// the comment i want to get
.
.
.
.
.
with getters and setters