How to Bind Data coming from DB to spring input tag - spring

i have the following scenario.
I have a list of auctions coming from the DB. I am displaying each auction properties on the JSP page as a record.
I am using spring 3.0.5, Tomcat 6.0.29 and eclipselink as JPA provider.
In my controller i am seeting this list as model attribute and passing it to the JSp page.
I want to use spring tags (form:input) to display the data.
Using Form backing bean we can display default values on a form. But in my case is there any way to bind data to form:input tag in the JSP?
Thanks

There is no reason to display your data in form:input tags other than that you want to allow your user to edit the data. If that is not the case, then using form:input just to display the data is pointless.
If you want to allow your user to edit the data, how are you going to get back the changes he has done? Obviously you are going to need your Command object. So there is no reason not to use formBackingObject() in your FormController to set values in your Command object, which will be consequently displayed on your JSP. When user will make any changes and submit the form, you will get all those modified values in your Command object which you can process in onSubmit() method of your FormController.

Related

How to create html element for each object in collection?

I have String like this:
{"response":{"count":997,"items":[{"id":2943,"first_name":"Vasya","last_name":"Babich","can_access_closed":true,"is_closed":false,"screen_name":"antanubis","track_code":"24fc13d6ZwhuhzyM9V1oRkohiruY-zXeoP1aliqA-1dA4qgxJrQAYSTQYe6kVWsTTKkXWWybQrHU"},{"id":231329886,"first_name":"Vasya","last_name":"Babich","can_access_closed":true,"is_closed":false,"screen_name":"lydka_lydka_lydka","track_code":"a348ab0aAo3CxaTAGsTDu4mpMdBMMjYxgAmOnr7PvUWgaanh141l5NGe_PlLz8a8unX1eOUxXj-GCo6esKk"}]}}
I want to show each value of "items" to user in browser and then user should be able to select one of them and save in database and in his own page in the website. I guess I should use loop and create html element for each item. But how to do this? What data type should I use to manipulate this data and store it?
Thymeleaf is the most widely used view/template engine with Spring Boot and can handle your loop requirement. Spring MVC enables you to manage your app behavior and define the data bound to HTML pages (views). You will need a database and there are lots of options. Check out Spring Data which makes it easy to work with all major database technologies.

Populate Wicket table with Ajax

Is it possible to have 1 input text field that accepts characters from the user, and as the user types, queries to a webservice are launched, and to update the contents of another component dynamicaly with the results of the webservice (which would be a table below the input text)?
If you prefer to use Wicket form controls and Data Table component then you need to make the call to the REST service in your impl of IDataProvider.
Otherwise, as I explained to you earlier today in your other SO post you can do this directly in JS without Wicket. It is a matter of taste and skills.

Spring MVC update field based on calculation

I have page with spring form fields.
They're bind using command.
Couple of fields in form need to be update based on calculation from other fields.
Those fields can be modified by user.
How can I do that?
I think about trigger java calculation in model using onchanged in web page. But I don't know how access methods from model and how read fields from page.
I notice, that field are update by setter when page is submit. This is too late if I want calculate 'live' when depending fields are changing.
If you need these calculations to be done on server (java model)... I suggest to use input's onChange event as you said, send values with AJAX to server and calculate there, returning the result to client again for update UI in real-time.
With this approach, you will get the 'live thing' you are wondering for.

Submit Datatable: Spring

I have a datatable on my jsp populated by a "java.util.Set" collection that came from a Hibernate search. I want to make this datatable editable and then save the edited table on my database. I'm able to do it if the datatable is formed through List collection object. All my POJO objects are formed with Set Collection and I'm trying to avoid changing all of them.
I'm using Spring MVC and as I told before Hibernate.
Thanks.
Regards.
It seems that it's possible to use a Set to display data in a JSP but you can't modify them.
Take a look of this link.

Passing ModelAttribute across multiple requests in Spring MVC

I have a multiple criteria search form with a command attribute. On the first submit, results are obtained based on the options in command object. On the results page, there is a link to export all the results to excel.. I have implemented it using the XMLViewResolver. I need to pass the SearchForm model attribute to the controller that handles this export requests. Also, from search results page, user can click on a person's profile and can come back to search results again. I want to keep this Model Attributes in session across all these requests. How would I achieve that in Spring MVC? #SessionAttributes is probably not an option because, as I understand, once the request goes to different controller, this object is flushed.
You can store whatever object you would like (SearchForm model) in the session associated with the HttpRequest via request.getSession();
This will allow you to access your model from the session within all controllers.
You could also store the criteria as hidden form fields on the form responsible for the user action. For instance, when the user clicks export to excel, the button would be contained within a form which contains hidden form fields whose values are set from the previous SearchForm bean.

Resources