I think i am doing the right thing with this.. i went to jenia.org and followed the instructions.. as i told you that i was not even getting the checkboxes, now i am getting them.. but when i click on the commandButton, i dont get the selected rows in the Collection/ List (i tried both one at a time). I am pasting my jsp and my bean code as under.. and i have the 2 jar files in the classpath : commons and dataTools provided by jenia. I could just not figure out where i am going wrong. Could you plz have a look at the code..
<
h:form>
<h:dataTable value="#{MaintenanceBean.perfFeeMaintModel.perfFee
}"
var="accountList"
id="perfFeeMaint"
rows="4">
<t:column>
<f:facet name=
"header">
<h:outputText value=
"Number"></h:outputText>
</f:facet>
<t:outputText value="#{accountList.id
}"></t:outputText>
</t:column>
<t:column>
<f:facet name=
"header">
<h:outputText value=
"Account"></h:outputText>
</f:facet>
<t:outputText value="#{accountList.account
}"></t:outputText>
</t:column>
<t:column>
<f:facet name=
"header">
<h:outputText value=
"Performance Fee"></h:outputText>
</f:facet>
<jdt:multipleRowsSelector
selectionList="#MaintenanceBean.perfFeeMaintModel.selectionList}"
/>
</t:column>
</h:dataTable>
<h:panelGrid columns="22"
cellpadding="0" cellspacing=
"0" border="0" width=
"80" >
<t:dataScroller id="perfFeeScroller"
for="perfFeeMaint"
pageCountVar="pageCount"
pageIndexVar="pageIndex"
paginator="true"
paginatorMaxPages="9"
paginatorTableClass="paginator"
paginatorActiveColumnStyle="font-weight:bold;"
>
<f:facet name="first"
>
<h:graphicImage value="/images/FirstPage.gif"
style="margin-top:4pt;"/>
</f:facet>
<f:facet name="last"
>
<h:graphicImage value="/images/LastPage.gif"
style="margin-top:4pt;"/>
</f:facet>
<f:facet name="previous"
>
<h:graphicImage value="/images/PreviousItem.gif"
style="margin-top:4pt;"/>
</f:facet>
<f:facet name="next"
>
<h:graphicImage value="/images/NextItem.gif"
style="margin-top:4pt;"/>
</f:facet>
</t:dataScroller>
</h:panelGrid>
</h:form>
<h:form id="saveForm"
>
<h:panelGroup>
<h:commandButton id="savePerf"
value="Save" action="#MaintenanceBean.perfFeeMaintModel.save
}"></h:commandButton>
</h:panelGroup>
</h:form>
Bean code:
List
perfFee = new ArrayList();
private Collection selectedList;
public Collection getSelectedList() {
return selectedList;
}
public void setSelectedList(Collection selectedList) {
this.selectedList = selectedList;
}
public List getPerfFee() {
perfFee.add(new PerformanceFeeData(1, "001"
, true));
perfFee.add(new PerformanceFeeData(2, "002"
, true));
perfFee.add(new PerformanceFeeData(3, "003"
, false));
perfFee.add(new PerformanceFeeData(4, "004"
, true));
perfFee.add(new PerformanceFeeData(5, "005"
, true));
perfFee.add(new PerformanceFeeData(6, "006"
, true));
perfFee.add(new PerformanceFeeData(7, "007"
, false));
perfFee.add(new PerformanceFeeData(8, "008"
, true));
perfFee.add(new PerformanceFeeData(9, "009"
, true));
perfFee.add(new PerformanceFeeData(10, "010"
,true));
return perfFee;
}
public String save(){
//setSelectedRow(Integer.parseInt((String) FacesContext.getCurrentInstance
).getExternalContext().getRequestParameterMap().get("selectedRow")));
//setSelectedPerf(Boolean.parseBoolean((String) FacesContext.getCurrentInstance
).getExternalContext().getRequestParameterMap().get("selectedPerf")));
//System.out.println("selected row: " + selectedRow + " selected perf : " + selectedPerf);
if(selectedList != null
){
System.out.println("size " +
selectedList.size());
}
return "success";
}
Here, the selectedList.size() gives me zero even if i select some checkboxes...
I would really appreciate your help.. have been trying this for a long time now..
Thanks again for taking out time to guide me..
Regards,
Nimisha.
On 8/9/06, Andrew Robinson <[EMAIL PROTECTED]> wrote:
Jenia's data multipleRowsSelector builds a list of the objects that
you are iterating over. So if your data table's value points to a list
of "MyObject" then the multipleRowsSelector will create list of
MyObject instances for each row that had the checkbox selected.
public class MyItem { ... }
public class MyBean
{
private List<MyItem> selectedItems;
private List<MyItem> allItems;
public List<MyItem> getSelectedItems() { return selectedItems; }
public void setSelectedItems(List<MyItem> selectedItems)
{ this.selectedItems = selectedItems; }
public List<MyItem> getAllItems() { return allItems; }
public String load()
{
// load all items here
}
public String onSubmit()
{
// put your code here
for (MyItem item : selectedItems)
; // do something with it
}
}
<t:dataTable
value="#{myBean.allItems}"
var="_item">
<t:column>
<jdt:multipleRowsSelector
selectionList="#{ myBean.selectedItems}" />
</t:column>
<t:column>
<f:facet name="header">
<t:outputText value="Something" />
</f:facet>
<t:outputText value="#{_item.something}" />
</t:column>
</t:dataTable>
<t:commandLink action="">value="Submit" />
As I mentioned, you don't want to work with IDs of the checkboxes.
-Andrew
On 8/9/06, nimisha sharma <[EMAIL PROTECTED]> wrote:
>
> I also saw your post on
> http://mail-archives.apache.org/mod_mbox/myfaces-users/200605.mbox/[EMAIL PROTECTED]
>
> but i dont get any checkboxes when i use :
>
>
> <jdt:multipleRowsSelector selectionList="#{ mybean.selectedItems}" />
>
>
> To be more precise, plz find my datatable part:
>
>
>
> <html xmlns:jdt="http://www.jenia.org/jsf/dataTools ">
>
> -------
>
> <
> t:dataTable
> value="#{MaintenanceBean.perfFeeMaintModel.perfFee}"
>
> var="accountList"
>
> id="perfFeeMaint"
>
> rows="4">
>
> <t:column>
>
> <f:facet name="header" >
>
> <h:outputText value="Number" ></h:outputText>
>
> </f:facet>
>
>
>
> <t:outputText value="#{accountList.id}" >
>
> <f:param id="selectedRow"
>
> name="id"
>
> value="#{ accountList.id}" />
>
> </t:outputText>
>
> </t:column>
>
> <t:column>
>
> <f:facet name="header" >
>
> <h:outputText value="Account" ></h:outputText>
>
> </f:facet>
>
>
>
> <t:outputText value="#{accountList.account}" ></t:outputText>
>
> </t:column>
>
> <t:column>
>
> <f:facet name="header" >
>
> <h:outputText value="Performance Fee" ></h:outputText>
>
> </f:facet>
>
>
>
> <jdt:multipleRowsSelector selectionList="#{ accountList.selectedPerf }" />
>
>
>
>
>
> </t:column>
>
> </t:dataTable>
> I need the id for each checkbox that is selected by the user.. like in
> regular HTML, i can do that by request.getParameterValues() and it gives me
> an array..
>
> Thanks for the help again...
>
> Regards,
>
> Nimisha.
>
>
>
>
> On 8/9/06, nimisha sharma <[EMAIL PROTECTED]> wrote:
> >
> >
> > Hi Andrew,
> >
> > Thanks for the quick response. What i want to do exactly is that one of
> the columns (it is a property in my list) in my datatable contains
> checkboxes.. i have to get them prepopulated (this i can easily do since the
> list that i pass to my datatable has it)
> > Now, once the user has this infront of him, he can modify the status of
> these checkboxes and submit the form. I need to retrieve these values in my
> bean.. so that i can update the db with the values selected by the user.
> >
> > With the first option i could not get exactly what has to be done.
> >
> > Regards,
> >
> > Nimisha.
> >
> >
> > On 8/9/06, Andrew Robinson <[EMAIL PROTECTED] > wrote:
> > > And FYI, you should avoid using the request parameters yourself -- it
> > > is best to let the JSF controls do that. DataTables not only use
> > > client IDs, but also add an inded for each row, so it is really not
> > > best to attempt to reproduce the ID yourself. Also renderers have the
> > > full ability and right according to the specification to change the ID
> > > to whatever they want (they don't even have to use the ID attribute
> > > from the UIComponent if they don't want to)
> > >
> > > On 8/9/06, Andrew Robinson < [EMAIL PROTECTED] > wrote:
> > > > If the checkbox is for a property on your loop variable (say Item):
> > > >
> > > > <t:dataTable
> > > > value="#{mybean.mylist}"
> > > > var="_item">
> > > > <t:column>
> > > > <t:selectBooleanCheckbox value="#{_item.selected}" />
> > > > </t:column>
> > > > </t:dataTable>
> > > >
> > > > If you want to save the checked items in a list on the bean:
> > > > <html
> > > > ...
> > > > xmlns:jdt=" http://www.jenia.org/jsf/dataTools">
> > > > ...
> > > > <t:dataTable
> > > > value="#{mybean.mylist}"
> > > > var="_item">
> > > > <t:column>
> > > > <jdt:multipleRowsSelector
> > > > selectionList="#{ mybean.selectedItems}" />
> > > > </t:column>
> > > > </t:dataTable>
> > > >
> > > > Where "selectedItems" would map to methods:
> > > > public List<Item> getSelectedItems()
> > > > public void setSelectedItems(List<Item> items)
> > > >
> > > > -Andrew
> > > >
> > > > On 8/9/06, nimisha sharma < [EMAIL PROTECTED]> wrote:
> > > > >
> > > > > Hi,
> > > > >
> > > > > I think this discussion must have already been there on this but
> since i
> > > > > could not find it, i m posting it here..
> > > > >
> > > > > I have a datatable where i have checkboxes in one column that the
> user
> > > > > checks.. these values have to be saved when the user clicks the save
> button.
> > > > > Somehow, i cannot get the values in my bean.. The command button for
> save
> > > > > has an action that calls the save() method in my bean. I have to get
> the
> > > > > values here so that i can update the db tables with these values.
> > > > >
> > > > > With each checkbox, i have set the param also.. as given:
> > > > >
> > > > >
> > > > >
> > > > > <t:selectBooleanCheckbox value="#{ accountList.perfFee}" >
> > > > >
> > > > > <f:param id="selectedPerf"
> > > > >
> > > > > name="perf"
> > > > >
> > > > > value="#{accountList.perfFee}" />
> > > > >
> > > > > </t:selectBooleanCheckbox>
> > > > >
> > > > > now, in my bean if i try getting the value using:
> > > > >
> > > > > (String)
> > > > >
> FacesContext.getCurrentInstance ().getExternalContext().getRequestParameterMap().get("selectedPerf");
> > > > > it returns null as there would be a List of values..
> > > > >
> > > > > Could someone give me directions as to how this can be done...
> > > > >
> > > > > Appreciate,
> > > > >
> > > > >
> > > > > Nimisha.
> > > > >
> > > >
> > >
> >
> >
>
>

