GWT confirmation dialog box - gwt

I'm trying to create a modal confirmation dialog box. I'd like it to work like Window.confirm(""), where I can just call it, and get a boolean response.
My trouble is I'm not sure how to do it. I'm trying to use MVP in my application. Here is the code I have so far:
public class DialogBoxPresenter implements Presenter {
public interface Display {
Label getDialogText();
Button getAffirmativeButton();
Button getCancelButton();
Widget asWidget();
public void center();
public void hide();
public void setHeader(String text);
}
private Display display;
private String header;
private String dialogText;
private String cancelButtonText;
private String affirmativeButtonText;
protected DialogBoxPresenter() {
}
public DialogBoxPresenter(Display display, String header, String dialogText, String cancelButtonText, String affirmativeButtonText) {
this.display = display;
this.header = header;
this.dialogText = dialogText;
this.cancelButtonText = cancelButtonText;
this.affirmativeButtonText = affirmativeButtonText;
bind();
}
public DialogBoxPresenter(Display display, String header, String dialogText) {
this.display = display;
this.header = header;
this.dialogText = dialogText;
this.cancelButtonText = "Cancel";
this.affirmativeButtonText = "OK";
bind();
}
private void bind() {
this.display.getDialogText().setText(dialogText);
this.display.getAffirmativeButton().setText(affirmativeButtonText);
this.display.getCancelButton().setText(cancelButtonText);
this.display.setHeader(header);
addClickHandlers();
}
private void addClickHandlers() {
this.display.getAffirmativeButton().addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
doAffirmative();
}
});
this.display.getCancelButton().addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
doCancel();
}
});
}
private void doAffirmative() {
//do something
display.hide();
}
private void doCancel() {
//do something
display.hide();
}
public void init() {
display.center();
}
#Override
public void go(HasWidgets container) {
container.clear();
container.add(display.asWidget());
}
}
and my view:
public class DialogBoxView extends DialogBox implements DialogBoxPresenter.Display {
private Label dialogText;
private Button affirmativeButton;
private Button cancelButton;
private VerticalPanel container;
public DialogBoxView() {
//init items
dialogText = new Label();
affirmativeButton = new Button();
cancelButton = new Button();
container = new VerticalPanel();
setGlassEnabled(true);
setAnimationEnabled(true);
setModal(false);
init();
}
private void init() {
//add items
container.add(dialogText);
HorizontalPanel hp = new HorizontalPanel();
hp.add(affirmativeButton);
hp.add(cancelButton);
container.add(hp);
this.add(container);
}
#Override
public Widget asWidget() {
return this;
}
#Override
public Label getDialogText() {
return dialogText;
}
#Override
public Button getAffirmativeButton() {
return affirmativeButton;
}
#Override
public Button getCancelButton() {
return cancelButton;
}
#Override
public void setHeader(String text) {
this.setText(text);
}
}

You're not going to be able to have it work in exactly the same way as Window.confirm(). The problem is that all of the javascript in a web page runs in a single thread. You'll notice that as long as a standard confirm dialog is open, the rest of the page goes dead. That's because the one javascript thread is blocked, waiting for confirm() to return. If you were to create a similar method for your dialog, as long as it was waiting for that method to return no user generated events would be processed and so your dialog wouldn't work. I hope that makes sense.
The best you will be able to do is similar to what the GWT library does for RPC calls -- the AsyncCallback interface. You could even reuse that interface yourself, or you might prefer to roll your own:
public interface DialogCallback {
void onOk();
void onCancel();
}
Instead of Window.confirm(String), your method signature will be more like Dialog.confirm(String,DialogCallback). Then your dialog just keeps a reference to the callback that's passed in, and where you have // do something in your code you make calls to onOk and onCancel.

