You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Dirk Hoegemann <di...@web.de> on 2006/03/17 21:15:02 UTC
DataModel problem(getRowData() always returns 0)
Hello,
I have a problem with the h:dataTable tag, respectively the ListDataModel. I
hope somebody can give me a hint (or better - a solution;-)) on that.
The problem is that the getRowIndex(also getRowData) Method returns always
the element at position 0 (no matter which element has been selected).
Info: I am using myfaces version 1.1.1 with Facelets1.0.12 in JBoss4.0.4
with EJB3.
The Bean (admin) is directly set into the HttpSession like this (from
LogInBean(that Bean lives in the request Scope!?)):
FacesContext fc = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession)
fc.getExternalContext().getSession(false);
session.setAttribute("admin",adminbean); //Is this the common (or
a recommended)way?
The UI:
<h:form>
<fieldset><legend><b>Courses</b></legend>
<h:dataTable value="#{admin.courses}" var="studIndex"
rendered="#{not empty admin.courses}">
<h:column>
<h:outputText value="#{studIndex.name}"/>
</h:column>
<h:column>
<h:commandButton type="submit" value="Delete"
action="#{admin.deleteCourse}"/>
</h:column>
</h:dataTable>
</fieldset>
</h:form>
The corresponding Bean:
...
private ListDataModel courses;
...
public DataModel getCourses()
{
courses = new ListDataModel();
courses.setWrappedData(Utils.getAdminEdit().getCourses()); //A
stateless SessionBean gets the List via the EJB3 EntityManager
return skillKategorien;
}
...
public String deleteCourse()
{
if(getCourses().isRowAvailable())
{
int index = this.courses.getRowIndex();
Course todelete =
((List <Course>)(this.courses.getWrappedData())).get(index);
Utils.getAdminEdit().deleteCourse(todelete);
}
return "editCourses";
}//always deletes the Element at position index 0!!
Any ideas, where I can expect the problem?
Thanks!
Regards
Dirk Högemann