What is the difference between action-forward and action-mapping - struts-1

So I have a searchPage.jsp which will search an api and show results on resultPage.jsp. searchForm.java which have getters and setters and have all the variables that will be on the searchPage.jsp form. There is a searchAction page that will call the api. Every page have its own configuration page like search-configuration.xml.
My question
How do I get the variables from the searchPage.jsp to searchAction.java using searchForm.java?
How do redirect searchPage.jsp take the results from searchAction.jsp and populate the field on the result page?
How do I configure the searchPage.jsp to handle this?
I have gone through this tutorial: https://mkyong.com/tutorials/struts-tutorials/
Thanks

Via a normal Struts 1 ActionForm implementation. The linked tutorial has several examples of action forms and passing data from JSP-to-action`.
There are multiple ways to do this; the easiest is by setting a request attribute and accessing it via JSTL1. The linked tutorial has several examples of setting request attributes and accessing them in the view layer.
Via the normal Struts 1 configuration mechanisms, of which the linked tutorial has several examples.
Remember: Struts 1 was EOLed ~10 years ago, with good reason. Unless there's a specific job still using a dead framework, or you're spelunking Java Web framework history, don't bother.
1 (JSTL tags should be favored over Struts 1 tags when functionality
overlaps.

Related

Spring Mvc passing model data to multiple pages before persisting

I am in the process of creating a simple application with Spring Mvc and thymeleaf and I am currently thinking of what functionality I want to implement but I don't know exactly how to do it.
Let's say I have a model class Person. Regularly I have a form and a controller where I am passing the new person object and persist it with JPA.
No problem there but what if I want to have a page that I give some of the person basics info and then hit the "next" button and give some additional information. Then hit "next" again, review the data and hit "save"?
You can do it by integrate Spring Webflow in your project.
Webflow is basically extensive part of WebMvc. Webflow has some configuration that, where you have to start and where you should go. If you have 5 page and you would like to all these data will put into database in one process then Webflow will help you. One more advantage is, you can add validation in particular pages and particular means you have five model and all these model will work in one flow.
Read more, https://projects.spring.io/spring-webflow/
I have not used Thymeleaf, but usually this kind of problem can be solved using some of the following methods or something similar:
1.) Save the unfinished data to database using the same schema or some other schema for this (or in session; in general sense, save it somewhere on server side). Problem with this is how to get rid of abandoned data where user has not moved to finish.
2.) Drag the data from page to page with request parameters. If the requests are of type POST then just in POST body, if they are type GET then as query parameters. Problem with this is it's not very clean.
3.) Don't do full page requests. Solve it with some front end solution using Javascript. Depending on the app it might or might not be possible.
4.) Do full page requests but still solve it in front end using local storage or session storage. Similar problems as with keeping the data in server side session.

Spring 4: Individual view layouts depending on request

I am using Spring 4 MVC to display serve my web page. I now want to display the same content with different layouts wrapped around the body/content depending on the current HttpServletRequest (e.g. request.getServerName()). This means https://page1.test/page.html will be mapped to the same controller as https://page2.test/page.html and returns the same content depending on the controller logic, but page1.test draws for example a different header and footer.
As far as I know, Spring MVC is not capable of doing this. I am now planing to use Apache Tiles 3 or JSP 2.0 tags to do this. Is there any best practice and how can I do this (Spring Java Config is preferred)?
You should take a read of http://tech.finn.no/2012/07/25/the-ultimate-view-tiles-3/ just to see how far you can push Tiles-3
Indeed it can solve what you're after.
(That blog website has just been migrated from wordpress to github pages so some of the code snippets require horizontal scrolling, we're still cleaning these small formatting issues up so please excuse them)

Render ASP.NET MVC string to View without HttpContext or ControllerContext?

I need to render an ASP.NET MVC view to a string so as to be able to send it via an email (it is an order confirmation email defined in an .ascx file ).
I've successfully been able to render an ASP.NET MVC View to string using one of the methods in this question.
However now I need to be able to do it via a WCF service (that will be accessed via silverlight) and so I don't have a ControllerContext. This WCF service is contained within the same project as my MVC project so has access to all my models etc.
I've looked at several questions on Stackoverflow about this issue, but they all seem to need a controller context. I thought there was something in mvccontrib but it doesn't seem to be there anymore.
The closest I've found is the accepted answer to the aforementioned question, but it unfortunately breaks with RenderPartial within the view you're rendering.
I'm hoping maybe some of the behind the scenes work for ASP.NET MVC 2 related to RenderAction may help make this possible now?
BuildStarted and I have put together a standalone Razor templating engine which you might find useful (Github). You'll need to adapt your .ascx content into a simple string template, but it should do the job.
If you've got NuGet, you can run Install-Package RazorEngine
You may checkout the following blog post. Also Postal is worth looking at.
You need to create a fake HttpContextBase with a fake HttpRequestBase that return meaningful values from their properties.

jqGrid filtering

I want to implement filtering in my jqGrid in my Spring Framework MVC 3.0 project. Where can I find sample code or documentation telling how to use filtering in this?
I just posted an answer on the same question (probably from you) on http://www.trirand.com/blog/?page_id=393/help/jqgrid-filtering. To make other people easy to read the answer I post the same information here.
The answer on your question depends a little how you interpret the "filtering". If you want use some external controls (selects, checkboxes and so on on the same page where you have jqGrid) to filter your data I recommend you to read How to filter the jqGrid data NOT using the built in search/filter box.
If you want to implement data filtering inside of jqGrid you can choose between serching with respect of "search" and reset of serching results with respect of "refresh" buttons of the navigator (simple searching and advanced searching), the usage of toolbar searching (conside the usage of stringResult: true to be more conform with other form of searching) and custom searching.
If you decide to use advance searching you can just add string filter parameter to the (see Guidance on a better way to retain filtering options when using ASP.NET MVC 2) action which provide the grid data or add three string parameters searchField, searchString, searchOper if you want to use simple searching feature. In all cases you will have to add WHERE to the SELECT statments which will be constructed in your program based on the values of the new parameters.
Probably other people post you more URLs to the good full code examples which you could use.
UPATED: I don't use Spring Framework myself, so I could not help you with any Spring MVC 3.0 examples. Some general solution is more common. For example in ASP.NET MVC solutions I prefer don't fill the data in the grid directly using MVC. Instead of that I provide a JSON web service (implemented as a part of ASP.NET MVC solutions or as WCFservice which are the part of the same web site) which URL I place in the jqGrid parameter. So you should just invest in the writing on business logic in form of JSON/XML web service which provide the data. The most jqGrid specific code you can write in JavaScript. So you can share the experience of other people in the usage of jqGrid and have a clear separation of HTML code from the business logic. Moreover JSON/XML web services can be better tested for example with respect of unit tests.

How to maintain state in a web app - as HTTP is stateless

I am new in building web apps and just begun learning and setting up Grails. I am planning to build an app which has a flow of 4 to 5 pages. Since HTTP is a stateless protocol, how is the state between the pages maintained usually. I am curious what is the accepted standard here, should I create session scoped objects and use them between pages or keep passing around the values between pages (not sure if it is effective if I have a large number of items on a page). Or instead of using 4 to 5 pages should I just use one page with multiple divs and show/hide based on the user clicks?
I think using domain objects in Grails would help here but I dont have a DB backing the UI and only some webservices which will do the UI actions so I cant use domain objects.
A Grails specific solution would be good but also wanted to know how this is handled in web development in general.
Without using a DB, there are a few options you could use:
Use POST/GET variables to pass info from page to page.
Use the session to store information.
Use cookies to store information.
Using POST/GET is usually best if you just have one page "talking" to one other page (e.g. submission of a form). If you have a bunch of data that will be shared by several pages, the best way to do it would probably be to put them in the session. If you need those values to stick around after the user leaves your site and comes back later, then you might want to use cookies.
You may want to look into WebFlow (Spring WebFlow) in Grails. I find it helpful in wizard like or shopping cart like applications where you want to hold on to the data between a group of pages (ie: Page 1, Page 2... Page 4) and then at the end submit the data somewhere etc.

Resources