The Struts 2 Convention platform defines several parent packages

I am working on a Struts 2 web application using the Convention plugin to customize everything with annotations. I hit some of my action classes where I would like to use multiple parent packages. I found a way to do this on the Apache site - but it seems to be out of date. This does not work, discarding a type mismatch: it is not possible to convert from String[] to String error.

 @ParentPackage({"my-parent-package1, my-parent-package2"}) package com.mycompany.myapp.actions import org.apache.struts2.config.ParentPackage; 

I am using Struts 2.2.1. Can I provide multiple batch action packages through annotations? It seems strange that they would remove it as a function.

+1
java annotations struts2 struts2-convention-plugin
source share
2 answers

You cannot do this with annotations, but it is still possible through the XML configuration. Javadok says

This annotation allows actions to modify the parent package that they use. Since XWork packages are created by the Convention plugin through Java packages in which actions exist, there are several complex processes for parent XWork packages and XWork package namespaces for detected actions, so that two actions in the same package can specify different parents and namespaces without collision.

To handle this correctly, the name of the XWork package that the actions are placed in is built in this format:

<java-package> # <parent-xwork-package> # <namespace>

This means that in a java package it is possible to have multiple parent packages. But you cannot place two or more @ParentPackage annotations in the same class or package. And since you cannot have an array for parent packages. But you can at least have two parent packages, one in the package definition and the other in the action class. And the failed constructor config builds two configurations for these annotations, but the action config is created only for those that have the annotation.

+2
source share

I checked org.apache.struts2.convention.annotation.ParentPackage for you, it is not allowed to define a package with multiple parents. here is a snippet:

 @Target({ElementType.TYPE, ElementType.PACKAGE}) @Retention(value = RetentionPolicy.RUNTIME) public @interface ParentPackage { /** * @return The parent package. */ String value(); } 
+1
source share

All Articles