|
|
Tool Tips
-
When implementing Model Driven interface to use Java Beans or Business objects in your pages,
do not reassign value to the model object. Only create model driven object once and use it, otherwise
the results may be unknown and you may see wierd behaviour in your application.
-
In Struts2, if you pass on a Null value to a web page, Struts will return a blank, NOT a Null value to your action.
This is good approach as compared to Struts1.x which returns nulls and because of that you often see NullPointerExceptions
errors in your applications and on your pages.
If you need to check on null values, you have to play a trick, for instance if you get back a blank value,
you can interpret it to a null value using a common utility method.
-
You can specify your own custom interceptor stack, to be used in your application instead of using the default
interceptor stack. The Stack can include your own interceptors, which defines the flow in your application.
-
Struts supports result types for Tiles, PDF and other formats. You do not have to do much hard work.
If you want to use Tiles in Struts2, there are two ways to do it. Either add the tiles-def.xml file in your
Struts.xml file, or you can include an entry for result type "tiles" in the Struts.xml configuration file.
-
When chaining actions, the properties with the same names are chained (carried forward), so if you want to
have same properties populated in the target action, then you should keep same property names in source and
target actions.
-
Default theme in Struts is XHTML theme which uses default struts presentation format (table/columns)
and the default labels for fields. If you want to use your own formatting on pages or When you want to use Ajax
tags to do dynamic loading of the DIVs and other parts of the page, you need to use simple theme and ajax theme
respectively. You can use different themes in different parts of the same page depending on what tags/functions
you want to use.
-
You can create Struts2 objects from Spring context
with dependencies injected by Spring into Actions.
To do so configure the beans in the Spring
application context file. Change the
"class"
attribute in
struts.xml
action mapping file to use the bean names defined in
the Spring context, instead of the actual class names.
Add
struts.objectFactory = spring
to the
struts.properties file
. Add the Spring listener to the
web.xml
, as shown below:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Add the Spring configiuration file to the WEB-INF folder.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="autodetect">
<bean id="tutorial" class="indus.it.tutorial"/>
</beans>
Note that you can also have a web context listener to do further manipulations at the application loading.
|
|