I have ListView.Where iam showing the some records.The ListView contain Lable and TextField.I entered some data in the textField(which is in ListView).On Submit() method,i am trying to retrieve the entered textfield value.But i am not getting the value which i entered in textbox.Please let me know how to get the entered value from textfield?Below is my code.
public List<StockCountDetail> getItemEntryDetails() {
List<StockCountDetail> myStockCountDetailList = new ArrayList<StockCountDetail>();
List<StockKeepingUnit> mySkuList = MpoBeanFactory.getBean(StockKeepingUnitDAO.class).getByStockLocation(stockLocationModel.getObject());
myStockCountDetailList.clear();
for (StockKeepingUnit mySku : mySkuList) {
StockCountDetail stockCountDetail = new StockCountDetail();
stockCountDetail.setProduct(mySku.getProduct());
myStockCountDetailList.add(stockCountDetail);
}
return myStockCountDetailList;
}
myStockCountDetailList = new ListView<StockCountDetail>("itemList", new PropertyModel<List<StockCountDetail>>(
StockCountEditPage.this, "itemEntryDetails")) {
#Override
protected void populateItem(ListItem<StockCountDetail> aItem) {
aItem.add(new AttributeAppender("class", true, new Model<String>(aItem.getIndex() % 2 == 0 ? "even" : "odd"), " "));
aItem.add(new Label("product", aItem.getModelObject().getProduct().getCode()));
aItem.add(new Label("description", aItem.getModelObject().getProduct().getDescription()));
aItem.add(new CheckBox("skipFlag", new PropertyModel<Boolean>(aItem.getModel(), "skipFlag")));
aItem.add(new TextField<Integer>("count", new PropertyModel<Integer>(aItem.getModel(), "count")));
}
};
myStockCountDetailList.setReuseItems(true);
form.add(myStockCountDetailList);
setOutputMarkupId(true);
AjaxFallbackButton mySave = new AjaxFallbackButton("save", form) {
#Override
protected void onSubmit(AjaxRequestTarget aTarget, Form<?> aForm) {
saveStockCount();
aTarget.addComponent(feedbackPanel);
}
};
form.add(mySave);
private void saveStockCount() {
boolean recordAdded = false;
for (StockCountDetail myStockCount : myStockCountDetailList.getModelObject()) {
if (!myStockCount.isSkipFlag()) {
myStockTransaction.setQuantity(new BigDecimal(myStockCount.getCount()));
}
here i am not getting the value using myStockCount.getCount() which is the entered value of textbox in listview.let me know how to get value of textbox?
Your ListView uses a PropertyModel that gets its value from calling getItemEntryDetails().
It you call myStockCountDetailList.getModelObject() then the resulting object will come from this.getItemEntryDetails() which will return a new List with new StockCountDetails.
In order to retain the value, you could store the list in a field.
Related
I am developing a GWT app where I am using paging toolbar. When I have more than 10 groups in grid, user can go to second page with paging toolbar. But when I press button to go to the second page, it goes to that second, loading is shown but then toolbar is back to the first page with those first. 10 items.
This is first page:
And when I press button for second page I get this loading:
But then after that toolbar backs me to the first page. This is my class for paging toolbar:
public class MyPagingToolBar extends PagingToolBar {
private static final ConsoleMessages MSGS = GWT.create(ConsoleMessages.class);
public MyPagingToolBar(int pageSize) {
super(pageSize);
PagingToolBarMessages pagingToolbarMessages = getMessages();
pagingToolbarMessages.setBeforePageText(MSGS.pagingToolbarPage());
pagingToolbarMessages.setAfterPageText(MSGS.pagingToolbarOf().concat("{0}"));
StringBuilder sb = new StringBuilder();
sb.append(MSGS.pagingToolbarShowingPre())
.append(" {0} - {1} ")
.append(MSGS.pagingToolbarShowingMid())
.append(" {2} ")
.append(MSGS.pagingToolbarShowingPost());
pagingToolbarMessages.setDisplayMsg(sb.toString());
pagingToolbarMessages.setEmptyMsg(MSGS.pagingToolbarNoResult());
pagingToolbarMessages.setFirstText(MSGS.pagingToolbarFirstPage());
pagingToolbarMessages.setPrevText(MSGS.pagingToolbarPrevPage());
pagingToolbarMessages.setNextText(MSGS.pagingToolbarNextPage());
pagingToolbarMessages.setLastText(MSGS.pagingToolbarLastPage());
pagingToolbarMessages.setRefreshText(MSGS.pagingToolbarRefresh());
}
}
And this is class where I using MyPagingToolbar:
public abstract class EntityGrid<M extends GwtEntityModel> extends ContentPanel {
private static final ConsoleMessages MSGS = GWT.create(ConsoleMessages.class);
private static final int ENTITY_PAGE_SIZE = 10;
protected GwtSession currentSession;
private AbstractEntityView<M> parentEntityView;
private EntityCRUDToolbar<M> entityCRUDToolbar;
protected KapuaGrid<M> entityGrid;
protected BasePagingLoader<PagingLoadResult<M>> entityLoader;
protected ListStore<M> entityStore;
protected PagingToolBar entityPagingToolbar;
protected EntityFilterPanel<M> filterPanel;
protected EntityGrid(AbstractEntityView<M> entityView, GwtSession currentSession) {
super(new FitLayout());
//
// Set other properties
this.parentEntityView = entityView;
this.currentSession = currentSession;
//
// Container borders
setBorders(false);
setBodyBorder(true);
setHeaderVisible(false);
//
// CRUD toolbar
entityCRUDToolbar = getToolbar();
if (entityCRUDToolbar != null) {
setTopComponent(entityCRUDToolbar);
}
//
// Paging toolbar
entityPagingToolbar = getPagingToolbar();
if (entityPagingToolbar != null) {
setBottomComponent(entityPagingToolbar);
}
}
#Override
protected void onRender(Element target, int index) {
super.onRender(target, index);
//
// Configure Entity Grid
// Data Proxy
RpcProxy<PagingLoadResult<M>> dataProxy = getDataProxy();
// Data Loader
entityLoader = new BasePagingLoader<PagingLoadResult<M>>(dataProxy);
// Data Store
entityStore = new ListStore<M>(entityLoader);
//
// Grid Data Load Listener
entityLoader.addLoadListener(new EntityGridLoadListener<M>(this, entityStore));
//
// Bind Entity Paging Toolbar
if (entityPagingToolbar != null) {
entityPagingToolbar.bind(entityLoader);
}
//
// Configure columns
ColumnModel columnModel = new ColumnModel(getColumns());
//
// Set grid
entityGrid = new KapuaGrid<M>(entityStore, columnModel);
add(entityGrid);
//
// Bind the grid to CRUD toolbar
entityCRUDToolbar.setEntityGrid(this);
//
// Grid selection mode
GridSelectionModel<M> selectionModel = entityGrid.getSelectionModel();
selectionModel.setSelectionMode(SelectionMode.SINGLE);
selectionModel.addSelectionChangedListener(new SelectionChangedListener<M>() {
#Override
public void selectionChanged(SelectionChangedEvent<M> se) {
selectionChangedEvent(se.getSelectedItem());
}
});
//
// Grid view options
GridView gridView = entityGrid.getView();
gridView.setEmptyText(MSGS.gridEmptyResult());
//
// Do first load
refresh();
}
protected EntityCRUDToolbar<M> getToolbar() {
return new EntityCRUDToolbar<M>(currentSession);
}
protected abstract RpcProxy<PagingLoadResult<M>> getDataProxy();
protected PagingToolBar getPagingToolbar() {
return new MyPagingToolBar(ENTITY_PAGE_SIZE);
}
protected abstract List<ColumnConfig> getColumns();
public void refresh() {
entityLoader.load();
entityPagingToolbar.enable();
}
public void refresh(GwtQuery query) {
// m_filterPredicates = predicates;
setFilterQuery(query);
entityLoader.load();
entityPagingToolbar.enable();
}
public void setFilterPanel(EntityFilterPanel<M> filterPanel) {
this.filterPanel = filterPanel;
entityCRUDToolbar.setFilterPanel(filterPanel);
}
protected void selectionChangedEvent(M selectedItem) {
if (parentEntityView != null) {
parentEntityView.setSelectedEntity(selectedItem);
}
}
public void setPagingToolbar(PagingToolBar entityPagingToolbar) {
this.entityPagingToolbar = entityPagingToolbar;
}
public GridSelectionModel<M> getSelectionModel() {
return entityGrid.getSelectionModel();
}
protected abstract GwtQuery getFilterQuery();
protected abstract void setFilterQuery(GwtQuery filterQuery);
What is my mistake?
EDIT: This is my server method:
int totalLength = 0;
List<GwtGroup> gwtGroupList = new ArrayList<GwtGroup>();
try {
KapuaLocator locator = KapuaLocator.getInstance();
GroupService groupService = locator.getService(GroupService.class);
UserService userService = locator.getService(UserService.class);
GroupQuery groupQuery = GwtKapuaAuthorizationModelConverter.convertGroupQuery(loadConfig,
gwtGroupQuery);
GroupListResult groups = groupService.query(groupQuery);
if (!groups.isEmpty()) {
if (groups.getSize() >= loadConfig.getLimit()) {
totalLength = Long.valueOf(groupService.count(groupQuery)).intValue();
} else {
totalLength = groups.getSize();
}
for (Group g : groups.getItems()) {
gwtGroupList.add(KapuaGwtAuthorizationModelConverter.convertGroup(g));
for (GwtGroup gwtGroup : gwtGroupList) {
User user = userService.find(g.getScopeId(), g.getCreatedBy());
if (user != null) {
gwtGroup.setUserName(user.getDisplayName());
}
}
}
}
} catch (Exception e) {
KapuaExceptionHandler.handle(e);
}
return new BasePagingLoadResult<GwtGroup>(gwtGroupList, loadConfig.getOffset(),
totalLength);
}
(Didn't I just answer this an earlier version of this? Please don't delete questions after you get an answer to them, or people won't answer your questions at all any more.)
If the server is given a request for the second page (offset of 10), but returns a PagingLoadResult for the first page anyway, that is what you will see. Make sure your server is actually sending back the second page - not only that, but it must send in the response object the offset that it actually used for the next page (in your example, 10), or else the paging toolbar will not know which page the user is actually on.
Make sure the server is taking the request offset into account, and returning the parameters it used correctly to the client. If that appears to be correct, please add the server method to your question, and add logging on the client and server to verify what is being requested, vs what is being returned.
Skipping items in Java is pretty straightforward, but will not scale very well for huge lists.
In short, just skip the first offset items when looping.
First though, a free code review - this is very inefficient code - you are rewriting every item in gwtGroupList every time you add something:
for (Group g : groups.getItems()) {
gwtGroupList.add(KapuaGwtAuthorizationModelConverter.convertGroup(g));
for (GwtGroup gwtGroup : gwtGroupList) {
User user = userService.find(g.getScopeId(), g.getCreatedBy());
if (user != null) {
gwtGroup.setUserName(user.getDisplayName());
}
}
It could instead read:
for (Group g : groups.getItems()) {
gwtGroupList.add(KapuaGwtAuthorizationModelConverter.convertGroup(g));
}
for (GwtGroup gwtGroup : gwtGroupList) {
User user = userService.find(g.getScopeId(), g.getCreatedBy());
if (user != null) {
gwtGroup.setUserName(user.getDisplayName());
}
}
Alternatively, they could be just one loop.
Now we modify it again, to handle offset and limit:
int itemsLeftToSkip = offset;
for (Group g : groups.getItems()) {
if (itemsLeftToSkip > 0) {
itemsLeftToSkip--;
continue;//we skipped this item, and now the count is one less
}
if (gwtGroupList.size() >= limit) {
break;//we've got enough already, quit the loop
}
gwtGroupList.add(KapuaGwtAuthorizationModelConverter.convertGroup(g));
}
for (GwtGroup gwtGroup : gwtGroupList) {
User user = userService.find(g.getScopeId(), g.getCreatedBy());
if (user != null) {
gwtGroup.setUserName(user.getDisplayName());
}
}
Notice how we use offset to avoid items until we get to the ones that are needed for the new page, and we use limit to only send that many time, at a maximum.
Finally, unless your groupQuery already has a limit built in (in which case, you should put the offset there too...), the if (groups.getSize() >= loadConfig.getLimit()) { block of code is likely not necessary at all, since you've already loaded all items. If it is necessary because there is a limit, then your pages will not correctly load all the way to the end. Either way, investigate this code, and possibly get it reviewed further, something looks very wrong there.
I have a complex problem, what I don't understand. In this class I would like to
add 21 random objects from one arraylist listChallenges to the arraylist finalChallenges. However it doesn't work , sometimes finalChallanges contains 21 objects , but most of the times it contains less objects, but I don't know where is the problem. Actually, I tried to comment every step, and if did something wrong, please tell me.
Please help me, I have no idea what shoud I do..
ArrayList<Challenges> listChallenges = new ArrayList<Challenges>();
ArrayList<Challenges> finalChallenges = new ArrayList<Challenges>(20);
//Check where the same userId and subscribers.objectId,
//Request these categories object and save to the ArrayList<Category> totalCategories
//Save these categories objectId to the selectedCategoriesId List<String>
BackendlessDataQuery query = new BackendlessDataQuery();
query.setWhereClause( "subscribers.objectId = '"+backendlessUser.getObjectId()+"'");
Backendless.Data.of(Category.class).find(query, new AsyncCallback<BackendlessCollection<Category>>() {
#Override
public void handleResponse(BackendlessCollection<Category> categoriesBackendlessCollection) {
//add selected categories to totalActivities Category ArrayList
for( Category categories : categoriesBackendlessCollection.getData()) {
totalCategories.add(categories);
selectedCategoriesId.add(categories.getObjectId());
//
}
System.out.println(selectedCategoriesId);
//For cycle is going to selectedCategoriesId.size
//Check where the same category-objectId and actual selectedCategoriesId
//Request these challenges object, which are in the actual category and save to the ArrayList<Challenges> listChallenges
//Save these categories objectId to the selectedCategoriesId List<String>
for(int k=0;k<selectedCategoriesId.size();k++) {
BackendlessDataQuery query = new BackendlessDataQuery();
query.setPageSize(pageSize);
query.setWhereClause("category.objectId = '" + selectedCategoriesId.get(k) + "'");
Backendless.Data.of(Challenges.class).find(query, new AsyncCallback<BackendlessCollection<Challenges>>() {
#Override
public void handleResponse(BackendlessCollection<Challenges> cha) {
for (Challenges challenges : cha.getData()) {
listChallenges.add(challenges);
challengeTitle.add(challenges.getChallengeTitle());
challengeContent.add(challenges.getChallengeContent());
challangeId.add(challenges.getObjectId());
}
System.out.println("osszes elem:"+listChallenges);
//ArrayList<Challenges> finalChallenges size is 21 with 0
// get from listChallenges random 21 object without concord and add to the finalChallenges
Random random = new Random();
List<Challenges> temp = new ArrayList<>(listChallenges);
ArrayList<Challenges> tempNewList = new ArrayList<Challenges>();
//ArrayList<Challenges> temp = new ArrayList<Challenges>(listChallenges.size());
for (Challenges item : listChallenges) temp.add(item);
while (finalChallenges.size()<21 && temp.size()>0) {
int index = random.nextInt(temp.size());
tempNewList.add(temp.get(index));
temp.remove(index);
finalChallenges= tempNewList;
}
// System.out.println("kihívások");
System.out.println(finalChallenges);
System.out.println(finalChallenges.size());
// title.setText(challengeTitle.get(0));
// content.setText(challengeContent.get(0));
// objectId = challangeId.get(0);
}
#Override
public void handleFault(BackendlessFault fault) {
}
});
//save finalChallenges array objects to the current user "userChallenges" relationship
Backendless.UserService.login( email, password, new AsyncCallback<BackendlessUser>() {
#Override
public void handleResponse(BackendlessUser backendlessUser) {
backendlessUser.setProperty("userChallenges",new ArrayList<>(finalChallenges));
}
});
Backendless.UserService.update(backendlessUser, new BackendlessCallback<BackendlessUser>() {
#Override
public void handleResponse(BackendlessUser response) {
System.out.println( "User has been updated" );
}
#Override
public void handleFault(BackendlessFault fault) {
System.out.println( "User has not been updated");
}
});
}
#Override
public void handleFault(BackendlessFault backendlessFault) {
System.out.println( "Server reported an error - " + backendlessFault.getMessage() );
}
},true);
}
}
#Override
public void handleFault(BackendlessFault fault) {
}
});
You don't show where finalChallenges is initialized, and we can see it is overwritten asynchronously in response handlers: it is very likely an issue of concurrent access.
The logic itself where you fill the list from random elements of another list would be correct, if the instance of finalChallenges was not "shared" across different/concurrent executions of that handler.
Also, a small tip: to create your temp list in one go without loop you can do this: List<Challenge> temp = new ArrayList<>(listChallenges);
Edit: 2 suggestions.
Use a temporary list in your loop when you fill it, then swap the lists atomically (listChallenges = tempNewList)
When you pass your list to user properties, pass a copy (backendlessUser.setProperty("userChallenges", new ArrayList<>(finalChallenges));)
NewForm.java
public class NewForm extends WebPage {
private Bean bean;
private DropDownClass dropdown;
private String selected = "choice";
void init()
{
bean = new Bean();
dropdown=new DropDownClass("test");
}
public NewForm(final PageParameters page) {
init();
final TextField<String> textname = new TextField<String>("name",Model.of(""));
textname.setRequired(true);
final DropDownChoice<String> dropname = new DropDownChoice<String>("type", new PropertyModel<String>(this, "selected"),
dropdown.getlist());
Form<?> form = new Form<Void>("Form") {
#Override
public void onSubmit() {
final String name = (String) textname.getModelObject();
final String dropdown = (String)dropname.getModelObject();
bean.add(name,dropdown);
final String schema = bean.getJsonSchema().toString();
page.add("schema", schema);
setResponsePage(new NewForm(page));
}
};
Label schemalabel = new Label("schema", page.get("schema"));
add(form);
form.add(textname);
form.add(dropname);
form.add(schemalabel);
}
}
Bean.java
public class Bean
{
private JSONObject jsonSchema;
public JSONObject getJsonSchema() {
return jsonSchema;
}
public void setJsonSchema(JSONObject jsonSchema) {
this.jsonSchema = jsonSchema;
}
public Bean() {
jsonSchema = new JSONObject();
}
public void add(String key,String value)
{
jsonSchema.put(key, value); // I am able to append values each time using "put" or "append" in JSF but not in WICKET.How can I append values in Wicket?
//or jsonSchema.append(key, value); //adding values only once and not appending each time,I enter the values in TextField and DropDown
}
}
In CreateForm.java - I have a Textfield and DropDown. When I enter the values in TextField and DropDown..I am able to convert the values entered in TextField and DropDown as JSON schema from method add(String key,String value) in AttributeInfo.java and display the schema as - {"name":"abc"} //where name is value entered in TextField and abc is from DropDown.
I am able to display the schema only once onSubmit But I need to append the values to schema each time,I enter in TextField and DropDown onSubmit and display in the samepage.
How can I achieve this in Wicket?
I am just a beginner.Any Help would be appreciated.Thankyou in advance.
i have one native select branchStateSelect:
branchStateSelect = new NativeSelect("State:");
branchStateSelect.setImmediate(true);
branchStateSelect.setWidth(COMMON_FIELD_WIDTH);
branchStateSelect.setRequired(true);
branchStateSelect.setNullSelectionItemId(0);
branchStateSelect.setItemCaption(0, "--Select--");
branchStateSelect.addValueChangeListener(fetchCityListener);
and there is another native select : this is binded to a fieldgroup
communicationAddressStateSelect = new NativeSelect("State:");
communicationAddressStateSelect.setRequired(true);
communicationAddressStateSelect.setImmediate(true);
communicationAddressStateSelect.setNullSelectionAllowed(true);
communicationAddressStateSelect.setWidth(COMMON_FIELD_WIDTH);
communicationAddressStateSelect.setEnabled(false);
and the city listener for state select :
private ValueChangeListener fetchCityListener = new ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
if (event.getProperty().getValue() == null) {
//do nothing
}
else{
communicationAddressStateSelect.setNullSelectionItemId(0l
communicationAddressStateSelect.setItemCaption(0l,
"state1");
communicationAddressStateSelect.select(0l);
}
}
}}
}
};
when I select branchstateselect native select
the value in the communicationAddressStateSelect is populated
but value binded to the fieldgroup is null???? why>?>>>
I want value 0L to be binded... what is the error
I'm trying to build grid with build in column filtering (using sencha gxt), here is my code:
public Grid<Stock> createGrid() {
// Columns definition
ColumnConfig<Stock, String> nameCol = new ColumnConfig<Stock, String>(props.name(), 100, "Company");
// Column model definition and creation
List<ColumnConfig<Stock, ?>> cl = new ArrayList<ColumnConfig<Stock, ?>>();
cl.add(nameCol);
ColumnModel<Stock> cm = new ColumnModel<Stock>(cl);
// Data populating
ListStore<Stock> store = new ListStore<Stock>(props.key());
store.addAll(TestData.getStocks());
// Grid creation with data
final Grid<Stock> grid = new Grid<Stock>(store, cm);
grid.getView().setAutoExpandColumn(nameCol);
grid.setBorders(false);
grid.getView().setStripeRows(true);
grid.getView().setColumnLines(true);
// Filters definition
StoreFilterField<Stock> filter = new StoreFilterField<Stock>() {
#Override
protected boolean doSelect(Store<Stock> store, Stock parent, Stock item, String filter) {
// Window.alert(String.valueOf("a"));
String name = item.getName();
name = name.toLowerCase();
if (name.startsWith(filter.toLowerCase())) {
return true;
}
return false;
}
};
filter.bind(store);
cm.addHeaderGroup(0, 0, new HeaderGroupConfig(filter, 1, 1));
filter.focus();
return grid;
}
My problem is: after I run this code, I cannot write anything to filter input, I'm using test data and classes (Stock.java and StockProperties.java) from this example: http://sencha.com/examples-dev/#ExamplePlace:filtergrid
I try to put allert in doSelect method to check if this function was called, but it wasn't.
Any idea will be welcome. Thanks.
I was able to make your code work. I observed that there were compiler errors in the code for StoreFilterField class. Here is the code that filters the grid based on the values in the first column, that is, name field in the Stock model.
StoreFilterField<Stock> filter1 = new StoreFilterField<Stock>() {
#Override
protected boolean doSelect(Store<Stock> store, Stock parent, Stock record, String property, String filter) {
String name = record.get("name");
name = name.toLowerCase();
if (name.startsWith(filter.toLowerCase())) {
return true;
}
return false;
}
};
filter1.bind(store);
Btw, I tested this with GXT 2.2.5 and GWT 2.4.
Thanks,
Ganesh
I solve this problem according to this paper http://www.sencha.com/forum/archive/index.php/ … but I replace disableTextSelection(false) with setAllowTextSelection(true);