Struts 2 json plugin and wildcard issue?

In my struts.xml a convention is followed to call actions for a particular action class like this:

struts.xml:

<package name="cdot.oss.cmsat.gma.struts" extends="struts-default" namespace="/">
    <action name="*ConfigureTspThreshold"
                class="cdot.oss.cmsat.gma.struts.ConfigureTspThresholdAction" method="{1}">
                <result name="display">pages/ConfigureTspThresholdInput.jsp</result>
    </action>
</package>

I get method name through wildcard and ConfigureTspThresholdAction is the class name.

I am using struts2-json-plugin to convert data to JSON. Now, for some actions i want to return JSON data using struts2 json plugin.

So I need to use extends json-default and result-type json for some actions like this:

<action name="*ConfigureTspThreshold" class="cdot.oss.cmsat.gma.struts.ConfigureTspThresholdAction" method="{1}">               
    <result type="json">
        <param name="excludeProperties">
            tspNameIdMap
        </param>
    </result>
</action>

<action name="*ConfigureTspThreshold" class="cdot.oss.cmsat.gma.struts.ConfigureTspThresholdAction"
            method="{1}">
    <result type="json">
        <param name="excludeProperties">
        thresholdParameters
        </param>
    </result>
</action>

So different exclude-properties with same result-type json .

How to i fit these JSON result types in the convention followed??? As the last two actions will conflict as they have same result type json ?

Answers


What I would do is create a property in your action class myexcludedProperties

And then in your action methods, set this myexcludedProperties

and then change your action mapping to

<action name="*ConfigureTspThreshold" class="cdot.oss.cmsat.gma.struts.ConfigureTspThresholdAction"
            method="{1}">
            <result type="json">
                <param name="excludeProperties">
                    ${myexcludedProperties}
                </param>
            </result>
</action>

I believe ${myexcludedProperties} is the correct syntax.

If you don't want to code a property, you have to figure out how to differentiate requests (method="{1}") so that you can set the correct param.

Hope that makes sense.


One of the option is to use dynamic parameters in the result configuration. You can always modify the result in the action before result is executed. Look at this answer.


Need Your Help

Hibernate Criteria Pagination Error

java sql-server-2008 criteria

In the below code, I am able to retrieve all the desired data without any problem.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.