why value in a native select not binding to the fieldgroup vaadin - java

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

Related

Why my grid does not move on second page with paging toolbar(GWT 2.4)?

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.

How to make a function of an object that doesn't stop even closing it's form in netbeans

My problem is that after closing the frame for admin that will set the available products the selected products gets unselected
The checkbox here must get activated by the admin from the other form
Here's my code:
private void chk1ActionPerformed(java.awt.event.ActionEvent evt) {
Cashier x = new Cashier();
if (chk1.isSelected() == true)
{
x.chkpr1.setEnabled(true);
}
else
{
x.chkpr1.setEnabled(false);
}
}

Retrieve TextField value from the ListView

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.

Hibernate update without select

I've a question on hibernate operation: update.
Here a bit of code:
Campaign campaign = campaignDAO.get(id);
campaign.setStatus(true);
campaignDAO.update(campaign);
If I just have all the data of the campaign object, is there any way to perform an update without perform the first select (campaignDAO.get(id)) ?
Thanks,
Alessio
HQL will definitely help you.
In order to maintain the separation of concerns, you can add a more specialized method in you DAO object:
public void updateStatusForId(long id, boolean status){
//provided you obtain a reference to your session object
session.createQuery("UPDATE Campaign SET status = " + status + " WHERE id = :id").setParameter("id", id).executeUpdate();
//flush your session
}
Then you could simply call this method from your business method. You can check the generated SQL statements inside the logs of your app by setting the show_sql hibernate property to true.
You can use session.load(). It will not hit the database. Here you can find its details and example code.
I had worte a extension to solve this issue in Nhibernate
how to use!
first of all you need enable dynamic-update="true"
using (ISession session = sessionFactory.OpenSession())
{
Customer c1 = new Customer();
c1.CustomerID = c.CustomerID;
session.Mark(c1);
// c1.Name = DateTime.Now.ToString();
c1.Phone = DateTime.Now.ToString();
//需要开启动态更新
session.UpdateDirty(c1);
session.Flush();
}
UpdateExtension.cs
public static class UpdateExtension
{
static readonly Object NOTNULL = new Object();
public static void UpdateDirty<TEntity>(this ISession session, TEntity entity)
{
SessionImpl implementor = session as SessionImpl;
EntityEntry entry = implementor.PersistenceContext.GetEntry(entity);
if (entry == null)
{
throw new InvalidOperationException("找不到对应的实例,请先使用Mask方法标记");
}
IEntityPersister persister = entry.Persister;
// 如果某列不可以为空,新的Entity里也不想更新他。
// 那么LoadState 里的值应该和Entity 中的值相同
Object[] CurrentState = entry.Persister.GetPropertyValues(entity, EntityMode.Poco);
Object[] LoadedState = entry.LoadedState;
int[] dirtys = persister.FindDirty(CurrentState
, LoadedState
, entity
, (SessionImpl)session);
if (dirtys == null || dirtys.Length == 0)
{
return;
}
persister.Update(entry.Id
, CurrentState
, dirtys
, true
, LoadedState
, entry.Version
, entity
, entry.RowId
, (SessionImpl)session);
implementor.PersistenceContext.RemoveEntry(entity);
implementor.PersistenceContext.RemoveEntity(entry.EntityKey);
session.Lock(entity, LockMode.None);
// 防止(implementor.PersistenceContext.EntityEntries.Count == 0)
}
public static void Mark<TEntity>(this ISession session, TEntity entity)
{
session.Lock(entity, LockMode.None);
}
}
here is update sql
command 0:UPDATE Customers SET Phone = #p0 WHERE CustomerID = #p1;#p0 = '2014/12/26 0:12:56' [Type: String (4000)], #p1 = 1 [Type: Int32 (0)]
Only update Phone column .
event Name property can not be null. we can work very well.

ExtGWT StoreFilterField input doesn't react

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);

Categories