Wicket AJAX update form TextField value from another field
Hi. Hopefully I can explain this scenario OK - I'll try to keep it simple. On a form, I have a couple of TextFields - SalePrice and DiscountAmount. After the user enters SalePrice, I need a way to allow the user to enter the DiscountAmount as either a flat rate or as a percentage of the SalePrice. For example, if entered SalePrice is 1000, the user could enter a flat DiscountAmount of 200.00. Or they could enter 20%. I'd like the option to do either since SalePrice might be 8,745 and the discount 2.75% or something (so hard to just calculat the true cash amount). Or it might just really be a flat £200 in which case hard to calculate the %. In a traditional app where I'm writing the JavaScript, I can think of various ways to do this involving extra fields for flatrate and/or % - then updating the real DiscountAmount field when the dummy fields change. But I'm trying to work out an elegant way with Wicket/AJAX - without too much success so far. Any suggestions - or links to similar examples? Ideally, the fewer extra dummy fields the better. Thanks. -- View this message in context: http://www.nabble.com/Wicket-AJAX-update-form-TextField-value-from-another-field-tp20117258p20117258.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Wicket AJAX update form TextField value from another field
Maybe I should have stated I have tried something like this. I have data entry TextFields for: SalePrice DiscountAmount then add another for: DiscountPercentage When I enter an amount into DiscountAmount I need DiscountPercentage to get calculated and update on the form. And it should also work the other way around - enter DiscountPercentage and DiscountAmount gets updated. But DiscountPercentage does not have a setter in my model - just a getter (it's calculated for viewing only and does not get persisted anywhere). So I get errors when Wicket attempts to update the model. And if I enter an an amount in DiscountPercentage and attempt to update the value for DiscountAmount then I can't update this either since I don't want to persist the form until all the other fields are entered. I am using the same form for creating a new record and editing an existing one, so when doing a new record I don't have mandatory fields filled when I'm entering the Discount stuff. Steve steve222 wrote: Hi. Hopefully I can explain this scenario OK - I'll try to keep it simple. On a form, I have a couple of TextFields - SalePrice and DiscountAmount. After the user enters SalePrice, I need a way to allow the user to enter the DiscountAmount as either a flat rate or as a percentage of the SalePrice. For example, if entered SalePrice is 1000, the user could enter a flat DiscountAmount of 200.00. Or they could enter 20%. I'd like the option to do either since SalePrice might be 8,745 and the discount 2.75% or something (so hard to just calculat the true cash amount). Or it might just really be a flat £200 in which case hard to calculate the %. In a traditional app where I'm writing the JavaScript, I can think of various ways to do this involving extra fields for flatrate and/or % - then updating the real DiscountAmount field when the dummy fields change. But I'm trying to work out an elegant way with Wicket/AJAX - without too much success so far. Any suggestions - or links to similar examples? Ideally, the fewer extra dummy fields the better. Thanks. -- View this message in context: http://www.nabble.com/Wicket-AJAX-update-form-TextField-value-from-another-field-tp20117258p20119555.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Wicket AJAX update form TextField value from another field
Many thanks for the detailed answer. I don't think the single field AbsoluteOrPercentage idea will work for me without a lot of other changes. I use the same form for editing a record as creating a new one. So I actually need to show both the AbsoluteDiscount and PercentageDiscount on the form at the same time - user enters % during initial entry, he needs to see % on later edit, etc. Both fields need to be editable, with the one that doesn't get edited being calculated. But thanks for the idea and the detail on how to implement this. I've been attempting to do it with separate fields for AbsoluteDiscount and PercentageDiscount - but it does not work for me. My model object used in the form does not have setters for the calculated field PercentageDiscount - just a getter to display the calculated % value. So I can't update this. And it seems I can't update the fields anyway since the need to be final jWeekend wrote: Steve, If you prefer not to take the easy option and add a couple of radio buttons to let the user select currency or percentage input, that could also control a couple of labels (or a border) that shows, in a locale specific way, the currency symbol or the percentage sign you could ... create an AbsoluteOrPercentage class an instance of which will back the model of your DiscountAmount field. Make a validator that checks that the last character entered looks like an int or a '%' and that the other characters represent a number, and, if required, put your validation messages in the appropriate place. Add this validator to your DiscountAmount text field. Make an appropriate converter (implement IConverter - very simple logic required for both methods) and override getConverter on your text field to return it for your AbsoluteOrPercentage class. If this text field will be useful elsewhere, make a (top level) subclass of TextField - AbsoluteOrPercentageTextField for instance that does all of the above. It is not clear from your post what you want updated, but let's assume you have three fields, one for each of SalePrice, DiscountAmount and ActualAmount (price with discount applied) and you want the latter updated. Add an AjaxFormComponentUpdatingBehavior (probably onblur) to both the input fields. In the onUpdate methods of each update the (dynamic) model object backing the ActualAmount field (probably rendered by a label since it is not meant to be edited by the user). Don't forget to add your actualAmountTextField component to the AjaxRequestTarget in both your onUpdate methods and also to request a markup id for actualAmountTextField - actualAmountField.setMarkupId(true) - where you build up the container. If this lot is likely to be useful elsewhere, wrap all three fields (and probably all the rest of the stuff described above) in a Panel so you can just drop it in a div anywhere you like later on. Does that do it? Regards - Cemal http://www.jWeekend.co.uk http://jWeekend.co.uk steve222 wrote: Hi. Hopefully I can explain this scenario OK - I'll try to keep it simple. On a form, I have a couple of TextFields - SalePrice and DiscountAmount. After the user enters SalePrice, I need a way to allow the user to enter the DiscountAmount as either a flat rate or as a percentage of the SalePrice. For example, if entered SalePrice is 1000, the user could enter a flat DiscountAmount of 200.00. Or they could enter 20%. I'd like the option to do either since SalePrice might be 8,745 and the discount 2.75% or something (so hard to just calculat the true cash amount). Or it might just really be a flat £200 in which case hard to calculate the %. In a traditional app where I'm writing the JavaScript, I can think of various ways to do this involving extra fields for flatrate and/or % - then updating the real DiscountAmount field when the dummy fields change. But I'm trying to work out an elegant way with Wicket/AJAX - without too much success so far. Any suggestions - or links to similar examples? Ideally, the fewer extra dummy fields the better. Thanks. -- View this message in context: http://www.nabble.com/Wicket-AJAX-update-form-TextField-value-from-another-field-tp20117258p20120528.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Wicket AJAX update form TextField value from another field
Ooops - my error. I need to do something like: pcntDiscount.setModel(new Model(amount.getModelObject().toString())); Then the AjaxFormComponentUpdatingBehavior works as expected. Steve steve222 wrote: Many thanks for the detailed answer. I don't think the single field AbsoluteOrPercentage idea will work for me without a lot of other changes. I use the same form for editing a record as creating a new one. So I actually need to show both the AbsoluteDiscount and PercentageDiscount on the form at the same time - user enters % during initial entry, he needs to see % on later edit, etc. Both fields need to be editable, with the one that doesn't get edited being calculated. But thanks for the idea and the detail on how to implement this. I've been attempting to do it with separate fields for AbsoluteDiscount and PercentageDiscount - but it does not work for me. My model object used in the form does not have setters for the calculated field PercentageDiscount - just a getter to display the calculated % value. So I can't update this with AjaxFormComponentUpdatingBehavior. And it seems I can't update the fields using AjaxEventBehavior, eg: final RequireTextfield amount = new RequiredTextfield(amount, Double.class); amount.add(DoubleMinimumValidator.minimum(1)); amount.setOutputMarkupId(true); container.add(amount); amount.add(new AjaxEventBehavior(onblur) { protected void onEvent(AjaxRequestTarget target) { // this will always be null on new data entry, and old value on edit pcntDiscount.setModelObject(amount.getModelObject().toString()); target.addComponent(pcntDiscount); } }); jWeekend wrote: Steve, If you prefer not to take the easy option and add a couple of radio buttons to let the user select currency or percentage input, that could also control a couple of labels (or a border) that shows, in a locale specific way, the currency symbol or the percentage sign you could ... create an AbsoluteOrPercentage class an instance of which will back the model of your DiscountAmount field. Make a validator that checks that the last character entered looks like an int or a '%' and that the other characters represent a number, and, if required, put your validation messages in the appropriate place. Add this validator to your DiscountAmount text field. Make an appropriate converter (implement IConverter - very simple logic required for both methods) and override getConverter on your text field to return it for your AbsoluteOrPercentage class. If this text field will be useful elsewhere, make a (top level) subclass of TextField - AbsoluteOrPercentageTextField for instance that does all of the above. It is not clear from your post what you want updated, but let's assume you have three fields, one for each of SalePrice, DiscountAmount and ActualAmount (price with discount applied) and you want the latter updated. Add an AjaxFormComponentUpdatingBehavior (probably onblur) to both the input fields. In the onUpdate methods of each update the (dynamic) model object backing the ActualAmount field (probably rendered by a label since it is not meant to be edited by the user). Don't forget to add your actualAmountTextField component to the AjaxRequestTarget in both your onUpdate methods and also to request a markup id for actualAmountTextField - actualAmountField.setMarkupId(true) - where you build up the container. If this lot is likely to be useful elsewhere, wrap all three fields (and probably all the rest of the stuff described above) in a Panel so you can just drop it in a div anywhere you like later on. Does that do it? Regards - Cemal http://www.jWeekend.co.uk http://jWeekend.co.uk steve222 wrote: Hi. Hopefully I can explain this scenario OK - I'll try to keep it simple. On a form, I have a couple of TextFields - SalePrice and DiscountAmount. After the user enters SalePrice, I need a way to allow the user to enter the DiscountAmount as either a flat rate or as a percentage of the SalePrice. For example, if entered SalePrice is 1000, the user could enter a flat DiscountAmount of 200.00. Or they could enter 20%. I'd like the option to do either since SalePrice might be 8,745 and the discount 2.75% or something (so hard to just calculat the true cash amount). Or it might just really be a flat £200 in which case hard to calculate the %. In a traditional app where I'm writing the JavaScript, I can think of various ways to do this involving extra fields for flatrate and/or % - then updating the real DiscountAmount field when the dummy fields change. But I'm trying to work out an elegant way with Wicket/AJAX - without too much success so far. Any suggestions - or links to similar examples? Ideally, the fewer extra dummy fields the better. Thanks. -- View
Re: Wicket AJAX update form TextField value from another field
But not for the field where the model does not have a setter (hibernate POJO - and no field in the database, just a formula). Fairly obvious why that's not going to work for an update - but I can't think of a solution on how to change the calculated value just to show it on the form. Steve steve222 wrote: Ooops - my error. I need to do something like: pcntDiscount.setModel(new Model(amount.getModelObject().toString())); Then the AjaxFormComponentUpdatingBehavior works as expected. Steve steve222 wrote: Many thanks for the detailed answer. I don't think the single field AbsoluteOrPercentage idea will work for me without a lot of other changes. I use the same form for editing a record as creating a new one. So I actually need to show both the AbsoluteDiscount and PercentageDiscount on the form at the same time - user enters % during initial entry, he needs to see % on later edit, etc. Both fields need to be editable, with the one that doesn't get edited being calculated. But thanks for the idea and the detail on how to implement this. I've been attempting to do it with separate fields for AbsoluteDiscount and PercentageDiscount - but it does not work for me. My model object used in the form does not have setters for the calculated field PercentageDiscount - just a getter to display the calculated % value. So I can't update this with AjaxFormComponentUpdatingBehavior. And it seems I can't update the fields using AjaxEventBehavior, eg: final RequireTextfield amount = new RequiredTextfield(amount, Double.class); amount.add(DoubleMinimumValidator.minimum(1)); amount.setOutputMarkupId(true); container.add(amount); amount.add(new AjaxEventBehavior(onblur) { protected void onEvent(AjaxRequestTarget target) { // this will always be null on new data entry, and old value on edit pcntDiscount.setModelObject(amount.getModelObject().toString()); target.addComponent(pcntDiscount); } }); jWeekend wrote: Steve, If you prefer not to take the easy option and add a couple of radio buttons to let the user select currency or percentage input, that could also control a couple of labels (or a border) that shows, in a locale specific way, the currency symbol or the percentage sign you could ... create an AbsoluteOrPercentage class an instance of which will back the model of your DiscountAmount field. Make a validator that checks that the last character entered looks like an int or a '%' and that the other characters represent a number, and, if required, put your validation messages in the appropriate place. Add this validator to your DiscountAmount text field. Make an appropriate converter (implement IConverter - very simple logic required for both methods) and override getConverter on your text field to return it for your AbsoluteOrPercentage class. If this text field will be useful elsewhere, make a (top level) subclass of TextField - AbsoluteOrPercentageTextField for instance that does all of the above. It is not clear from your post what you want updated, but let's assume you have three fields, one for each of SalePrice, DiscountAmount and ActualAmount (price with discount applied) and you want the latter updated. Add an AjaxFormComponentUpdatingBehavior (probably onblur) to both the input fields. In the onUpdate methods of each update the (dynamic) model object backing the ActualAmount field (probably rendered by a label since it is not meant to be edited by the user). Don't forget to add your actualAmountTextField component to the AjaxRequestTarget in both your onUpdate methods and also to request a markup id for actualAmountTextField - actualAmountField.setMarkupId(true) - where you build up the container. If this lot is likely to be useful elsewhere, wrap all three fields (and probably all the rest of the stuff described above) in a Panel so you can just drop it in a div anywhere you like later on. Does that do it? Regards - Cemal http://www.jWeekend.co.uk http://jWeekend.co.uk steve222 wrote: Hi. Hopefully I can explain this scenario OK - I'll try to keep it simple. On a form, I have a couple of TextFields - SalePrice and DiscountAmount. After the user enters SalePrice, I need a way to allow the user to enter the DiscountAmount as either a flat rate or as a percentage of the SalePrice. For example, if entered SalePrice is 1000, the user could enter a flat DiscountAmount of 200.00. Or they could enter 20%. I'd like the option to do either since SalePrice might be 8,745 and the discount 2.75% or something (so hard to just calculat the true cash amount). Or it might just really be a flat £200 in which case hard to calculate the %. In a traditional app where I'm writing the JavaScript, I can think of various ways to do this involving extra fields
Re: Wicket AJAX update form TextField value from another field
Thanks. I now have this fully working now with a customised model class containing a setter to store the calculated field if upated from the Wicket form. Will look at FormComponentPanel - thanks for the suggestion. Steve Timo Rantalaiho wrote: On Wed, 22 Oct 2008, steve222 wrote: But DiscountPercentage does not have a setter in my model - just a getter (it's calculated for viewing only and does not get persisted anywhere). So I get errors when Wicket attempts to update the model. I would have done this by using customised models, but a while back in a similar discussion on this list Igor suggested using FormComponentPanel. You can probably solve your situation with it. Best wishes, Timo -- Timo Rantalaiho Reaktor Innovations OyURL: http://www.ri.fi/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Wicket-AJAX-update-form-TextField-value-from-another-field-tp20117258p20124799.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Easiest way to add column totals to a table?
Thanks. Will try this. Steve jwcarman wrote: Sorry, I mean addBottomToolbar() On Tue, Oct 14, 2008 at 1:25 PM, James Carman [EMAIL PROTECTED] wrote: Have you tried creating a toolbar? You could call setBottomToolbar() on your DataTable. On Tue, Oct 14, 2008 at 1:21 PM, steve222 [EMAIL PROTECTED] wrote: Maybe I did not phrase my original the question well enough to get an answer. I have a simple DataTable containing - let call it sales records. So, some columns have numbers (eg, sales prices, sales commission, etc). At the bottom of the table, I need a row showing the of sales prices for all items in the table. I've done something like this in my Panel (this code has been chopped about, so may not be correct - but you get the idea): public class SalesPanel extends PanelBase { private double totalSales = 0.0d; private Label totalSalesLabel = new Label(totalSalesLabel, ); private WebMarkupContainer listContainer = new WebMarkupContainer(listContainer); public SalesPanel (String id) { super(id); listContainer.add(new DataView(sales, dataProvider) { int i = 0; protected void populateItem(final Item item) { SalesItem salesitem = (SalesItem) item.getModelObject(); item.add(new Label(salesref, String.valueOf(salesitem .getRef(; // add all the other columns here... // increment the total totalSales += salesitem .getSalesPrice(); totalSalesLabel.setModel(new Model(totalSales)); i++; // if we are on the last row, reset the total to zero so // total does not keep growing when panel is redisplayed // it's on a cached tab if(i == dataProvider.size()){ i = 0; totalSales = 0; } } }); addLabels(); add(listContainer); } } But maybe there is a better way. And maybe a way to do this in an AjaxFallbackDefaultDataTable? Steve steve222 wrote: What is the easiest way to get the final row in a table to show the column totals for numeric values? No need for paging or sorting - just a simple table with column totals in the final row. -- View this message in context: http://www.nabble.com/Easiest-way-to-add-column-totals-to-a-table--tp19927092p19978198.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Easiest-way-to-add-column-totals-to-a-table--tp19927092p20016024.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Easiest way to add column totals to a table?
Maybe I did not phrase my original the question well enough to get an answer. I have a simple DataTable containing - let call it sales records. So, some columns have numbers (eg, sales prices, sales commission, etc). At the bottom of the table, I need a row showing the of sales prices for all items in the table. I've done something like this in my Panel (this code has been chopped about, so may not be correct - but you get the idea): public class SalesPanel extends PanelBase { private double totalSales = 0.0d; private Label totalSalesLabel = new Label(totalSalesLabel, ); private WebMarkupContainer listContainer = new WebMarkupContainer(listContainer); public SalesPanel (String id) { super(id); listContainer.add(new DataView(sales, dataProvider) { int i = 0; protected void populateItem(final Item item) { SalesItem salesitem = (SalesItem) item.getModelObject(); item.add(new Label(salesref, String.valueOf(salesitem .getRef(; // add all the other columns here... // increment the total totalSales += salesitem .getSalesPrice(); totalSalesLabel.setModel(new Model(totalSales)); i++; // if we are on the last row, reset the total to zero so // total does not keep growing when panel is redisplayed // it's on a cached tab if(i == dataProvider.size()){ i = 0; totalSales = 0; } } }); addLabels(); add(listContainer); } } But maybe there is a better way. And maybe a way to do this in an AjaxFallbackDefaultDataTable? Steve steve222 wrote: What is the easiest way to get the final row in a table to show the column totals for numeric values? No need for paging or sorting - just a simple table with column totals in the final row. -- View this message in context: http://www.nabble.com/Easiest-way-to-add-column-totals-to-a-table--tp19927092p19978198.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Easiest way to add column totals to a table?
What is the easiest way to get the final row in a table to show the column totals for numeric values? No need for paging or sorting - just a simple table with column totals in the final row. -- View this message in context: http://www.nabble.com/Easiest-way-to-add-column-totals-to-a-table--tp19927092p19927092.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: AjaxFallbackDefaultDataTable - goto page number on return from another page
Anyone know how to solve this? Thanks. steviezz wrote: Wicket 1.3.4. I have a Page (ThingListing) containing an AjaxFallbackDefaultDataTable - created like: private WebMarkupContainer listContainer = new WebMarkupContainer(listContainer); private MySortableDealProvider dataProvider; private Thing thing = null; public ThingListing(PageParameters params) { // this is a reload from the CRUD page if (params != null) { setThing(getThingManager().findById(params.getString(thingId))); } // else load everything ... dataProvider = new SortableDealDataProvider(getThingManager(), thing); String sort = params.getString(sort); Boolean isAscending = params.getBoolean(ascending); dataProvider.setSort(sort, isAscending); ... listContainer.add(new AjaxFallbackDefaultDataTable(mything, columns, dataProvider, TABLE_ROWS)); I add an AbstractColumn to the AjaxFallbackDefaultDataTable to handle forwarding to a page to do CRUD work on the selected item from the table - like : columns.add(new AbstractColumn(new Model(Edit)) { public void populateItem(Item cellItem, String componentId, IModel model) { cellItem.add(new ActionPanel(componentId, model)); } public String getCssClass() { return edit; } }); class ActionPanel extends Panel { public ActionPanel(String id, IModel model) { super(id, model); add(new Link(edit) { public void onClick() { Integer thingId = ((Thing) getParent().getModelObject()).getId(); PageParameters params = new PageParameters(); params.put(thingId, thingId); params.put(sort, dataProvider.getSort().getProperty()); params.put(ascending, dataProvider.getSort().isAscending()); setResponsePage(ThingEdit.class, params); } }); } } Note - I am attempting to pass the id of the selected row in the table, plus the sort column, and the ascending direction to the CRUD page. The ThingEdit CRUD page takes all the page params from the ThingListing page, does normal CRUD work, then passes back all the params back into the main listing page constructor so that when the listing page reloads, it maintains its state (main selection criteria, sort column, sort order) from the page the user selected before triggering the CRUD page - eg: public class ThingEdit { private PageParameters pageParams; public ThingEdit(PageParameters p) { pageParams = p; ... } ... private void addCancelButton(Form form) { Button cancel = new Button(cancelbutton) { public void onSubmit() { setResponsePage(ThingListing.class, pageParams); } }; cancel.setDefaultFormProcessing(false); form.add(cancel); } However, I can't work out how to go back to the page number that the user was on before he loaded the CRUD page. That is, if the user was on page 3 of 20, then after clicking a record to edit goes to the CRUD page, then he goes back to the listing the correct order and sort are maintaine, but he's always at page 1 of 20 instead of page 3. I have tried manually setting the ThingSortableDataProvider.iterator() first and count and with additional page params - but this just ends up with it being called twice - once with my page params, and again by the default 0 and count. So, any way to make this work? I think am probably still missing the point with Wicket (can't really get my head around Models) and revert to attempting to use page params and manually adding to session to pass data from one page to another and back again. Steve -- View this message in context: http://www.nabble.com/AjaxFallbackDefaultDataTable---goto-page-number-on-return-from-another-page-tp18744983p19247459.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Ajax validation error messages
Hi. Can anyone recommend a good strategy for handling and dislplaying validation error messages when using Ajax? I want my basic field validation error to show next to the relevant input text boxes, and have used my own FormComponentFeedbackBorder to do this. I still want a feedback panel for more fatal backend errors - eg, record already exists, concurrent record modification, etc. Problem. If I put a feedback panel on the page, and repaint this in my button's onError with target.addComponent(feedback) - then I get duplicates of my field validation errors in my panel. Not what I want. If I only repaint the feedback onSubmit then I can catch the backend error and display my message. But subsequent Ajax form submissions don't refresh the page, so the error message in the feedback panel sticks on the page. Not sure how to clear out existing errors in the feedback panel when using Ajax, so have now used a label on my page instead, and manually clean up after myself. But is this the best way to go? -- View this message in context: http://www.nabble.com/Ajax-validation-error-messages-tp19190006p19190006.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Ajax validation error messages
Excellent - thank you. pointbreak+wicketstuff wrote: Why not just put a filter on your 'global' feedbackpanel and filter out the messages that you already display for each component? E.g. I have the following code in a form: private void addGlobalSubmitPanel() { final ListFormComponent components = getFormComponents(); final FeedbackPanel feedback = new FeedbackPanel(FEEDBACK); feedback.setFilter(new IFeedbackMessageFilter() { public boolean accept(FeedbackMessage message) { return !components.contains(message.getReporter()); } }); add(feedback); } private ListFormComponent getFormComponents() { final ListFormComponent components = new ArrayListFormComponent(); visitFormComponents(new FormComponent.IVisitor() { public Object formComponent(IFormVisitorParticipant formComponent) { final FormComponent fc = (FormComponent)formComponent; components.add(fc); return Component.IVisitor.CONTINUE_TRAVERSAL; } }); return components; } Hi. Can anyone recommend a good strategy for handling and dislplaying validation error messages when using Ajax? I want my basic field validation error to show next to the relevant input text boxes, and have used my own FormComponentFeedbackBorder to do this. I still want a feedback panel for more fatal backend errors - eg, record already exists, concurrent record modification, etc. Problem. If I put a feedback panel on the page, and repaint this in my button's onError with target.addComponent(feedback) - then I get duplicates of my field validation errors in my panel. Not what I want. If I only repaint the feedback onSubmit then I can catch the backend error and display my message. But subsequent Ajax form submissions don't refresh the page, so the error message in the feedback panel sticks on the page. Not sure how to clear out existing errors in the feedback panel when using Ajax, so have now used a label on my page instead, and manually clean up after myself. But is this the best way to go? -- View this message in context: http://www.nabble.com/Ajax-validation-error-messages-tp19190006p19190919.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Ajax-validation-error-messages-tp19190006p19191684.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Modal window - update main page on close
Hi. Using Wicket 1.3.4. I have a main page with a panel. Page contains a form for editing a main record. Panel contains a DataView containing a list of related sub records. In the java code for the pabel, create a ModalWindow and pop this for adding more sub-records. Uses AJAX. Got this working OK similar to: Main page code: public MainRecordEdit(PageParameters p) { Integer id = p.getInt(mainRecord); // uses application scope Spring bean to get record from database final MyRecord myRecord = getRecordManager().findById(id); ... // stuff form main record CRUD on main page ... // add the panel for the sub records add(new MyListingPanel(myListingPanel, myRecord)); } Panel code for sub records: public MyListingPanel(String id, final MyRecord myRecord) { super(id); Collection mySubs = myRecord.getSubRecords(); DataView dataView = new DataView(dataView, new ListDataProvider(new ArrayList(mySubs))) { public void populateItem(final Item item) { final MySub ms = (MyRecord) item.getModelObject(); item.add(new Label(id, ms.getId())); ... } }; final WebMarkupContainer listContainer = new WebMarkupContainer(theContainer); listContainer.setOutputMarkupId(true); listContainer.add(dataView); ... payawayWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { public void onClose(AjaxRequestTarget target) { // not sure what to put here to refresh the list in dataview target.addComponent(listContainer); } }); final ModalWindow modalWindow = new ModalWindow(modalWindow); modalWindow.setOutputMarkupId(true); add(modalWindow); add(new AjaxLink(modalLink) { public void onClick(AjaxRequestTarget target) { modalWindowshow(target); } }); In the jave code for the Modal window - also a Panel - I do normal CRUD stuff via AJAX with feedback going into a FeedbackPanel on the modal window panel when I save (or hit validation errors). No problems here - my AJAX updates work OK. I close the popup panel using a button: private void addCancelButton(Form form, final ModalWindow window) { AjaxFallbackButton cancel = new AjaxFallbackButton(cancelbutton, form) { @Override protected void onSubmit(AjaxRequestTarget target, Form form) { // not sure if I need to do anything here to make the new // sub record appear on main page when I close this window info(Cancel was pressed!); window.close(target); } }; cancel.setDefaultFormProcessing(false); form.add(cancel); } Window closes. Main page does not show new sub record in the DataView on the main Panel. Page refresh reloads the list OK. Thanks. -- View this message in context: http://www.nabble.com/Modal-window---update-main-page-on-close-tp18701883p18701883.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]