This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes JSF and the fly likes Editing datatable column content dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Editing datatable column content dynamically" Watch "Editing datatable column content dynamically" New topic
Author

Editing datatable column content dynamically

Per-Morten Lindanger
Greenhorn

Joined: Oct 13, 2008
Posts: 10
I am currently trying to list out a collection of objects from an arraylist stored in a bean.

The objects all implement a common interface, but are of different object types. What I want to do, is to display the list so that some of the objects are displayed as combo boxes, and others as inputfields, depending on what kind of object they are.

Is this doable? and in that case how? I don't want to generate the content of the JSP in doview() unless I really really REALLY have to.
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

Well i am thinking of an another work around. Why dont you make two boolean properties in each object like isList or isCombo and give one of these fields in Rendered. So at a time only one will be displayed.


My Blog SCJP 5 SCWCD 5
Per-Morten Lindanger
Greenhorn

Joined: Oct 13, 2008
Posts: 10
Would'nt the ".setRendered(false)" cause all the inputTexts/comboboxes in the column to be hidden?

The list will contain objects of different classes at the same time.
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

You can go like this that in your both classes you have two boolean variables say isListable and isInput(something like that. you may think of some better name). Now set it whenever your object gets initialized.

Categorise it such that when your object gets created it will sets its properties(Boolean properties) by itself.


Now in the code provide two components in a single column of your datatable

1. <h:input... rendered=#{bean.input}>

2. <h:selectmany... rendered=#{bean.listable}>

Hope this works...
[ October 13, 2008: Message edited by: Himanshu Gupta ]
Per-Morten Lindanger
Greenhorn

Joined: Oct 13, 2008
Posts: 10
Works perfectly. Thanks!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Editing datatable column content dynamically
 
Similar Threads
not able to add element into List<?>
Prototype and script.aculo.us ToC
Arraylist
Struts2: My s:select will not select rows which it should do applicable
Need Strategy for Object Vertioning