Accessing text fields in a table, which aren't bound to a dataprovider

Hi,

I have a table bound to a dataprovider, that also has some extra columns I added on through the "table layout" menu. These extra columns have text fields which are NOT bound to anything. How can I retrieve what text is written inside them? it's fine if this requires binding them to something.

Thanks for any help!

Tristan

[352 byte] By [apersona] at [2007-11-26 16:29:51]
# 1
bump - this must be possible
apersona at 2007-7-8 22:54:16 > top of Java-index,Development Tools,Java Tools...
# 2

Did you try anything like:

getValue("#{currentRow.value['staticText1']}");

but it really depends on where you want to access them from, and what for. For example, you could also bind that entire column to a property of type String[] , which would put everything in that column in the array (though I think in semi-random order, not sure).

sd4139a at 2007-7-8 22:54:16 > top of Java-index,Development Tools,Java Tools...
# 3

I was mostly trying something similar except with the column name as the parameter.The you posted for me doesn't cause exceptions, but it doesn't seem to return anything, even when all the text fields are filled in.

What I used:

alti_db_instanceDataProvider.cursorFirst();

alti_db_instanceDataProvider.cursorNext();

info((String)getValue("#{currentRow.value['textField1']}"));

(note: it returns nothing regardless of what you do with the cursor, it seems)

I'm not too fussed how I access it, as long as I can associate what I get with the rest of the information in that row.

Thanks for the help so far.

apersona at 2007-7-8 22:54:16 > top of Java-index,Development Tools,Java Tools...
# 4

Ah, I see. I suspect nothing is being returned because the currentRow variable is associated with the JSF table component. When you set the cursor position of the rowset with the dataprovider it doesn't actually change where currentRow points to (not sure if that makes sense, oh well).

Anyway, that doesn't matter, because I think I found the actual way to do it :-) You need to get a reference to the TableDataProvider backing the table object (the regular dataprovider is sort of behind the tabledataprovider, so the tabledataprovider should include the dataprovider columns and the columns you added, if you see what I mean). Anyway, you should be able to do:

TableDataProvider tbl = getTableRowGroup1().getSourceData();

Then use getValue(FieldKey, RowKey) to get the value you want. You'll have to figure out which FieldKey and RowKey you want, but hopefully that's not too hard. The method getFieldKeys() should help.

Sorry for the delay, hope it's still helpful.

sd4139a at 2007-7-8 22:54:16 > top of Java-index,Development Tools,Java Tools...
# 5

Thanks for the reply SD.

It seems that wasn't the solution either. The following code did not show any fields the regular dataprovider doesn't have.TableDataProvider tbl = getTableRowGroup1().getSourceData();

for (int i=0;i<tbl.getFieldKeys().length;i++)

info(tbl.getFieldKeys()[i].getFieldId());

Isn't it surprising how such a simple task could be so difficult? I think the easier you make some tasks, the harder you have to make others. For better or worse, some things in JSC were made extremely easy

I'm spending hours of company time on this one.>

apersona at 2007-7-8 22:54:16 > top of Java-index,Development Tools,Java Tools...
# 6
Oh, actually I just tried that with something I've been working on, and it didn't seem to work. Sorry. Not sure then.
sd4139a at 2007-7-8 22:54:16 > top of Java-index,Development Tools,Java Tools...
# 7

Yeah, I know what you mean.

Well, anyway, the currentRow variable is only active when the table is iterated over. I'm still not sure exactly when that happens, but I think it's when a form is submitted (or maybe when you just click a button, I don't know). Anyway, if you bind the field you're interested in to a property, then have get and set methods for that property, those methods will be called once for each row (at some point, maybe). Certainly you could put side-effects in those methods to do something with the data you want. Not sure how useful that would be, but you might be able to work something out.

I have a method like:

/* Record whether or not the current run should be marked as selected,

* based on the state of the checkbox.*/

public void setSelectedRun(boolean b) {

//log("Called setSelected");

TableRowDataProvider trdp =(TableRowDataProvider)getBean("currentRow");

RowKey rowKey = trdp.getTableRow();

if (checkbox1.isChecked()) {

selectedRuns.add(rowKey);

selectedRun = rowKey;

}

}

for a Checkbox control in my project.

sd4139a at 2007-7-8 22:54:16 > top of Java-index,Development Tools,Java Tools...
# 8

Great! With your help, I can now do what I want. Here's how it goes:

1) user enters passwords into table of connections to make

2) hits button

3) JSC calls setter methods associated with text fields (thanks for pointing this out), and new values of those text fields are automagically given as arguments.

It's an odd way to do it, but it works. That just about sums up everything I've been doing lately.

Now I just need to get password fields into a table, but I think I have a couple of hacks that will collectively make that possible.

Message was edited by:

aperson

apersona at 2007-7-8 22:54:17 > top of Java-index,Development Tools,Java Tools...