I use primefaces and the dataTable component. On my Site i have several forms which i use to collect Data and persist it in the Database. This is triggered by a p:command Button, which Attribute “Update“ contains the id of the dataTable showing the DB contents. When i submit the Form the component (table) is Not updated. What could be wrong?
not an answer but a question to help divine the point of failure. is the datatable in a separate form from the commandButton? if so, assuming you're using ajax="true" (the default for pf components), how are you referencing the table to make sure it updates. if you're not using ajax, i'm guessing it's a stale data issue in the backing bean. but without more info, it's hard. try attaching source code (stripped down to your comfort level if you're working on something sensitive).
HTH
Related
I have a view where there is a dropdown and datatable.
At initial load, I am loading the values to be loaded in the datatable based on the first select of dropdown and on change of dropdown, I want to fetch data based on that condition and populate those data on the datatable.
Please anyone suggest a way to do this!
I am trying a way using get request but it is reloading the page and hence I am unable to make the data persist in the datatable.
I followed exactly this https://laracasts.com/discuss/channels/laravel/filtering-data-using-drop-down-onchange-event
Data is coming and populates to the datatable but just after a second, it reloads and comes to old data in datatable.
Please either correct my or suggest some new way to do it!
After debugging, I found that in one of the js file included, there were a code
$(document).ajaxStop(function() {
window.location.reload();
});
Since, this code was making it to reload on every ajax call completes, I faced this issue.
I have a data table that represents data like this:
after clicking the edit marker (pencil icon) i can edit some fields. The fields need to be validated and if it fails the fields have to reset. I do this in the managed bean of the view using p:ajax event="rowEditInit" to save the attributes before saving and ajax event="rowEdit"to do the actual validation. if validation fails i return the previously saved values. if validation is correct i save the data to the database and load the collection again. Then i
RequestContext.getCurrentInstance().update("vesselBalticSegmentCreateForm")
to reload the view.
Doesnt matter if the validation fails and i set the values back or it succeeds and i save/reload data the table breaks becoming like this:
seems to load only the edited row. and loads both edit/list modes.
any ideas what i'm doing wrong?
The primeFaces RowEdit functionality already updates the row, also updating the table does by design not work (not sure if it is intentional, but that is just how it is). I know there is a duplicate of this Q/A on stackoverflow, I just do not seem to be able to find it. Someone might be able to create a patch/workaround, e.g. try on the prerenderview event to remove the id's of id's in the individual row that was edited. I don't have the time to try to create one.
i have a MVC3 project with KnockoutJS and in my view.
The form that the user fills, has information already loaded from the server and the user is filling and selecting from this data so then, the user saves the data selected.
So... sometimes, the user, in the middle of the form, realize that some data is missing and it must cancel the form fill and edit the data that is missing and come back and do it again. So, my question is this... can i persist the view model in some way that the user can edit the missing data in other tab or window in the explorer and then refresh the form and dont lose the data?
I hope the explanation was clear.. my English is a little bit rusty.
Thanks!
Yes, you can. If the data is on the same page, you could save the viewmodel data to another object, possibly using ko.toJSON. Then you can pull it back in later.
If you have to reload the page, you could save the viewmodel or the form's state in storage, using a library like amplify.js. http://amplifyjs.com/api/store/
pseudo code:
amplify.store('myData', myViewModel);
I have a form that only has a checkbox. If the checkbox is not checked then the page won't be valid and won't submit the data. On the view I have out putted some fields from the model object, just to let the user know what they are deleting. When I click the Submit button and the model state is not valid the page will show the validation error but the data from the model is no longer there!
Does anyone know how I can persist this data without making another call to the database to populate the model object?
Thanks
ASP.Net MVC will not magically persist model info.
You need to either include it in hidden fields in the form (which an attacker can modify), or re-fetch it from the database.
If you don't repopulate the Model from the DB, you have to postback all the data, using hidden fields for example.
Anyway, I don't understand how the model validation could fail, being just a checkbox :/.
I was wondering if there is a way to maintain your list of options on a Select List in MVC 3. I am pretty new to MVC but in WebForms you could populate the DropDownList on the first load of the page and then the ViewState would maintain that list for all of the AutoPostBacks. This was nice because often, DropDownLists are populated by query to the database. I know that ViewState does not exist in MVC but is there a better way of repopulating the SelectList without having to hit the database during the request of every post?
You have several options here.
Your selected value will be posted back. With that in mind since you no longer have ViewState you ideally want to
Have your Repository (if you dont have one - create one. You simply ask the repository for the data and it controls the caching or loading) that you ask for the data in the drop down, cache the data and just simply request it again. Rebind your list (use DropDownFor)
Use MVCContrib's Html.Serialize to essentially ViewState it, however the cache is a bit cleaner and doesnt rely on data sent back and forth.
Also remember that after you post your data, if everything is 'good' you want to REDIRECT back to your "GET" action to reload the data and display to the client. This was an issue in web forms that sometime a user saw XYZ after postback but after a refresh saw YXX. Using the PRG pattern in MVC posts-redirects-gets to load up fresh data.
After your post you should generally only redisplay the data if there was a validation error, otherwise redirect to a get method.
Your controller receives the value on postback. You have to place that value back in the model to tell the view what the selected value is.