Here is the code I have working if anyone is curious.
public class DialogBoxPresenter implements Presenter {
public interface Display {
Label getDialogText();
Button getAffirmativeButton();
Button getCancelButton();
Widget asWidget();
public void center();
public void hide();
public void setHeader(String text);
}
private Display display;
private String header;
private String dialogText;
private String cancelButtonText;
private String affirmativeButtonText;
private ConfirmDialogCallback confirmCallback;
private AlertDialogCallback alertCallback;
protected DialogBoxPresenter() {
}
public DialogBoxPresenter(Display display, String header, String dialogText, String cancelButtonText, String affirmativeButtonText, ConfirmDialogCallback callback) {
this.display = display;
this.header = header;
this.dialogText = dialogText;
this.cancelButtonText = cancelButtonText;
this.affirmativeButtonText = affirmativeButtonText;
this.confirmCallback = callback;
bind();
}
public DialogBoxPresenter(Display display, String header, String dialogText, String affirmativeButtonText, AlertDialogCallback callback) {
this.display = display;
this.header = header;
this.dialogText = dialogText;
this.affirmativeButtonText = affirmativeButtonText;
this.alertCallback = callback;
this.display.getCancelButton().setVisible(false);
bind();
}
private void bind() {
this.display.getDialogText().setText(dialogText);
this.display.getAffirmativeButton().setText(affirmativeButtonText);
this.display.getCancelButton().setText(cancelButtonText);
this.display.setHeader(header);
addClickHandlers();
}
private void addClickHandlers() {
this.display.getAffirmativeButton().addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
doAffirmative();
}
});
this.display.getCancelButton().addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
doCancel();
}
});
}
private void doAffirmative() {
if (confirmCallback != null) {
confirmCallback.onAffirmative();
} else {
alertCallback.onAffirmative();
}
display.hide();
}
private void doCancel() {
confirmCallback.onCancel();
display.hide();
}
public void init() {
display.center();
}
#Override
public void go(HasWidgets container) {
container.clear();
container.add(display.asWidget());
}
}
public class DialogBoxView extends DialogBox implements DialogBoxPresenter.Display {
private Label dialogText;
private Button affirmativeButton;
private Button cancelButton;
private VerticalPanel container;
public DialogBoxView() {
//init items
dialogText = new Label();
affirmativeButton = new Button();
cancelButton = new Button();
container = new VerticalPanel();
setGlassEnabled(true);
setAnimationEnabled(true);
setModal(false);
init();
}
private void init() {
//add items
container.add(dialogText);
HorizontalPanel hp = new HorizontalPanel();
hp.add(affirmativeButton);
hp.add(cancelButton);
container.add(hp);
this.add(container);
}
#Override
public Widget asWidget() {
return this;
}
#Override
public Label getDialogText() {
return dialogText;
}
#Override
public Button getAffirmativeButton() {
return affirmativeButton;
}
#Override
public Button getCancelButton() {
return cancelButton;
}
#Override
public void setHeader(String text) {
this.setText(text);
}
}
public class DialogBoxWidget implements LensooConstant {
private static DialogBoxView view = null;
private static DialogBoxPresenter presenter = null;
public static DialogBoxPresenter confirm(String header, String dialogText, String cancelButtonText, String affirmativeButtonText, ConfirmDialogCallback callback) {
view = new DialogBoxView();
presenter = new DialogBoxPresenter(view, header, dialogText, cancelButtonText, affirmativeButtonText, callback);
presenter.init();
return presenter;
}
public static DialogBoxPresenter confirm(String header, String dialogText, ConfirmDialogCallback callback) {
return DialogBoxWidget.confirm(header, dialogText, constants.cancelButton(), constants.okButton(), callback);
}
public static DialogBoxPresenter alert(String header, String dialogText, String affirmativeButtonText, AlertDialogCallback callback) {
view = new DialogBoxView();
presenter = new DialogBoxPresenter(view, header, dialogText, affirmativeButtonText, callback);
presenter.init();
return presenter;
}
public static DialogBoxPresenter alert(String header, String dialogText, AlertDialogCallback callback) {
return DialogBoxWidget.alert(header, dialogText, constants.okButton(), callback);
}
protected DialogBoxWidget() {
}
}
public interface AlertDialogCallback {
void onAffirmative();
}
public interface ConfirmDialogCallback {
void onAffirmative();
void onCancel();
}

Related

problem with Nested recyclerview and LiveData observe

