I'm working on a webflow (SWF2). The entities are generated using Roo. One of the webflow views, multi-instance.jspx, may be called multiple times to allow for multiple, persisted instances of the same entity (MyClass).
I'd like to keep a list of those persisted entities so that I can reference them on a later point in the flow. So far, I've tried the following.
A simplified version of my flow.xml looks like this:
<on-start>
<evaluate expression="new java.util.ArrayList()" result="flowScope.myList" result-type="java.io.Serializable"/>
</on-start>
<view-state id="multi-instance" view="multi-instance" model="myClass">
<binder>
<binding property="field1"/>
<binding property="field2"/>
</binder>
<on-entry>
<evaluate expression="new com.test.MyClass()" result="flowScope.myClass" />
</on-entry>
<transition on="another_instance" to="multi-instance"/>
<transition on="success" to="confirm"/>
<transition on="cancel" to="abort"/>
<on-exit>
<evaluate expression="myClass.persist()"/>
<evaluate expression="flowScope.myList.add(myClass)"/>
</on-exit>
</view-state>
The confirm and abort view-states are defined in flow.xml as well. The confirm.jspx looks like this:
<div xmlns:spring="http://www.springframework.org/tags" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:form="http://www.springframework.org/tags/form" xmlns:util="urn:jsptagdir:/WEB-INF/tags/util" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<jsp:output omit-xml-declaration="yes" />
<form:form>
<c:forEach items="${myList}" var="instance">
<li>${instance.getField1()} ${instance.getField2()}</li>
</c:forEach>
<div class="submit">
<input type="submit" id="success" name="_eventId_success" value="success"/>
<input type="submit" id="cancel" name="_eventId_cancel" value="cancel" />
</div>
</form:form>
</div>
So to the question:
Whenever I hit confirm.jspx, the web return says that there's an exception thrown at org.springframework.webflow.engine.impl.FlowExecutionImpl.wrap(FlowExecutionImpl.java:569).
EDIT: The Apache log is a little more enlightening. The following is a snippet of the top of the call stack:
SEVERE: Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException:
/WEB-INF/views/myflow/confirmation.jspx(6,7)
The function getField1 must be used with a prefix when a default namespace is not specified
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
I'm not sure if the ArrayList-approach is possible; I believe I've read somewhere that the flowScope.myClass instance, as it is defined in the multi-instance-state, is picked up by the GC or at least falls out of scope. I'm not sure. If anyone can shed some light on that particular topic, I'd be thrilled.
(And if you happen to know a better way to keep a list of these persisted entities, please feel free to let me know!) Thanks in advance! :)
Update:
I'm able to count the number of elements in my list like so:
<c:choose>
<c:when test="${myList != null}">myList exists, it contains <c:out value="${fn:length(myList)}" /> items!</c:when>
<c:otherwise>myList doesn't exist.</c:otherwise>
</c:choose>
It shows the same number of elements as I've inserted. However, when I do this:
<c:forEach items="${myList}" var="instance">
<c:if test="${instance != null}">
<li>${instance.field1} ${instance.field2}</li>
</c:if>
</c:forEach>
nothing is displayed. (I can confirm that there is a correct number of <li>-elements when the null-test is omitted. Note also that I'm trying to access the properties directly, as indicated here: jstl/jsp - iterating over a vector of beans) I don't know what to think, regarding the scope here, but it seems clear that I can't access my entities via an ArrayList.
First, with regards to your question(s) around variable scoping, I would suggest looking at section 4.4 of the SWF documentation, where it describes all of the different available scopes.
Flow scope variables live through the lifetime of the flow. So your myClass variable will not go away until the flow exits. However keep in mind that your <on-entry> expression is assigning a new instance every time that view state is entered.
Second, I think you are probably on the right track with your solution. I would note several things:
You are persisting and adding to your list in the <on-exit> element -- this means these two things will always happen when you leave the state, including when you are doing your cancel transition. This may not be what you want. Related:
Your <transition on="another_instance" to="multi-instance"/> is actually exiting the view-state and re-entering it, triggering the <on-exit> and <on-entry> logic. It is possible to remain in the same state, by simply doing <transition on="another_instance">. Doing this will execute any logic you have inside the transition, and then re-render the view without actually changing states.
You may want to consider using the <var> tag to initialize variables... what you are doing with <evaluate expression="new ..."/> works but using <var> may be cleaner. Also, it is not necessary to say result-type="java.io.Serializable". result-type should be used when you need to convert the return type to something elese.
Finally, the error you are getting looks like it is unrelated to webflow. JSTL/EL allow you to access bean properties but not methods, and you are trying to invoke a method. See this question for more info.
Related
I have two test groups which are dependent on another group.
<dependencies>
<group name="search" depends-on="login" />
<group name="addnew" depends-on="login" />
</dependencies>
Which one out of the two groups (search, addnew) should ideally get executed first? For me, the group addnew is getting executed first all the time, which I don't want to happen. I want search to get executed and then addnew to get executed, once login is done. Also, I have set "preserve-order" for the test as true. Any suggestions?
If you want search to get executed first, then add new is also dependent on search group in that case. You can specify a list of groups in the depends-on list. Try with depends-on="login search" or you can let search depend on login and make add new depend on search to guarantee execution order.
Quote from documentation: "By default, TestNG will run your tests in the order they are found in the XML file. If you want the classes and methods listed in this file to be run in an unpredictible order, set the preserve-order attribute to false:"
<test name="Regression1" preserve-order="false">
<class name="test.Test1">
<methods>
<include name="m1" />
<include name="m2" />
</methods>
</class>
<class name="test.Test2" />
I've created a spring roo project using 'Getting started with spring roo' as a starting point. The project is created in STS using roo 1.1.5. I've added neo4j graph and is able to create nodes with simple edges and create the web-part issuing 'controller all --package ~.web'.
The project is a simple web-app with a Person and Race node and a Participant-edge with start-time, end-time, total-time and race-id. Since the edge Participant is a #RelatedToVia it becomes a #RelationshipEntity and I want to add a button to save Participant.
I found WEB-INF/tags/form/field/table.tagx where the add-, modify-, delete-buttons and friends are defined, ie.:
<c:if test="${update}">
<td class="utilbox">
..
But where do I set the variable update? I've looked through the code that is created by STS, but unable to find it. Pardon if this is obvious.
regards
Claus
Edit:
I found out that WEB-INF/tags/form/show.tagx have the knobs to enable/disable for instance the update-button:
<c:if test="${empty update}">
<c:set var="update" value="true" />
</c:if>
So I will add my new button in this file. The spring framework seems so well laid out. Just have to find the various places.
regards
Claus
The value for update is obtained from attributes you specify when you use the tag created using the tagx.
For an example,
If form:table was used as in a jspx and if the following was set, you will recieve true in your update variable if it was assigned using a directive. However it seems that the true is set as default in the form:table tag within Spring Roo.
If you want to set it to false, when using you have to set the value to the attribute as following.
<form:table update="false" />
If you want to go deeper into this, look in to the table.tagx file you have mentioned you will find the following line which explains it.
<jsp:directive.attribute name="update" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Include 'update' link into table (default true)" />
Cheers.
I am playing around with Spring-Webflow (2.3), ZK (5.0.7.1) and ZK Spring (3.0).
Actually I'm trying to signal an event with a HTML link as described at Spring-Webflow.
<a href="${flowExecutionUrl}&_eventId=go2ProjectRoomView" >2 Project</a>
Part of my flow definition file looks like:
<view-state id="mainView">
<transition on="go2ProjectRoomView" to="projectRoomView" bind="false"/>
</view-state>
<view-state id="projectRoomView">
<transition on="go2MainView" to="mainView" bind="false"/>
</view-state>
If I deploy my web project and navigate to the main view following error appears:
The reference to entity "_eventId" must end with the ';' delimiter
Same error happens if I replace _eventId=go2ProjectRoomView by _eventId_go2ProjectRoomView.
Link to full stack trace.
The error you are receiving is actually an HTML/XML parsing error. Ampersand (&) is used to reference special characters/entities (see here). Change your link to:
<a href="${flowExecutionUrl}&_eventId=go2ProjectRoomView" >2 Project</a>
and you should be ok.
I'm reading Spring WebFlow documentation, but I don't understand what can i do with outcome value in end-state of flow. Could You show me some practical example ? I wonder how to pass outcome variable to MVC Controller or another flow, but don't know how.
<flow>
<end-state id="test2">
<output name="id" value="123" />
</end-state>
</flow>
You can access your output variables from the parent flow (if you have called a subflow) by using currentEvent.attributes (so in your example):
currentEvent.attributes.id
See section 3.10 Calling Subflows
You can also get them programatically in a FlowHandler by implementing the handleExecutionOutcome method. There is an example in the docs under the "Example FlowHandler" section of 11.4 Implementing custom FlowHandlers.
I'm responsible for allowing unit tests for one of ETL components.I want to acomplish this using testNG with generic java test class and number of test definitions in testng.xmlpassing various parameters to the class.Oracle and ETL guys should be able to add new tests without changing the java code, so we need to use xml suite file instead of annotations.
Question
Is there a way to group tests in testng.xml?(similarly to how it is done with annotations)
I mean something like
<group name="first_group">
<test>
<class ...>
<parameter ...>
</test>
</group>
<group name="second_group">
<test>
<class ...>
<parameter ...>
</test>
</group>
I've checked the testng.dtd as figured out that similar syntax is not allowed.But is therea workaround to allow grouping?
Thanks in advance
You can specify groups within testng.xml and then run testng using -groups
<test name="Regression1">
<groups>
<run>
<exclude name="brokenTests" />
<include name="checkinTests" />
</run>
</groups>
....
No, this is not possible at the moment.
As a rule of thumb, I don't like adding information in XML that points into Java code, because refactorings might silently break your entire build.
For example, if you rename a method or a class name, your tests might start mysteriously breaking until you remember you need to update your XML as well.
Feel free to bring this up on the testng-users mailing-list and we can see if there's interest for such a feature.
--
Cedric