CommandLink / -Button does not work within nested datatable

Hi,

my CommandLink / -Button does not work within nested datatable. There is a Nullpointer-Exception when I try to get the "accid".

But when I put the Delete-Link / -Button in the last row of the accessorycat-Table it does always work!

Jsp:

...

<h:dataTable value="#{accessories.accesoryCatRows}" var="row" id="accessorycat" rows="#{accessories.rowNumbers}" first="#{accessories.firstRow}">

<f:param id="ranking" value="#{row.ranking}" />

<f:param id="id" value="#{row.id}" />

<h:column>

<h:inputText value="#{row.description}"/>

</h:column>

<h:column>

<h:commandButton value="#{msg.button_add}" actionListener="#{accessories.addAccessoryCat}"/>

</h:column>

<h:column>

<h:dataTable id="accessory" var="accessrow" value="#{row.accessory}">

<f:param id="accranking" value="#{accessrow.ranking}" />

<f:param id="accid" value="#{accessrow.id}" />

<f:param id="acccatid" value="#{row.id}" />

<h:column>

<h:outputText value="Ranking: #{accessrow.ranking}" />

<h:inputText value="#{accessrow.title}"/>

</h:column>

<h:column>

<h:commandButton value="#{msg.button_del}" actionListener="#{accessories.deleteAccessory}" action=""/>

</h:column>

</h:dataTable>

</h:column>

</h:dataTable>

...

Backing-Bean:

...

publicvoid deleteAccessory(ActionEvent event){

try{

UIParameter component = (UIParameter) event.getComponent().findComponent("accid");

Integer id = Integer.parseInt(component.getValue().toString());

System.out.println("Id: "+id);

}catch (Exception e){

e.printStackTrace();

}

}

...

Thanks,

Chris

[2894 byte] By [chris_1982a] at [2007-10-2 19:08:50]
# 1

What you can do is passing the selected row via a http parameter:

JSP

<h:commandLink action="#{dataBean.yourActionFunction}">

<f:param name="selectedDataId" value="#{data.id}" />

<h:outputText value="#{data.name}" />

</h:commandLink>

BEAN:

public String yourActionFunction() {

try {

Map params = FacesContext.getCurrentInstance().getExternalContext()

.getRequestParameterMap();

String id = (String) params.get("selectedDataId");

// do stuff

} catch (Exception e) {

JsfHelper.addMessage("Error: " + e.getMessage());

}

return "navigation_rule_x"; // faces-config.xml

}

//addition

quoting Horstmann

The id attribute lets page authors reference a component from another tag. For

example, an error message for a component can be displayed like this:

<h:inputText id="name".../>

<h:message for="name"/>

You can also use component identifiers to get a component reference in your

Java code. For example, you could access the name component in a listener, like

this:

UIComponent component = event.getComponent().findComponent("name");

The preceding call to findComponent has a caveat: the component that generated

the event and the name component must be in the same form (or data table).

Message was edited by:

Gumble_

Gumble_a at 2007-7-13 20:48:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...