I have nested RecyclerView and two LiveData. one is parentList and another one is childList
I managed to use LiveData for ParentAdapter but when I try LiveData for ChildAdapter nothing showen in childAdapter. ParentAdapter is working.
Can someone help me?
Thanks?
this method is in MainActivity.class
private void sendAllDataToAdapter(){
CashFlowViewModel viewModel = ViewModelProviders.of(this).get(CashFlowViewModel.class);
viewModel.cashGroupByDate().observe(this, new Observer<List<CashFlow>>() {
#Override
public void onChanged(List<CashFlow> cashFlows) {
adapter.submitList(cashFlows);
}
});
adapter = new MainAdapter(this, this);
recyclerView.setAdapter(adapter);
}
This is ParentAdapter
public class MainAdapter extends ListAdapter<CashFlow, MainAdapter.MainViewHolder>{
Context context;
List<CashFlow> cashFlowList = new ArrayList<>();
List<CashFlow> cashFlowListChild = new ArrayList<>();
CashflowRepository repository;
CashFlowViewModel viewModel;
LifecycleOwner lifecycleOwner;
public MainAdapter(Context context, LifecycleOwner lifecycleOwner) {
super(diffCallback);
this.context = context;
this.cashFlowList = cashFlowList;
this.cashFlowListChild = cashFlowListChild;
this.repository = repository;
this.lifecycleOwner = lifecycleOwner;
viewModel = ViewModelProviders.of((MainActivity) context).get(CashFlowViewModel.class);
}
private static final DiffUtil.ItemCallback<CashFlow> diffCallback = new DiffUtil.ItemCallback<CashFlow>() {
#Override
public boolean areItemsTheSame(#NonNull CashFlow oldItem, #NonNull CashFlow newItem) {
return oldItem.getId() == newItem.getId();
}
#Override
public boolean areContentsTheSame(#NonNull CashFlow oldItem, #NonNull CashFlow newItem) {
return oldItem.getAdded_date().equals(newItem.getAdded_date())
&& oldItem.getTitle().equals(newItem.getTitle())
&& oldItem.getBody().equals(newItem.getBody());
}
};
#NonNull
#Override
public MainViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.main_adapter, parent, false);
return new MainViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull MainViewHolder holder, int position) {
holder.tvDate.setText(getItem(position).getAdded_date());
holder.tvIncome.setText(String.valueOf(getItem(position).getIncome()));
holder.tvExpense.setText(String.valueOf(getItem(position).getExpense()));
ChildAdapter adapter = new ChildAdapter(context);
holder.rvChild.setAdapter(adapter);
viewModel.cashGroupByDate().observe(lifecycleOwner, new Observer<List<CashFlow>>() {
#Override
public void onChanged(List<CashFlow> cashFlows) {
adapter.submitList(cashFlows);
}
});
Log.d("Child", getItem(position).getAdded_date()+"");
}
public class MainViewHolder extends RecyclerView.ViewHolder {
TextView tvDate, tvIncome, tvExpense;
RecyclerView rvChild;
public MainViewHolder(#NonNull View itemView) {
super(itemView);
tvDate = itemView.findViewById(R.id.main_adapter_date);
tvIncome = itemView.findViewById(R.id.main_adapter_income);
tvExpense = itemView.findViewById(R.id.main_adapter_expense);
rvChild = itemView.findViewById(R.id.child_recyclerview);
}
}
This is ChildAdapter
public class ChildAdapter extends ListAdapter<CashFlow, ChildAdapter.ChildViewHolder> {
Context context;
public ChildAdapter(Context context) {
super(diffCallback);
this.context = context;
}
private static final DiffUtil.ItemCallback<CashFlow> diffCallback = new DiffUtil.ItemCallback<CashFlow>() {
#Override
public boolean areItemsTheSame(#NonNull CashFlow oldItem, #NonNull CashFlow newItem) {
return oldItem.getId() == newItem.getId();
}
#Override
public boolean areContentsTheSame(#NonNull CashFlow oldItem, #NonNull CashFlow newItem) {
return oldItem.getAdded_date().equals(newItem.getAdded_date())
&& oldItem.getBody().equals(newItem.getBody())
&& oldItem.getTitle().equals(newItem.getTitle())
&& oldItem.getExpense() == newItem.getExpense()
&& oldItem.getIncome() == newItem.getIncome()
&& oldItem.getType().equals(newItem.getType());
}
};
#NonNull
#Override
public ChildViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.child_adapter, parent, false);
return new ChildViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ChildViewHolder holder, int position) {
holder.imageView.setImageResource(getItem(position).getImage_id());
holder.tvTitle.setText(getItem(position).getTitle());
if (getItem(position).getType().equals(BaseActivity.INCOME)){
holder.tvSum.setText(String.valueOf(getItem(position).getIncome()));
}
else if (getItem(position).getType().equals(BaseActivity.EXPENSE)){
holder.tvSum.setText(String.valueOf(getItem(position).getExpense()));
}
}
public class ChildViewHolder extends RecyclerView.ViewHolder {
ImageView imageView;
TextView tvTitle, tvSum;
public ChildViewHolder(#NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.child_adapter_image);
tvTitle = itemView.findViewById(R.id.child_adapter_title);
tvSum = itemView.findViewById(R.id.child_adapter_sum);
}
}
}
This is my ViewModel.class
public class CashFlowViewModel extends AndroidViewModel {
private CashflowRepository repository;
public CashFlowViewModel(#NonNull Application application) {
super(application);
repository = new CashflowRepository(application);
}
public void insert(CashFlow cashFlow){
repository.insert(cashFlow);
}
public void update(CashFlow cashFlow){
repository.update(cashFlow);
}
public void delete(CashFlow cashFlow){
repository.delete(cashFlow);
}
public LiveData<List<CashFlow>> cashGroupByDate(){
return repository.getCashGroupByDate();
}
public LiveData<List<CashFlow>> cashByDate(String addedDate){
return repository.getCashByDate(addedDate);
}
public void insertCategory(Category category){
repository.insertCategory(category);
}
public void updateCategory(Category category){
repository.updateCategory(category);
}
public void deleteCategory(Category category){
repository.deleteCategory(category);
}
public List<Category> allCategories(String type){
return repository.getAllCategories(type);
}

Android ListView - ExpandableHeightListView add a limit of 10 records per page

My listview is found inside a ScrollView. The ListView was extended by ExpandableHeightListView class. When, 20 row items are loaded, the image library freeze the UI until all images are loaded. Then, user can scroll and select an item. To handle this issue, I tried to load every 10 records in the arraylist. Can i do it directly in the ExpandableHeightListView , if so how ?
public class ExpandableHeightListView extends ListView {
boolean expanded = false;
public ExpandableHeightListView(Context context) {
super(context);
}
public ExpandableHeightListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExpandableHeightListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public boolean isExpanded() {
return expanded;
}
#Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (isExpanded()) {
// int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST);
//super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// Calculate entire height by providing a very large height hint.
// MEASURED_SIZE_MASK represents the largest height possible.
//int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST);
//super.onMeasure(widthMeasureSpec, expandSpec);
// Calculate entire height by providing a very large height hint.
// But do not use the highest 2 bits of this integer; those are
// reserved for the MeasureSpec mode.
int expandSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public void setExpanded(boolean expanded) {
this.expanded = expanded;
}
}
The ListView adapter is as follows:
public class ResultatRechercheAdapter extends BaseAdapter {
public static final String IMAGE_CACHE_DIR = "images";
public static final String EXTRA_IMAGE = "extra_image";
public List<MRechercheResult> items;
public final OnClickListener itemButtonClickListener;
public final Context context;
public Activity activity;
public String agenda_date;
public String agenda_from;
public String agenda_to;
public ViewHolder holder;
public int agenda_from_hour=-1;
public int agenda_from_minute=-1;
public int agenda_to_hour;
public int agenda_to_minute;
public String from_am_pm;
public String to_am_pm;
private String monday;
private String tuesday;
private String wednesday;
private String thursday;
private String friday;
private String saturday;
private String sunday;
public ImageFetcher mImageFetcher;
public ResultatRechercheAdapter(Activity activity,Context context, List<MRechercheResult> resultat, OnClickListener itemButtonClickListener) {
this.activity = activity;
this.context = context;
this.items = resultat;
this.itemButtonClickListener = itemButtonClickListener;
//this.mImageFetcher = mImageFetcher;
try {
monday= activity.getResources().getString(R.string.monday);
tuesday= activity.getResources().getString(R.string.tuesday);
wednesday= activity.getResources().getString(R.string.wednesday);
thursday= activity.getResources().getString(R.string.thursday);
friday= activity.getResources().getString(R.string.friday);
saturday= activity.getResources().getString(R.string.saturday);
sunday= activity.getResources().getString(R.string.sunday);
} catch(Exception ex){}
}
#Override
public int getCount() {
return items.size();//items.size()
}
#Override
public MRechercheResult getItem(int position) {
return items.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public int getViewTypeCount() {
return 1;//items.size()
}
#Override
public int getItemViewType(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.list_item_card, null);
holder = new ViewHolder();
holder.txRowTitle = (TextView) convertView.findViewById(R.id.txRowTitle);
holder.imThumbnail= (RecyclingImageView) convertView.findViewById(R.id.imThumbnail);
holder.itemButton1 = (Button) convertView.findViewById(R.id.list_item_card_close);
holder.itemButton2 = (Button) convertView.findViewById(R.id.list_item_card_button_2);
holder.imCircleLundi= (ImageView) convertView.findViewById(R.id.imCircleLundi);
holder.imCircleMardi= (ImageView) convertView.findViewById(R.id.imCircleMardi);
holder.imCircleMercredi= (ImageView) convertView.findViewById(R.id.imCircleMercredi);
holder.imCircleJeudi= (ImageView) convertView.findViewById(R.id.imCircleJeudi);
holder.imCircleVendredi= (ImageView) convertView.findViewById(R.id.imCircleVendredi);
holder.imCircleSamedi= (ImageView) convertView.findViewById(R.id.imCircleSamedi);
holder.imCircleDimanche= (ImageView) convertView.findViewById(R.id.imCircleDimanche);
holder.rlListRecherche= (RelativeLayout) convertView.findViewById(R.id.rlListRecherche);
holder.llImage= (LinearLayout) convertView.findViewById(R.id.llImage);
holder.rlListClose= (RelativeLayout) convertView.findViewById(R.id.rlListClose);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
boolean no_record = items.get(position).no_record;
if (no_record){ // listview is empty
holder.llImage.setVisibility(View.GONE);
holder.rlListClose.setVisibility(View.GONE);
holder.rlListRecherche.setVisibility(View.VISIBLE);
} else {
Utils.shortWeek(activity, convertView);
holder.llImage.setVisibility(View.VISIBLE);
holder.rlListClose.setVisibility(View.VISIBLE);
holder.rlListRecherche.setVisibility(View.GONE);
if (itemButtonClickListener != null) {
//holder.itemButton1.setOnClickListener(itemButtonClickListener);
holder.itemButton1.setVisibility(View.GONE);
holder.itemButton2.setOnClickListener(itemButtonClickListener);
}
final String image_url = items.get(position).profil_photo.toString().replace("\\","").replace("hepigo", "helpigo");
String item_title = items.get(position).profil.toString();
if (item_title.equalsIgnoreCase("Julien Perez")){
if (true){
String display_pos = String.valueOf(position);
System.out.println(display_pos);
}
}
//searchRequest(position,image_url);
//if (!TextUtils.isEmpty(image_url))
// mImageFetcher.loadImage(image_url, holder.imThumbnail);
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
if (TextUtils.isEmpty(items.get(position).profil_photo)) {
//no url
} else {
Picasso.with(activity)
.load(image_url)
.error(android.R.drawable.stat_notify_error)
.transform(transformation)
.placeholder(R.drawable.loading_image_placeholder)
.config(Config.RGB_565)
.into(holder.imThumbnail);
}
}
});
//if (!TextUtils.isEmpty(image_url))
// new DownloadImageTask(holder.imThumbnail).execute(image_url);
holder.txRowTitle.setText(item_title);
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
List<Agenda> agenda = items.get(position).agenda;
Utils.displayAgenda(agenda,holder.imCircleLundi,monday);
Utils.displayAgenda(agenda,holder.imCircleMardi,tuesday);
Utils.displayAgenda(agenda,holder.imCircleMercredi,wednesday);
Utils.displayAgenda(agenda,holder.imCircleJeudi,thursday);
Utils.displayAgenda(agenda,holder.imCircleVendredi,friday);
Utils.displayAgenda(agenda,holder.imCircleSamedi,saturday);
Utils.displayAgenda(agenda,holder.imCircleDimanche,sunday);
}
});
}
return convertView;
}
public static class ViewHolder {
public RelativeLayout rlListClose;
public LinearLayout llImage;
public RelativeLayout rlListRecherche;
public ImageView imCircleSamedi;
public ImageView imCircleDimanche;
public ImageView imCircleVendredi;
public ImageView imCircleJeudi;
public ImageView imCircleMercredi;
public ImageView imCircleMardi;
public ImageView imCircleLundi;
public RecyclingImageView imThumbnail;
public TextView txRowTitle;
public Button itemButton1;
public Button itemButton2;
}

