I am my migrating my Struts 1.1 application to Struts 2.1.
I know that in struts 1 all action urls have .do eg
myLoginAction.do
So can Struts 2 also have action with .do extension?
If yes what is the correct way to that?
Need step by step solution.
You can use struts.action.extension to define acceptable multiple patterns.
The following constant allows actions with the suffixes of "", ".action", or ".do".
<constant name="struts.action.extension" value=",action,do" />
Related
I am new to Struts. I have to migrate code form Struts1 to Struts2 but confused in select tag of Struts2. Please help in writing the equivalent code in Struts2.
<nested:select property="pmt_type0" onchange="openTable(this,0)">
<html:option value=""></html:option>
<html:optionsCollection name="paymentTypesList" label="paymentTypeDescription" value="paymentTypeCode"/>
</nested:select>
It should be something like this:
<s:select name="pmt_type0"
list="paymentTypesList"
listKey="paymentTypeCode"
listValue="paymentTypeDescription"
emptyOption="true"
onchange="openTable(this,0)" />
Where paymentTypesList is a list of objects with paymentTypeCode and paymentTypeDescription properties.
To find out more take a look at the Struts2 tags.
I am working on code migration from Struts 1.x to Struts 2.0
Can anyone please tell me the equivalent tag for the below line in Struts 2.0
<bean:page id="req" property="request" /> is the tag in Struts 1.x
Now I want to convert the above line in Struts 1.x to the equivalent line in Struts 2.0.
There isn't a direct equivalent.
The <bean:page> tag just exposes a page-scoped bean for scriptlets, which you shouldn't be using.
If you want to use a page scope of the variable you can use scope attribute of the s:set tag
<s:set var="req" value="#request" scope="page"/>
Note, that the #request points to the Struts request map, it's not JSP's implicit request object, but it has access to request attributes.
I want to extend Struts 2 s:select tag.
Can somebody explain step required to do the same.
Also if there is any hook or implementation available in Struts2 framework for the same
I think you can change the freemarker template as you need and extend org.apache.struts2.views.jsp.ui.SelectTag class.
Check this article to start with.
You can start by examining the freemarker templates (default is freemarker but it can be velocity or some other template engine). See http://mikeski.net/site/node/16.
If that is not enough for you then you could extend or create your own implementation of select tag. http://joshuajava.wordpress.com/2008/12/27/creating-custom-components-with-struts-2/
I want to create a custom template engine like velocity or freemarker which will be used in struts 2 based application. Why I don't want to use any of the available template engines is because, I want to keep the HMTL fixed and editable by dreamweaver means no struts tags or JSTL. The values will be injected with Xpath or simple string replacement of values of existing HTML tags. I require:
plain HTML + some configuration (properties/xml) + data =>
HTML populated with data + some dynamically generated javascripts
1) Define a package with the name of your result type and the class that will be called when an action returns that result type.
<package name="default" namespace="/" extends="struts-default">
<result-types>
<result-type name="myResultType" class="com.awesome.MyResult"/>
</result-types>
.... actions and other things...
</package>
2) Implement the Struts 2 result type class:
package com.awesome;
public class MyResult extends StrutsResultSupport{
//1) read the the target file
//2) process/transform the target file
//3) write out the transformed file as the result
}
There is a good description of this in "Apache Struts 2 web application Development" by Dave Newton. I know the above class isn't implemented but I bet you can find what you need from here.
I need to generate a datagrid using a Struts 2, i have found out Struts-Layout can do that, but its not supporting Struts 2. Can any one suggest me a way to generate a datagrid using Struts 2?
There are two out of the box solution available.
The first is Display Tag and the other is [Struts2 jQuery Plugin with the Grid Tag][2].
http://displaytag.sourceforge.net/1.2/
http://code.google.com/p/struts2-jquery/