struts1 to struts2 migration message resource - struts2

Currently we are using Struts1 and we want to use struts2(convention+annotation) for incoming projects.
I'm having a problem with struts2 regarding message resource
in Struts1 we use a custom MessageResourceFactory which configured in struts-config.xml
<message-resource factory="" param="">
we used <bean:message> tags in struts1 to call the messages.
I can't find a good way to do it in struts2
any recommendation?

Never mind I ended up, overwriting the defaultTextProvider from Struts2 , define a bean for it in struts.xml and also set it as TextProvider that should be used.

Related

How to upload a file in Grails 3

Grails 2 had a plugin for that, there also used to be
request.getFile
method. There is no method like this in Grails 3 as far as I can see, or a plugin.
I tried using
request.getInputStream
But this one is always empty. Other thing I tried was by using Spring-boot way of handling Uploads, but this one relies on
#RequestParam("file") MultipartFile file
It cannot be used in Grails, controllers there do not allow parameters to be defined this way AFAIK.
How to upload files in Grails 3?
Actually there is
request.getFile(fileName)
in Grails 3 as well. It was just not displayed in autofill in my IDE for some reason (the rest of the request methods like getParameters or isPost are displayed correctly).

How to use ActionForm, ActionForward, DispatchAction, ActionMessages in Struts2

I am converting application from struts1 to struts2 so I need to use ActionForm, ActionForward, DispatchAction, ActionMessages.
How I can use that in struts 2?
If you convert an app from struts1 to struts2 then you don't need to use these classes because they belong to struts1, but if you want to use struts2-struts1-plugin then you can use them. Note that using this plugin is is not easy and requires some effort to configure such application. See Struts 1 Plugin.

Struts 1 or Struts 2 . Which one is advisable for web application development?

I am little bit confused to choose Struts 1 or Struts 2 for my new web application development assignment. Could any one suggest me which framework should I use for development from architecture point of view? What are the points I should take care of to choose the struts version before I go for development of the application?
Any help will be appreciated.
Hi I prefer struts 2 because,
Struts 1.x
In struts 1.x front controller is ActionServlet
In struts 1.x we have RequestProcessor class
In struts 1.x we have multiple tag libraries like html, logic, bean..etc
In struts 1.x the configuration fine name can be [any name].xml and we used to place in web-inf folder
In struts 1.x we have form beans and Action classes separately
In struts 1.x an Action class is a single ton class, so Action class object is not a thread safe, as a programmer we need to make it as thread safe by applying synchronization
In struts 1.x we have only jsp as a view technology
Struts 2.X
In 2.x front controller is FilterDispatcher
In 2.x we have Interceptors instead RequestProcessor
In 2.x we do not have multiple libraries, instead we have single library which includes all tags
In 2.x the configuration file must be struts.xml only and this must be in classes folder
In 2.x form bean, Action classes are combinedly given as Action class only, of course we can take separately if we want
In 2.x an Action class object will be created for each request, so it is by default thread safe, so we no need to take care about safety issues here
In 2.x we have support of multiple view technologies like velocity, Freemarker, jasper reports, jsp.
Since you have mentioned that it is going to be a new web-application,Just go with Struts2.Struts1 has already in EOL which means there will be no loner support for the Struts1.
Also Struts2 is a new and very flexible framework and will provide you a lot more control.Here are
Choose latest version of Struts2 to start work with (2.3.15.1)
If you are planning to write your service layer in Spring, you can use Struts2-spring plugin to let spring DI manage struts2 component for you.
Since you seems new to Struts2, i suggest to pay special attention to OGNL which is a core building block in struts2 and you will going to use it a lot in your Tags at UI.
Struts2 has a very flexible plug-able architecture which let you to create as well use many plugin which can save your time to build functionality from start.
Hope this might help you.Additionally You can review and look in to other MVC framework also
I also prefer going with Struts2 itself rather than Struts1 because Struts1 is old and its EOL has been announced on September 1, 2013 with the message "the Struts 1.x web framework has reached its end of life and is no longer officially supported."
[Source:- wikipedia.org]
So it is better to go with Struts2[i have been using version:-2.3.1.1 as I faced some "Dispatcher error"(jar files in the package were not compatible with each other) issue while using 2.3.16 version]
Hope this might help.
I've had a similar dilemma as you do, but instead of going with Struts, I've chosen Tapestry after some consideration.
Some of its awesome features are
Pages as POJOs
Really good dependency injection
Scalable
Easy to learn with lots of examples
much more...

JSF 2.0 javax.faces.webapp.FacesServlet mappig

I started to use JSF 2.0 recently and I don't understand completely how I need to configure the javax.faces.webapp.FacesServlet to correctly handle resources.
For example, If I decided to create a web application with .xhtml files and .jsp files and I want both them to use jsf technology how am I supposed to configure the jsf servlet to handle both?
Sometimes I found example where the servlet url pattern is just /faces/*
thanks!
I suggest to use a suffix pattern as URL pattern like *.jsf. If a Facelets file (.xhtml) is present on the given view ID, then it will be served. Otherwise if a JSP file (.jsp) is present on the given view ID, then it will be served. This also gives you the room to gradually upgrade from JSP to Facelets without the need to change URLs, so that you can ultimately get rid of those legacy JSPs in an easy way.

How can I ensure all requests go through an interceptor stack?

When working in Struts2, it is just too easy to create a template and refer a URL to it without creating an associated Action. Struts2 merrily renders the template -- which is fine in most cases, but not in our case: in order to ensure proper selection of a locale, we need all our requests go through a minimal interceptor stack.
We've been researching these two ways, both unsuccessfully:
Defining a "default action" which
would be executed for any template
which doesn't have an associated
action.
Disabling the ability to
render templates without an action
-- this would force programmers to define actions for any template,
which is a good solution too.
Thanks.
Maybe look into the wildcard mappings.
<action name="*" class="struts2you.examplelogin.BaseActionSupport">
<result name="success">{1}.jsp</result>
</action>
If you place something like this as the first action I think all your unmapped jsp will be run through the default interceptor stack which you can define in struts.xml
Then also place your jsp files under the WEB-INF directory to prevent direct access
When working in Struts2, it is just too easy to create a template and refer a URL to it without creating an associated Action.
Since Struts2 is an MVC framework, every request to it should invoke an action class and therefore go through an interceptor stack. I assume that you mean that you have JSPs that are not under WEB-INF and so they can be invoked directly via URL. That's generally a poor practice in the MVC world, as your JSPs should only represent the view layer. Place the JSPs somewhere under WEB-INF and all requests will be forced to go through an action, which will resolve your problem.
As for the choices, I would advocate creating explicit mappings for each of your templates.

Resources