checkbox in pageablelistview in wicket

private ArrayList<MFRList> list;
private ArrayList<STUList> list1 = new ArrayList<STUList>();
public ResultPage(PageParameters params) throws APIException {
Form form = new Form("form");
PageableListView view = new PageableListView("view", list, 10) {
#Override
public void onConfigure() {
super.onConfigure();
setVisible(list.size() > 0);
}
#Override
protected void populateItem(ListItem item) {
final StuList stu= (StuList) item.getModelObject();
item.add(new CheckBox("check", item.getModel()));
item.add(new Label("name", stu.getName()));
item.add(new Label("num", stu.getNumber()));
item.add(new Label("age", stu.getAge()));
item.add(new Label("sex", stu.getSex()));
}
};
Button backtosearchbutton = new Button("backtosearchbutton") {
#Override
public void onSubmit() {
setResponsePage(SearchPage.class);
}
}.setDefaultFormProcessing(false);
Button groupcheckbutton = new Button("groupcheckbutton") {
#Override
public void onSubmit() {
}
}.setDefaultFormProcessing(false);
Button groupuncheckbutton = new Button("groupuncheckbutton") {
#Override
public void onSubmit() {
}
}.setDefaultFormProcessing(false);
Button submitselectionbutton = new Button("submitselectionbutton") {
#Override
public void onSubmit() {
}
}.setDefaultFormProcessing(true);
form.add(view);
form.add(backtosearchbutton);
form.add(submitselectionbutton);
form.add(groupuncheckbutton);
form.add(groupcheckbutton);
add(form);
add(new CustomPagingNavigator("navigator", view));
how are the selected records stored and how can i use it. i understand that on form submission these records are submitted but i am not clear on how and where.
and my pojo is
public class MFRList implements Serializable {
private String name;
private String num;
private String age;
private String sex;
private Boolean selected = Boolean.FALSE;
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
public String getnum() {
return num;
}
public void setnum(String num) {
this.num = num;
}
public String getAge() {
return age;
}
public void setsex(String sex) {
this.sex= sex;
}
public String getsex() {
return sex;
}
public void setage(String age) {
this.age = age;
}
public Boolean getSelected() {
return selected;
}
public void setSelected(Boolean selected) {
this.selected = selected;
}
}
where is the selected row saved and how can i retrieve and use it.
Thanks in Advance
You should use a CheckGroup with Checks instead:
public ResultPage(PageParameters params) throws APIException {
Form form = new Form("form");
CheckGroup selection = new CheckGroup("selection", new ArrayList());
selection.setRenderBodyOnly(false);
form.add(selection);
PageableListView view = new PageableListView("view", list, 10) {
#Override
public void onConfigure() {
super.onConfigure();
setVisible(list.size() > 0);
}
#Override
protected void populateItem(ListItem item) {
final StuList stu= (StuList) item.getModelObject();
item.add(new Check("check", item.getModel()));
item.add(new Label("name", stu.getName()));
item.add(new Label("num", stu.getNumber()));
item.add(new Label("age", stu.getAge()));
item.add(new Label("sex", stu.getSex()));
}
};
selection.add(view);
This way the arrayList passed to the CheckGroup constructor will always contain the selected objects.
I got what i was trying to acheive but i am not su7re if it is optimal solution.
I created my own Model and added the object to a list when check box is selected.
class SelectedCheckBoxModel extends AbstractCheckBoxModel {
private final STUList info;
private ArrayList<STUList> list1;
public SelectedCheckBoxModel(STUList info, ArrayList<STUList> list1) {
super();
this.info = info;
this.list1 = list1;
}
#Override
public boolean isSelected() {
// TODO Auto-generated method stub
return list1.contains(info);
}
#Override
public void select() {
// TODO Auto-generated method stub
list1.add(info);
}
#Override
public void unselect() {
// TODO Auto-generated method stub
list1.remove(info);
}
and i called it in my listview
check = new CheckBox("check", new SelectedCheckBoxModel(stu, list1));
item.add(check);
if this is not optimal please suggest
Thank You

How to use same servlet for RPC and upload File in GWT.

i created a web application where i have to use fileUpload.
i have to send the file and their properties to server . For sending a file i used FormPanel and for properties i used RPC .
public void onModuleLoad() {
final FileServiceEndPoint serviceEndPoint = new FileServiceEndPoint();
new AddDocument();
Button b = new Button("addDocument");
b.addClickHandler(new ClickHandler() {
private Map<String, String> docProperty;
public void onClick(ClickEvent event) {
docProperty =getProperties();
AsyncCallback<String> callback = new AsyncCallback<String>() {
public void onSuccess(String result) {
System.out.println("he ha" +result);
}
public void onFailure(Throwable caught) {
}
};
serviceEndPoint.uploadAttachement(docProperty, callback);
}
});
RootPanel.get().add(b);
}
this new AddDocument(); contains code for uploading a file (formPanel code)
private FormPanel getFormPanel() {
if (uploadForm == null) {
uploadForm = new FormPanel();
uploadForm.setAction(GWT.getHostPageBaseURL() +"TestUploadFileServlet");
uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
uploadForm.setMethod(FormPanel.METHOD_POST);
uploadForm.setWidget(getFileUpload());
System.out.println(GWT.getHostPageBaseURL() +"TestUploadFileServlet");
uploadForm.addFormHandler(new FormHandler() {
public void onSubmitComplete(FormSubmitCompleteEvent event) {
AddDocument.this.hide(true);
}
public void onSubmit(FormSubmitEvent event) {
}
});
}
return uploadForm;
}
private Button getAddButton() {
if (addButton == null) {
addButton = new Button("ADD");
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
uploadForm.submit();
}
});
addButton.setText("Add");
}
Interface is created for Sending property.
EndPoints:
public class FileServiceEndPoint implements FileServiceAsync{
FileServiceAsync service = (FileServiceAsync)GWT.create(FileService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) service;
public FileServiceEndPoint() {
endpoint.setServiceEntryPoint(GWT.getHostPageBaseURL() + “TestUploadFileServlet”);
}
public void uploadAttachement(Map docProperty,
AsyncCallback callback) {
service.uploadAttachement(docProperty, callback);
}
}
On Server:
public class FileUploadImpl extends RemoteServiceServlet implements FileService {
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(FileUploadImpl.class
.getName());
String a;
protected void service(final HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException {
a=”5″;
System.out.println(“ServletWorking Fine “);
}
public String uploadAttachement(Map docProperty) {
// TODO Auto-generated method stub
return “Checked”;
}
}
When I debug formPanel.submit : the debugger goes in Server and print ServletWorking Fine(this is perfect)
and when i debug the addProperties button it goes to server and print ServletWorking Fine. but It should not go in service method.
the debugger should go in UploadAttachement.
Plz tell how to pass hashMap using same servlet.

Does anyone have a working examples of ActionCells working within a CompositeCell?

I tried following the example, http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellTree , and added two ActionCells inside of the CompositeCell with no luck. The ActionCell's onBrowserEvent() does not get triggered.
This simple example works for me. Since you didn't provide any code or further explanation on what exactly you're trying to achieve, I have no idea whether my example is of any help or not.
public void onModuleLoad() {
CellTable<Person> table = new CellTable<Starter.Person>();
List<HasCell<Person, ?>> cells = new LinkedList<HasCell<Person, ?>>();
cells.add(new HasCellImpl("first name", new Delegate<Person>() {
#Override
public void execute(Person object) {
Window.alert(object.getFirstName());
}
}));
cells.add(new HasCellImpl("last name", new Delegate<Starter.Person>() {
#Override
public void execute(Person object) {
Window.alert(object.getLastName());
}
}));
CompositeCell<Person> cell = new CompositeCell<Person>(cells);
table.addColumn(new TextColumn<Starter.Person>() {
#Override
public String getValue(Person object) {
return object.getFirstName() + " " + object.getLastName();
}
}, "name");
table.addColumn(new Column<Person, Person>(cell) {
#Override
public Person getValue(Person object) {
return object;
}
}, "composite");
LinkedList<Person> data = new LinkedList<Starter.Person>();
data.add(new Person("Amy", "Reed"));
data.add(new Person("Tim", "Gardner"));
table.setRowData(data);
RootPanel.get().add(table);
}
private class HasCellImpl implements HasCell<Person, Person> {
private ActionCell<Person> fCell;
public HasCellImpl(String text, Delegate<Person> delegate) {
fCell = new ActionCell<Person>(text, delegate);
}
#Override
public Cell<Person> getCell() {
return fCell;
}
#Override
public FieldUpdater<Person, Person> getFieldUpdater() {
return null;
}
#Override
public Person getValue(Person object) {
return object;
}
}
private class Person {
private String fFirstName;
private String fLastName;
public Person(String first, String last) {
fFirstName = first;
fLastName = last;
}
public String getFirstName() {
return fFirstName;
}
public String getLastName() {
return fLastName;
}
}