dataTable linked with treenode

hi community..

I'm trying to work with a tree and a datatable...

I want that user can click a treenode and thus view a specific datatable.

datatable comes out from a query from a database....

so the click action could pass a value to a variable of datatable bean and customize it....

well my code is this

the htmlx page contain

<ice:form>

<table cellpadding="" cellspacing="0" border="2">

<tr>

<td width="25%" valign="top">

<ice:panelGrid columns="3" cellspacing="5">

<!-- first column, for tree navigation -->

<ice:panelGroup style=" solid gray; height:300px;width:200px;">

<!--

This is a very links tree comprising of only text nodes. The

expand and contract images are rendered because the "imageDir"

attribute on the tree component has been set to a known path.

-->

<ice:tree id="tree"

value="#{tree.model}"

var="item"

hideRootNode="false"

hideNavigation="false"

imageDir="images/xp/css-images/">

<ice:treeNode>

<f:facet name="icon">

<ice:panelGroup style="display: inline">

<h:graphicImage value="#{item.userObject.icon}"/>

</ice:panelGroup>

</f:facet>

<f:facet name="content">

<ice:panelGroup style="display: inline">

<ice:commandLink

actionListener="#{item.userObject.selectTable}"

value="#{item.userObject.text}"/>

</ice:panelGroup>

</f:facet>

</ice:treeNode>

</ice:tree>

<ice:outputText value="#{item.userObject.displayPanel}" />

</h:panelGroup>

</h:panelGrid>

</td>

<td width="75%" valign="top">

<ice:panelGrid columns="1" cellspacing="5">

<!-- Third column, for panel stack -->

<ice:panelGroup style="border: 1px solid gray; width:350px " >

<ice:panelTabSet>

<ice:panelTab label="#{tabset.tabs[0].label}">

<ice:outputText value="#{tabset.tabs[0].content}"/>

<ice:dataTable

value="#{inventoryList.carInventory}"

var="item"

columnClasses="categoryColumn, propertyColumn, valueColumn, unitColumn"

rowClasses="oddRow, evenRow"

styleClass="tableStyle">

<!-- Category -->

<ice:column>

<f:facet name="header">

<ice:outputText value="Category"/>

</f:facet>

<ice:outputText value="#{item.category}"/>

</ice:column>

<!-- Property -->

<ice:column>

<f:facet name="header">

<ice:outputText value="Property"/>

</f:facet>

<ice:outputText value="#{item.property}"/>

</ice:column>

<!-- Value -->

<ice:column>

<f:facet name="header">

<ice:outputText value="Value"/>

</f:facet>

<ice:outputText value="#{item.value}"/>

</ice:column>

<!-- Unit -->

<ice:column>

<f:facet name="header">

<ice:outputText value="Unit"/>

</f:facet>

<ice:outputText value="#{item.unit}"/>

</ice:column>

</ice:dataTable>

</ice:panelTab>

<ice:panelTab label="#{tabset.tabs[1].label}">

<ice:outputText value="#{tabset.tabs[1].content}"/>

</ice:panelTab>

</ice:panelTabSet>

</ice:panelGroup >

</ice:panelGrid>

</td>

</tr>

</table>

</ice:form>

the action is registered by

<ice:commandLinkactionListener="#{item.userObject.selectTable}"

value="#{item.userObject.text}"/>

selectTable is the method of the backing bean

public class TableSelectUserObject extends IceUserObject {

// displayPanel to show when a node is clicked

private String displayPanel;

// panel stack which will be manipulated when a command links action is fired.

private TableBean Table;

/**

* Default contsructor for a PanelSelectUserObject object. A reference

* is made to a backing bean with the name "panelStack", if possible.

* @param wrapper

*/

public TableSelectUserObject(DefaultMutableTreeNode wrapper) {

super(wrapper);

// get a reference to the PanelStackBean from the faces context

FacesContext facesContext = FacesContext.getCurrentInstance();

Object TableObject =

facesContext.getApplication()

.createValueBinding("#{inventoryList}")

.getValue(facesContext);

if (TableObject instanceof TableBean){

Table = (TableBean)TableObject;

}

}

/**

* Gets the name of a panel in the panel stack which is associated with

* this object.

*

* @return name of a panel in the panel stack

*/

public String getDisplayPanel() {

return displayPanel;

}

/**

* Sets the name of a panelStack panel, assumed to be valid.

*

* @param displayPanel panelStack panel name.

*/

public void setDisplayPanel(String displayPanel) {

this.displayPanel = displayPanel;

}

/**

* ActionListener method called when a node in the tree is clicked. Sets

* the selected panel of the reference panelStack to the value of the instance

* variable #displayPanel.

*

* @param action JSF action event.

*/

public void selectTable(ActionEvent action){

if (Table != null){

Table.setObjectpath("moon/green/default/power/rtg");

}

}

}

