-
1. Re: Help with <a4j:commandButton> within <rich:dataTable>
user1234 Dec 21, 2009 12:48 AM (in response to sdf1)1 of 1 people found this helpfulPlease check the demo for editable data tabale
http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=editDataTable&cid=5364210
there you can find a good example how to acess the current row and work on it.
To assign the current row in thta aaj:commandButton have to use f:setPropertyActionListener value
<a4j:commandLink ajaxSingle="true" ....... />
<f:setPropertyActionListener value="#{row}"
target="#{dataTableScrollerBean.currentRow}" />
</a4j:commandLink>In the bean currentRow will have the row where you are working on, so you can get the required data from this object.
To get the demo bean source check for the SVN source code
-
2. Re: Help with <a4j:commandButton> within <rich:dataTable>
sdf1 Dec 23, 2009 7:33 PM (in response to sdf1)Following my first post.
I managed to send the ID data (first column) from the table, the row that I clicked.But how now to take the data from <rich:inputNumberSpinner>(3) components?
This is part of code (xhtml page and java bean class):
CatalogPortlet.xhtml
<a4j:region> <rich:dataTable id="dt1" value="#{CatalogBean.itemArtAll}" var="itemArt" rowKeyVar="row" onRowMouseOver="this.style.backgroundColor='#EFF7FF'" onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'" width="100%" columns="7"> ... <rich:column> <f:facet name="header"> <h:outputText value="Odaberi kolicinu" /> </f:facet> <!-- <a4j:form ajaxSubmit="true">--> <rich:inputNumberSpinner value="#{CatalogBean.odbKolicina}" minValue="1" maxValue="#{itemArt.kolicina}" /> <!-- </a4j:form>--> </rich:column> <rich:column> <f:facet name="header"> <h:outputText value="Dodaj u korpu" /> </f:facet> <a4j:commandButton id="button" value="Kupi" ajaxSingle="true" actionListener="#{CatalogBean.currentRow}" immediate="true" style="width:70px;"> <f:setPropertyActionListener value="#{row}" target="#{CatalogBean.currentRow}" /> </a4j:commandButton> </rich:column> ... </rich:dataTable> </a4j:region>
CatalogBean.java
... private int currentRow; private int odbKolicina; private List<itemArt> itemArtAll = new ArrayList(); public List getItemArtAll() { // This method the fills variable "itemArtAll" with items from the database return itemArtAll; } public void currentRow(ActionEvent event) { int idd = itemArtAll.get(getCurrentRow()).getId(); System.out.println("IDD = " + idd); int kol = odbKolicina; System.out.println("KOL = " + kol); } public int getCurrentRow() { return currentRow; } public void setCurrentRow(int currentRow) { this.currentRow = currentRow; } public int getOdbKolicina() { return odbKolicina; } public void setOdbKolicina(int odbKolicina) { this.odbKolicina = odbKolicina; } public class itemArt { private int id; //get, set private int cena; private int kolicina; private String nazivArtikla; private String nazivKategorije; public itemArt(){} public itemArt(int id, int cena, int kolicina, String nazivArtikla, String nazivKategorije){ this.id = id; this.cena = cena; this.kolicina = kolicina; this.nazivArtikla = nazivArtikla; this.nazivKategorije = nazivKategorije; } ... Getters and Setters }
Current solution that I have in the code, for taking values from the <> doesn't work. Always returns 0 ( "KOL = 0" in the console). For IDD works correct.
If someone has an idea what the problem is here?
-
3. Re: Help with <a4j:commandButton> within <rich:dataTable>
nbelaevski Dec 23, 2009 7:42 PM (in response to sdf1)Hi,
How about this:
<rich:inputNumberSpinner value="#{itemArt.odbKolicina}"
and also move action method to "itemArt"?
Message was edited by: Nick Belaevski