I'm using the struts2 jasperreports plugin and it works well. The problem is that I want to pass exportParameters and I'm not sure how to do that through the plugin.
Which version of Struts2 you are using starting with 2.1.2+ it provides the feature to provides exportParameters
All you need to add following entry or similar entry in your struts config file inside your action class
<action name="myJasperTest" class="com.acme.test.action.JasperAction">
<result name="success" type="jasper">
<param name="location">foo.jasper</param>
<param name="dataSource">mySource</param>
<param name="exportParameters ">exportParameters </param>
</result>
</action>
exportParameters - OGNL expression used to retrieve a map of JR exporter parameters from the value stack. The export parameters are used to customize the JR export. For example, a PDF export might enable encryption and set the user password to a string known to the report creator.
All you need to define a map for your export parameters in your action class and provides its getter/setter than use its reference as described.
For details refer this URL
jasperreports
**Update**
Here is how they have done it in result type
exporter = new JRXlsExporter();
Map exportParams = (Map) stack.findValue(exportParameters);
if (exportParams != null) {
LOG.debug("Found export parameters; adding to exporter parameters...");
exporter.getParameters().putAll(exportParams);
}
so what they did is they tried to find out a map in value stack with name exportParameters if they find it they are adding it.So have to do this in your action class
Map<String,String> exportParameters= //init your map here
set your properties in this map and create a getter and setter for this property
getExportParameters()
setExportParameters()
and in your struts config file declare the map as follows
<param name="exportParameters ">exportParameters </param>
rest framework will take care
Hope this will help you
Related
I need to create and use global variable as optional parameter, but do not know how I can implement it.
I created the global variable in Ranorex studio:
Also this variable appeared in Data binding tag:
But I can't use this variable in the code. (ASECore package do not contains any parameters).
You can use the global Variables in Ranorex Record module or Ranorex Code module. Let me please first make an introduction of how to use them.
Create in Record module
In the Record module, click button Variables... in the top right corner and add the variables you want to use in the redord module.
Then use them in your recording:
Create in Code module
When you create a code module, it will look like this:
/// <summary>
/// Description of MyCode.
/// </summary>
[TestModule("32310FEC-5336-4F83-B448-ABC851EE5731", ModuleType.UserCode, 1)]
public class MyCode : ITestModule
{
/// <summary>
/// Constructs a new instance.
/// </summary>
public MyCode()
{
// Do not delete - a parameterless constructor is required!
}
/// <summary>
/// Performs the playback of actions in this module.
/// </summary>
/// <remarks>You should not call this method directly, instead pass the module
/// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method
/// that will in turn invoke this method.</remarks>
void ITestModule.Run()
{
Mouse.DefaultMoveTime = 300;
Keyboard.DefaultKeyPressTime = 100;
Delay.SpeedFactor = 1.0;
}
}
Now, right click in the code and choose "Insert new module variable". Then you can set a name and default value. Press ok and it will add something like this:
string _MyVariable = "DefaultValue";
[TestVariable("de0fb4a9-32ba-4635-8f0f-4ff6db184c3f")]
public string MyVariable
{
get { return _MyVariable; }
set { _MyVariable = value; }
}
Now, you can use the variables in the run method like normal C# properties:
repo.Calculator.CalculatorResults.PressKeys(Input_1);
repo.Calculator.PlusButton.Click();
repo.Calculator.CalculatorResults.PressKeys(Input_2);
repo.Calculator.EqualButton.Click();
How to bind Variables in Suite
When you created the global parameters, it's true that you can not bind them on the suite level.
Therefore close the dialog and right click on the Record/Code module and choose "Data binding"
In the lower table you can bind your variables of the Record/Code module to the global variables. If they have the same name, you can also Auto-bind them.
When you now execute the test suite, the values of the global variables will be used in test. If you execute the Record/Code module standalone, then the default values will be used in test.
Once you have set that variable in your highest node, you can use it and assign variables to it in lower nodes. So when you make a smart folder in your test suite and go to the data binding, you will notice the global is present under the parameters. All you need to do is make a recording with a variable that will use the global variable and link it in that folder.
Using Mule, I need to loop a collection of records in a batch fashion (don't want to use the Batch scope). In the foreach element you have the way to specify the batch size to partition your collection.
Being said that, if you specify a number it works just fine. For instance
<foreach doc:name="For Each" batchSize="100">
<logger message="#[flowVars.counter]" level="INFO" doc:name="Logger"/>
</foreach>
It will print batches of 100 elements as I want. But if I use MEL it throws a NumberFormatException. Here the xml
<foreach doc:name="For Each" batchSize="#[flowVars.counter]">
<logger message="#[flowVars.counter]" level="INFO" doc:name="Logger"/>
</foreach>
The exception
ERROR 2017-03-01 09:47:06,121 [main] org.mule.module.launcher.application.DefaultMuleApplication: null
java.lang.NumberFormatException: For input string: "[flowVars.batchSize]"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[?:1.8.0_121]
at java.lang.Integer.parseInt(Integer.java:580) ~[?:1.8.0_121]
at java.lang.Integer.valueOf(Integer.java:740) ~[?:1.8.0_121]
at java.lang.Integer.decode(Integer.java:1197) ~[?:1.8.0_121]
I printed the class type of #[flowVars.batchSize] and it is an Integer, so that shouldn't be the problem. Instead, I think that the foreach scope doesn't allow you to use MEL at least for this property.
My question, is it or is it not possible to use MEL to determine the batch size value of a foreach scope?
Thanks in advance.
Notice that this is not a runtime error. This error appears in the initialise() stage of the class ForEach,in other words, according to the default configuration you are not allowed to set dynamically the batchSize of the components. The issue is that he is trying to parse the xml to get the value inside the batchSize="" xml tag and he finds a string (#[flowVars.counter]) and not an integer ("5").
ForEach class below:
public class Foreach extends AbstractMessageProcessorOwner implements Initialisable, MessageProcessor, NonBlockingSupported{
#Override
public void initialise() throws InitialisationException
{....
splitter.setBatchSize(batchSize); .... }
As a work around, you can just set one property as batchSizeForEach and refer to this property using ${batchSizeForEach}
Regards!
I have a list of "Business Needs" (custom type) each need should be implemented by an "Epic".
How can I add a thing to a "Business Need" that will let me create an "Epic" with the link created automatically?
You can achieve this by developing a new Jira-Plugin.
This could consist of two parts:
Define a new menu entry in the jira application menu
Define a jira-action which does your linking stuff
Defining a new menu entry is rather simple:
The needed plugin-type is Web Item Plugin Module.
For this you just have to make an entry in your atlassian.xml:
<web-item key="foo" name="Foo"
section="operations-top-level" weight="47">
//snip...
<label>Foo action</label>
<link linkId="foo">
<![CDATA[/secure/FooAction!default.jspa?issue=${issue.id}]]>
</link>
</web-item>
After doing so you can define the action you want to trigger when clicking the action. For this you can use a Webwork plugin
<webwork1 key="fooaction" name="FooAction" class="java.lang.Object">
//snip...
<actions>
<action name="fooaction" alias="FooAction"></action>
</actions>
</webwork1>
In you FooAction-class you just can do your linking stuff:
public class FooAction extends JiraWebActionSupport {
#Override
#RequiresXsrfCheck
public String doExecute() throws Exception {
ComponentAccessor.getIssueLinkManager().createIssueLink(...);
}
}
When I access a JPA managed date value from JSF, it comes back with an javax.faces.component.UdateModelException saying
'Cannot convert 01.01.10 00:00 of type class java.util.Date to class org.apache.openjpa.util.java$util$Date$proxy
Using a JPA-managed date value (which means it is proxied) works fine when it is used directly from the EL likes this:
'<h:outputLabel value="MyDateValue" for="input"/>
'<h:inputText id="inputDate" value="#{bean.myDate}"/>
However, it causes trouble when trying to use it with composite components
and gives back the following converter exception and thus can't update the model...
The (simplified) JSF composite component inputDate.xhtml
<head>
<title>A date input field</title>
</head>
<composite:interface>
<composite:attribute name="dateValue"/>
</composite:interface>
<composite:implementation>
<h:outputLabel value="MyDateValue" for="input"/>
<h:inputText id="input" value="#{cc.attrs.dateValue}"/>
</composite:implementation>
Assumption:
It seems the proxy replacement in OpenJPA is handled differently when the value is being accessed from inside a composite. My guess is the EL-resolver handles calls to object values differently when it is passed to composites. Passing it to composites means it is first accessed within the composite, which is too late and the required replacement of the proxy is not accomplished (thus the converter exception)
So I tried to change the Expression Language for MyFaces, but it didn't work in Websphere, even though I changed the class loading to parent last and provided el-impl and el-api from glassfish in the lib folder and inserted the necessary context-param for MyFaces
How do you guys use JPA-managed dates (or other proxied entities) in composite components???
If you are using the sun EL implementation you might use the following ELResolver which works around this issue:
public class BugfixELResolver extends ELResolver {
//...
#Override
public Class<?> getType(ELContext anElContext, Object aBase, Object aProperty) {
if (aBase.getClass().getCanonicalName().equals("com.sun.faces.el.CompositeComponentAttributesELResolver.ExpressionEvalMap")){
Object tempProperty=((Map)aBase).get(aProperty);
if (tempProperty!=null&&tempProperty.getClass().getCanonicalName().equals("org.apache.openjpa.util.java.util.Date.proxy")) {
anElContext.setPropertyResolved(true);
return java.util.Date.class;
}
}
return null;
}
}
Add it to the faces-config this way:
<el-resolver>
xxx.BugfixELResolver
</el-resolver>
This workaround can also be used in environments where you can not change the EL implementation (like websphere etc.).
Here is the workaround. The problem seems to be WebSpheres' ExpressionLanguage Implementation or rather the order resolvers are executed. Registering the JBoss EL implementation works and resolves the date proxies before calling the composite component. I also tried the Glassfish EL, but it didn't work either...
Registering a alternative EL is quite strange: The setting in web.xml for MyFaces is
<context-param>
<param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
Additionally under WebContent/META-INF/services/ a file named javax.el.expressionFactory is needed with this single line org.jboss.el.ExpressionFactoryImpl. The class comes from jboss-el-2.0.2.CR1.jar
(sorry, couldn't find the link to a maven repo)
I will keep you updated once I find a better solution...
I'm trying to implement the Struts 2 Annotations in my project, but I don't know how.
I added the convention-plugin v 2.1.8.1 to my pom
I modified the web.xml
...
<init-param>
<param-name>actionPackages</param-name>
<param-value>org.apache.struts.helloworld.action</param-value>
</init-param>
...
My Action
package org.apache.struts.helloworld.action;
import org.apache.struts.helloworld.model.MessageStore;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
#Results({
#Result(name="success", location="HelloWorld.jsp")
})
public class HelloWorld extends ActionSupport {
public String execute() throws Exception {
messageStore = new MessageStore() ; return SUCCESS;
}
The jsp page from where I'm trying to use my action.
<body>
<h1>Welcome To Struts 2!</h1>
<p>Hello World</p>
</body>
When I press the link associated to the action helloWorld, but it's sends me to the exactly the same page. So, from index.jsp, it's sends to index.jsp.
The way it should behave: it should send me to HelloWorld.jsp.
I uploaded the project (a very simple HelloWorld app) to FileFront, maybe someone sees where is the problem. http://www.filefront.com/16364385/Hello_World.zip
Convention uses a different convention to convert CamelCaseAction names to url's and jsp's names. If you are using Convention's defaults, I believe you should have used the following names:
ActionClass: HelloWorldAction.java
JSP: hello-world.jsp
Action: hello-world
Also, notice that by default convention will look for your JSPs on WEB-INF/content . The documentation is a bit shallow, you have to understand by the examples, but you can consult all default values there: http://struts.apache.org/2.x/docs/convention-plugin.html
I havent used Struts2 with annotations (which Struts2 version? are you following some tutorial or doc?) . But should not that location attribute (in the Result annotation) be instead value ?
What do the logs say? Have you tried using /HelloWorld.jsp for "success". I think that struts framework does not find the resource and is loading the same page.
When you use /HelloWorld.jsp, hopefully you will see the result page.