this class call super....class treeBean where for each node I fix

branchNode1 = new DefaultMutableTreeNode();

branchObject1 = new TableSelectUserObject(branchNode1);

branchObject1.setText(sys_opt_array[j]);

branchObject1.setDisplayPanel(study_array+"/"+sys_opt_array[j]);

branchObject1.setBranchContractedIcon(sys_pic);

branchObject1.setBranchExpandedIcon(sys_pic);

branchObject1.setLeafIcon(XP_BRANCH_LEAF_ICON);

branchNode1.setUserObject(branchObject1);

branchNode.add(branchNode1);

tableBean is

public class TableBean {

public static InventoryItem[] resize(InventoryItem[] oldArray, int newLength)

{ if (newLength < 0 || oldArray == null)

throw new IllegalArgumentException();

InventoryItem[] newArray = new InventoryItem[newLength];

int count = oldArray.length;

if (newLength < count)

count = newLength;

for (int i = 0; i < count; i++)

newArray = oldArray;

return newArray;

}

// List of sample inventory data.

public InventoryItem[] carInventory = new InventoryItem[]

{};

private String path="moon/green/default/aocs/reaction wheel"; //"neo/moon/default/power/solar"; //"moon/green/default/power/rtg"; "moon/green/default/power/rtg";

public TableBean(){

int i;

int j;

select sel =new select();

String[] path_array=path.split("/");

if (path_array.length==5){

String[][] property_inventory=new String[1][1];

property_inventory=sel.view_all_prop_value(path_array[0], path_array[1], path_array[2], path_array[3], path_array[4]);

for(i=1;i<property_inventory[1].length;i++){

carInventory=TableBean.resize(carInventory,i);

carInventory[i-1]= new InventoryItem(property_inventory[1], property_inventory[2], property_inventory[3], property_inventory[4]);

}

}

}

public String getObjectpath() {

return path;

}

public void setObjectpath(String path) {

this.path = path;

}

/**

* Gets the inventoryItem array of car data.

* @return array of car inventory data.

*/

public InventoryItem[] getCarInventory() {

return carInventory;

}

/**

* Inventory Item subclass stores data about a cars inventory data. Properties

* such a stock, model, description, odometer and price are stored.

*/

public class InventoryItem {

// slock number

String category;

// model or type of inventory

String property;

// description of item

String value;

// number of miles on odometer

String unit;

/**

* Creates a new instance of InventoryItem.

* @param stock stock number.

* @param model model or type of inventory.

* @param description description of item.

* @param odometer number of miles on odometer.

* @param price price of care in Canadian dollars.

*/

public InventoryItem(String category, String property, String value, String unit) {

this.category = category;

this.property = property;

this.value = value;

this.unit = unit;

}

/**

* Gets the stock number of this iventory item.

* @return stock number.

*/

public String getCategory() {

return category;

}

/**

* Gets the model number of this iventory item.

* @return model number.

*/

public String getProperty() {

return property;

}

/**

* Gets the description of the this iventory item.

* @return description

*/

public String getValue() {

return value;

}

/**

* Gets the odometer reading from this iventory item.

* @return odometer reading.

*/

public String getUnit() {

return unit;

}

}

}

what I get is a static table.....nothing happen when I click... I suppose this happen because every time dataTable is created a new instance of path is read and it can't show any change......

someone could help me please?>

[10022 byte] By [ripcurla] at [2007-11-26 13:17:20]
# 1

it's possible that I could not only pass the variable path but make another instance of datatable?

the action shuold be performed as

public void selectTable(ActionEvent action){

if (Table != null){

Table.setObjectpath("moon/green/default/power/rtg");

new Table;

}

}

but when I call Table it takes variable path that I've passed before or the new one linked to each instance of TABLE?

ripcurla at 2007-7-7 17:41:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...