Can someone hint me on how to utilize selection functionality of extendeddatatable in rich:datatable ?
My requirement is each row contains more than 15 columns and all are editable and should be able to scale upto 3000 records in a page.
I'm using JSF 1.2 and richfaces 3.3.3.final with spring webflow.
To use the selection attribute on extendeddatatable:
Declare in your view
<rich:extendedDataTable id="xxxDataTable" value="#{xxxBean.listXxxDataModel}"
var="xxxItem" selectionMode="single" rows="3" width="800px" height="100px" noDataLabel="#{msg.dataTable_noDataLabel}"
selection="#{xxxBean.xxxSelection}">
Bind your dataTable value to ExtendedTableDataModel : use a org.richfaces.model.DataProvider to provide data to the ExtendedTableDataModel.
ArrayList<XXX> values = ...;
XXXDataProvider xxxDataProvider = new XXXDataProvider(values);
ExtendedTableDataModel<XXX> xxxDataModel = new ExtendedTableDataModel<XXX>(xxxDataProvider);
The selection is binding to
/** Binding selection */
private SimpleSelection xxxSelection;
Last, to retrieve the selected object from your dataprovider :
key = xxxSelection.getKeys().next();
selectedObject = xxxDataModel.getObjectByKey(key);
Related
I create two SelectOneMenu in JSF:
SelectOneMenu menu = new SelectOneMenu();
menu.setId("MenuSelect1" + ctrlCenterResultModel.getId());
UISelectItems item = new UISelectItems();
item.setValue(ctrlCenterResultModel.getBudget());
menu.getChildren().add(item);
SelectOneMenu menu1 = new SelectOneMenu();
menu1.setId("MenuSelect2" + ctrlCenterResultModel.getId());
UISelectItems item1 = new UISelectItems();
item1.setId("Item2"+ctrlCenterResultModel.getId());
item1.setValue(ctrlCenterResultModel.getPeriods());
menu1.getChildren().add(item1);
I want set ValueChangeListener for second menu. When I change value in first SelectOneMenu in second I want have different values. For example in first SelectOneMenu I choose Budget1 and I have period for this budget. Next my problem is that I set list of objects in UISelectItems and when I get value for this item I have String, not Object. I know how do that, when SelectOneMenu is created in XHTML, but in this case I create it in Java code.
I have a dataTable that is populated using my Bean. I am only wanting to display the first 15 results, then allow the user to use a next button that will display the next 15 results. Here is my dataTable
<h:dataTable id ="data" value="#{copd.getCopds()}" var="c"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row">
my CopdBean has an int value called pageNumber that it passes down to be used with the CopdDaoImpl to determine the results for the table. Here is a quick path down the backend...
CopdBean.java
public List<Copd> getCopds(){
return copdBo.findAllCopd(pageNumber);
}
copdBoImp.java
public List<Copd> findAllCopd(int pageNumber) {
return copdDao.findAllCopd(pageNumber);
}
copdDaoImp.java
private static int pageSize = 15;
public List<Copd> findAllCopd(int pageNumber){
Criteria crit = getSession().createCriteria(Copd.class);
crit.add(Restrictions.like("copdPK.upi","0%"));
crit.addOrder(Order.desc("copdPK.upi"));
crit.setFirstResult(pageSize * (pageNumber -1));
crit.setMaxResults(pageSize);
return crit.list();
}
So as you can see, when the pageNumber int value is updated, the copd.getCopds() will display the next 15. When i hard code and change the int value to say 2, 3, or 4 and run the webapp, everything displays correclty. I'm just needing button functionality that will update this pageNumber value, and refresh the dataTable(aka recalling the copd.getCopds() and storing that result as 'value' in the dataTable.
I have a commandButton labeled Next that will call a method to update my pageNumber int value. But when this button is clicked nothing happens. I have even ran in debug and it seems the method is never called.
<h:commandButton value="Next" action="#{copd.nextPage()}"/>
copd.nextPage() just increases the int value by 1. However clicking this button does nothing. I have tried
onclick="refreshTable()"
with
<script type="text/javascript">
function refreshTable()
{
var table = document.getElementById("data");
table.refresh();
}
</script>
I have also tried <f:ajax render="data"/>
Everything works for my application, i'm just trying to basically update the 'value' in the dataTable and then refresh the dataTable without the whole page refreshing(which i'm told will then start over with a new bean) so that i'm only displaying 15 rows at a time vs. all 150 or 200 or 4000. Any help is greatly appreciated as I know its just something simple i'm missing on my front end dataTable.
How do we dynamically (from java program) add a tab to existing TabView primefaces component.
My situation is something like this,
There is a drop down with some values,
whenever user selects some value from drop down,
We need to add a tab dynamically at specific position to TabView.
I know we can get existing TabView component, and add a tab,
But if we want add a tab at particular position , how ?
public void addTab(){
FacesContext fc = FacesContext.getCurrentInstance();
TabView tabView = (TabView) fc.getApplication().createComponent(
"org.primefaces.component.TabView");
Tab tab1 = new Tab();
tab1.setTitle("Dynamic Tab-1");
tabView.getChildren().add(index,tab1);
}
You should update the view to reflect the new tab. Use RequestContext for ajax update.
RequestContext context = RequestContext.getCurrentInstance();
context.update("tabview");
I'm using dojo dataGrid, and i need to get the row id.
When i use the "rowIndex" event, i get the "id" of the row, but, if i sort the grid, the data keeps another value in the row "id".
Can someone tell me how to solve this problem ? Thanks
Do you need the row of the grid when selected? Why do you need the row id? Usually I find if I let dojo handle row and data sorting for me and just pull in the selected item when I need it I'm better off.
e.g.
function onSelectedGridParm(nRow){
var objGridParm = dijit.byId("gridParm");
var item = objGridParm.getItem(nRow);
// single select - use an array here for multi select
// and remove in onDeselect
_selectedVariable = item;
fnEnableButton( "VariableEdit" );
fnEnableButton( "VariableDelete" );
}
....
<div id="gridParm" dojoType="dojox.grid.DataGrid"
style="width: 100%; height: 550px;"
structure="layoutVariables"
selectionMode="single"
noDataMessage="No Data Found with current filters"
onSelected="onSelectedGridParm"
onDeselected="onDeselectedGridParm"
rowsPerPage="50"
>
</div>
I've created a custom edit form as a simple aspx page in VS2010 (inherits from LayoutsPageBase) which uses the SharePoint Web controls LookupField control to display a drop down list of values from a custom type
The form displays correctly with the drop down box containing the expected range of values
The ControlMode is set to the same as the FormContext (though I have tried explicitly setting this to Edit)
But on the postback the value of the dropdown list is not set - the selected item index is set to -1
How can I correctly use the LookupField control to capture a selected value from the user?
Could it be because I'm adding the controls declaritivly in the aspx and then setting the list id etc from the SPContext in the page load event? - see code snippet below (not the prettiest but just trying to get it to work at this point):
from aspx:
<SharePoint:FileField ID="FileNameText" InputFieldLabel="Name" runat="server" ControlMode="Display"/><br />
<SharePoint:LookupField ID="FeedType" runat="server" />
<SharePoint:TextField ID="FeedStatus" runat="server" />
....
in the code behind page load:
if (!IsPostBack)
{
SPItem feedFileItem = SPContext.Current.Item;
FileNameText.ControlMode = SPContext.Current.FormContext.FormMode;
FileNameText.ListId = SPContext.Current.ListId;
FileNameText.ItemId = SPContext.Current.ItemId;
FileNameText.FieldName = "Name";
FeedType.ControlMode = SPControlMode.Edit;
FeedType.ListId = SPContext.Current.ListId;
FeedType.ItemId = SPContext.Current.ItemId;
FeedType.FieldName = "FeedType";
FeedStatus.ItemContext = SPContext.Current;
FeedStatus.RenderContext = SPContext.Current;
FeedStatus.ControlMode = SPControlMode.Edit;
FeedStatus.ListId = SPContext.Current.ListId;
FeedStatus.ItemId = SPContext.Current.ItemId;
FeedStatus.FieldName = "FeedStatus";
}
UPDATE
Ok I managed to get my form working by adding the controls in the code behind in the override of CreateChildControls - this is in line with the majority of the samples I've seen on the net.
But can someone explain why my approach didn't work and whether I can do this all in a declarative way in the aspx?
During postbacks selected values from lists are simply ignored if the list control isn't populated. So if you choose item 2 and the list items are null it will simply ignore the response parameter and not set the Value property. This is because ProcessPostData occurs prior to LoadData. Even if you were to remove the !IsPostBack on the LoadData method it still wouldn't work because ProcessPostData still occurs before LoadData and you didn't load the list prior to processing the postback.
A simple way to fix this is move your initialization code into the EnsureChildControls method of your Application page.
protected override void EnsureChildControls()
{
base.EnsureChildControls();
...
FeedType.ControlMode = SPControlMode.Edit;
FeedType.ListId = SPContext.Current.ListId;
FeedType.ItemId = SPContext.Current.ItemId;
FeedType.FieldName = "FeedType";
...
}