users@woodstock.java.net

Re: Tables and non-POJO lists

From: Brawn Do <brawndoe_at_gmail.com>
Date: Tue, 29 Apr 2008 13:56:31 -0500

Thanks for the response Dan. I understand the name var is just a variable.
In my example, name is not a getter in the backing bean - it is simply the
cursor/ref/var as shown in the code below. The data contained within the
list is a simple list of strings. The fact that the data provider is just a
list of strings as opposed to POJOs with accessors that can be referenced is
the problem. Since the value is just a string there's no field key -
#{sourceVarName.value.????} therefore I am unable to get at the underlying
value. I'm guessing from your response that "simple" values have to be
wrapped with a bean that exposes an accessor?


Example #2 creates a table with pojos in the provider i.e., Name objects
with accessors (field keys) such as "first" and "last" and as such you can
reference the dataprovider values with a fieldkey; e.g.,
#{sourceVarName.value.first}. This works fine for me and I use the pattern
regularly. Again, the problem I have encountered is how to deal with
"simple" values i.e., a ListDataProvider populated with Strings. In the
example I provided, the "names" list is just a list of strings. I trust
this clarifies my intent.


Thanks for your help!


On Tue, Apr 29, 2008 at 12:30 PM, Dan Labrecque <Dan.Labrecque_at_sun.com>
wrote:

> "#{name.value}" is not the correct syntax for the StaticText component.
> The "name" keyword should not be a getter in your backing bean. It is a
> variable given to the sourceVar property of the TableRowGroup component. (It
> is used only in an EL expression as a pointer to the DataProvider.) In order
> for your EL expression to work property, you must also include a field key
> (e.g., "#{name.value.last}").
>
> If you want examples of how to create a table dynamically, check out the
> TLD docs below. Specifically, example #2 of tableRowGroup.
>
> http://webdev2.sun.com/woodstock-tlddocs
>
> The same "Dynamic Table" example can also be found in the Woodstock example
> app.
>
> http://webdev2.sun.com/example/faces/index.jsp
>
> Dan
>
>
> Brawn Do wrote:
>
> Hi,
>
> I've got a handle on dealing with POJO beans within my tables, but am
> unclear how to handle "simple" lists of primitive elements like strings. I
> must be missing the boat on this. With the code below I'm attempting to
> simply display the name "foo", but instead end up with a
> com.sun.webui.jsf.faces.DataProviderELResolver$ValueData toString()'d Can
> anyone lend a hand (code below)? Similar code works fine with POJO lists;
> e.g., where the name is a getter on a bean #{
> mybeanwithanamegetter.value.name}
>
> Thanks!
>
> Table table = new Table();
> table.setId("tbl");
> TableRowGroup rowGroup = new TableRowGroup();
> rowGroup.setId("rowGroup");
> rowGroup.setSourceVar("name");
> List<String> names = new LinkedList<String>();
> names.add("foo");
> ListDataProvider provider = new ListDataProvider (names);
> rowGroup.setSourceData(provider);
> TableColumn column = new TableColumn();
> column.setId("col");
> column.setHeaderText("Value");
> StaticText nameText = new StaticText();
> nameText.setId("nameText");
> FacesContext context = FacesContext.getCurrentInstance();
> nameText.setValueExpression("value",
>
> context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(),
> "#{name.value}",String.class)
>
> column.getChildren().add(nameText);
> rowGroup.getChildren().add(column);
> table.getChildren().add(rowGroup);
>
>
>