Problem with richfaces ajax datatable + buttons
- by Schyzotrop
Hello i have another problem with RichFaces
this is my application and it shows how i want it to work :
http://www.screencast.com/users/Schyzotrop/folders/Jing/media/a299dc1e-7a10-440e-8c39-96b1ec6e85a4
this is video of some glitch that i can't solve
http://screencast.com/t/MDFiMGMzY
the problem is that when i am trying to press any buttons on others than 1st category it won't do anything IF 1st category has less rows than the one i am calling it from
from 1st category it works always
i am using follwoing code in jsp for collumns :
<h:form id="categoryAttributeList">
<rich:panel>
<f:facet name="header">
<h:outputText value="Category Attribute List" />
</f:facet>
<rich:dataTable id="table" value="#{categoryAttributeBean.allCategoryAttribute}" var="cat" width="100%" rows="10" columnClasses="col1,col2,col2,col3">
<f:facet name="header">
<rich:columnGroup>
<h:column>Name</h:column>
<h:column>Description</h:column>
<h:column>Category</h:column>
<h:column>Actions</h:column>
</rich:columnGroup>
</f:facet>
<rich:column filterMethod="#{categoryAttributeFilteringBean.filterNames}">
<f:facet name="header">
<h:inputText value="#{categoryAttributeFilteringBean.filterNameValue}" id="input">
<a4j:support event="onkeyup" reRender="table , ds"
ignoreDupResponses="true" requestDelay="700"
oncomplete="setCaretToEnd(event);"
/>
</h:inputText>
</f:facet>
<h:outputText value="#{cat.name}" />
</rich:column>
<rich:column filterMethod="#{categoryAttributeFilteringBean.filterDescriptions}">
<f:facet name="header">
<h:inputText value="#{categoryAttributeFilteringBean.filterDescriptionValue}" id="input2">
<a4j:support event="onkeyup" reRender="table , ds"
ignoreDupResponses="true" requestDelay="700"
oncomplete="setCaretToEnd(event);"
/>
</h:inputText>
</f:facet>
<h:outputText value="#{cat.description}" />
</rich:column>
<rich:column filterMethod="#{categoryAttributeFilteringBean.filterCategories}">
<f:facet name="header">
<h:selectOneMenu value="#{categoryAttributeFilteringBean.filterCategoryValue}">
<f:selectItems value="#{categoryAttributeFilteringBean.categories}" />
<a4j:support event="onchange" reRender="table, ds" />
</h:selectOneMenu>
</f:facet>
<h:outputText value="#{cat.categoryID.name}" />
</rich:column>
<h:column>
<a4j:commandButton value="Edit" reRender="pnl" action="#{categoryAttributeBean.editCategoryAttributeSetup}">
<a4j:actionparam name="categoryAttributeID" value="#{cat.categoryAttributeID}" assignTo="#{categoryAttributeBean.id}" />
<a4j:actionparam name="state" value="edit" />
<a4j:actionparam name="editId" value="#{cat.categoryAttributeID}" />
</a4j:commandButton>
<a4j:commandButton reRender="categoryAttributeList" value="Delete" action="#{categoryAttributeBean.deleteCategoryAttribute}">
<a4j:actionparam name="categoryAttributeID" value="#{cat.categoryAttributeID}" assignTo="#{categoryAttributeBean.id}" />
</a4j:commandButton>
</h:column>
<f:facet name="footer">
<rich:datascroller id="ds" renderIfSinglePage="false"></rich:datascroller>
</f:facet>
</rich:dataTable>
<rich:panel id="msg">
<h:messages errorStyle="color:red" infoStyle="color:green"></h:messages>
</rich:panel>
</rich:panel>
</h:form>
and here is code of my backing bean
@EJB
private CategoryBeanLocal categoryBean;
private CategoryAttribute categoryAttribute = new CategoryAttribute();
private ArrayList<SelectItem> categories = new ArrayList<SelectItem>();
private int id;
private int categoryid;
// Actions
public void newCategoryAttribute() {
categoryAttribute.setCategoryID(categoryBean.findCategoryByID(categoryid));
categoryBean.addCategoryAttribute(categoryAttribute);
FacesContext.getCurrentInstance().addMessage("newCategoryAttribute", new FacesMessage("CategoryAttribute " + categoryAttribute.getName() + " created."));
this.categoryAttribute = new CategoryAttribute();
}
public void editCategoryAttributeSetup() {
categoryAttribute = categoryBean.findCategoryAttributeByID(id);
}
public void editCategoryAttribute() {
categoryAttribute.setCategoryID(categoryBean.findCategoryByID(categoryid));
categoryBean.updateCategoryAttribute(categoryAttribute);
FacesContext.getCurrentInstance().addMessage("newCategoryAttribute", new FacesMessage("CategoryAttribute " + categoryAttribute.getName() + " edited."));
this.categoryAttribute = new CategoryAttribute();
}
public void deleteCategoryAttribute() {
categoryAttribute = categoryBean.findCategoryAttributeByID(id);
categoryBean.removeCategoryAttribute(categoryAttribute);
FacesContext.getCurrentInstance().addMessage("categoryAttributeList", new FacesMessage("CategoryAttribute " + categoryAttribute.getName() + " deleted."));
this.categoryAttribute = new CategoryAttribute();
}
// Getters
public CategoryAttribute getCategoryAttribute() {
return categoryAttribute;
}
public List<CategoryAttribute> getAllCategoryAttribute() {
return categoryBean.findAllCategoryAttributes();
}
public ArrayList<SelectItem> getCategories() {
categories.clear();
List<Category> allCategory = categoryBean.findAllCategory();
Iterator it = allCategory.iterator();
while (it.hasNext()) {
Category cat = (Category) it.next();
SelectItem select = new SelectItem();
select.setLabel(cat.getName());
select.setValue(cat.getCategoryID());
categories.add(select);
}
return categories;
}
public int getId() {
return id;
}
public int getCategoryid() {
return categoryid;
}
// Setters
public void setCategoryAttribute(CategoryAttribute categoryAttribute) {
this.categoryAttribute = categoryAttribute;
}
public void setId(int id) {
this.id = id;
}
public void setCategoryid(int categoryid) {
this.categoryid = categoryid;
}
and here is filtering bean :
@EJB
private CategoryBeanLocal categoryBean;
private String filterNameValue = "";
private String filterDescriptionValue = "";
private int filterCategoryValue = 0;
private ArrayList<SelectItem> categories = new ArrayList<SelectItem>();
public boolean filterNames(Object current) {
CategoryAttribute currentName = (CategoryAttribute) current;
if (filterNameValue.length() == 0) {
return true;
}
if (currentName.getName().toLowerCase().contains(filterNameValue.toLowerCase())) {
return true;
} else {
System.out.println("name");
return false;
}
}
public boolean filterDescriptions(Object current) {
CategoryAttribute currentDescription = (CategoryAttribute) current;
if (filterDescriptionValue.length() == 0) {
return true;
}
if (currentDescription.getDescription().toLowerCase().contains(filterDescriptionValue.toLowerCase())) {
return true;
} else {
System.out.println("desc");
return false;
}
}
public boolean filterCategories(Object current) {
if (filterCategoryValue == 0) {
getCategories();
filterCategoryValue = new Integer(categories.get(0).getValue().toString());
}
CategoryAttribute currentCategory = (CategoryAttribute) current;
if (currentCategory.getCategoryID().getCategoryID() == filterCategoryValue) {
return true;
} else {
System.out.println(currentCategory.getCategoryID().getCategoryID() + "cate" + filterCategoryValue);
return false;
}
}
public ArrayList<SelectItem> getCategories() {
categories.clear();
List<Category> allCategory = categoryBean.findAllCategory();
Iterator it = allCategory.iterator();
while (it.hasNext()) {
Category cat = (Category) it.next();
SelectItem select = new SelectItem();
select.setLabel(cat.getName());
select.setValue(cat.getCategoryID());
categories.add(select);
}
return categories;
}
public String getFilterDescriptionValue() {
return filterDescriptionValue;
}
public String getFilterNameValue() {
return filterNameValue;
}
public int getFilterCategoryValue() {
return filterCategoryValue;
}
public void setFilterDescriptionValue(String filterDescriptionValue) {
this.filterDescriptionValue = filterDescriptionValue;
}
public void setFilterNameValue(String filterNameValue) {
this.filterNameValue = filterNameValue;
}
public void setFilterCategoryValue(int filterCategoryValue) {
this.filterCategoryValue = filterCategoryValue;
}
unfortunetly i can't even imagine what could cause this problem that's why i even made videos to help u understand my problem
thanks for help!