Spring Webflow: No actions were executed - spring-webflow

I'm trying to implement an Action in SWF but I get the same error even in the simplest example.
Error: "java.lang.IllegalStateException: No actions were executed, thus I cannot execute any state transition"
import org.springframework.webflow.execution.Action;
import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;
public class HelloAction implements Action {
#Override
public Event execute(RequestContext rc) throws Exception {
return new Event(this, "success");
}
I've declared the bean.
<bean id="helloAction" class="app.action.HelloAction"/>
And in flow.xml..
<action-state id="intermedio">
<action bean="helloAction"/>
<transition on="success" to="fin"/>
</action-state>
<end-state id="fin" view="final" />
It works fine if I don't use "HelloAction". But if I want to use Action in SWF, I always get the previous error.
Is something else needed?
Thanks in advance.

<action-state id="intermedio">
<evaluate expression="helloAction.execute()">
<transition on="success" to="fin"/>
</action-state>

Related

Windchill - Create tab

i created custom-actionmodels.xml
<model name="partInfoPageTabSet" resource="com.ptc.core.ui.navigationRB">
<submodel name="windimTabModel" />
</model>
<model name="windimTabModel" resourceBundle="com.windim.windimRB">
<action name="windimTabAction" type="windim"/>
</model>
custom-actions.xml also
<objecttype name="windim" resourceBundle="com.windim.windimRB">
<action name="windimTabAction" resourceBundle="com.windim.windimRB">
<command windowType="page" url="netmarkets/jsp/part/info.jsp"/>
</action>
</objecttype>
and compiled windimRB.java in /codebase/com/windim
package com.windim;
import wt.util.resource.*;
#RBUUID("com.windim.windimRB")
public final class windimRB extends WTListResourceBundle {
#RBEntry("WindIM")
// #RBComment("Resolving issues")
// #RBArgComment0("Any string...")
public static final String WINDIM_TABMODEL = "object_windimTabModel";
}
and tab does not work.
object_windimTabModel
turned intoto
object.windimTabModel

How to obtain httpServletRequest in validate method of SpringWebFlow

I need to access httpServletRequest in the validate method of spring webflow. Please help me how to do this.
My webflow for view state is:
<var name="search" class="com.test.form.Search"/>
...................
<view-state id="search" model="search" view="searchPage">
<transition on="submit" to="searchAction">
</transition>
</view-state>
...............
validate method in search model class is:
public void validateLoanSearch(ValidationContext context) {
//I need to get a httpServletRequest here...
}
In action/controller class I can get it thru RequestContext but ValidationContext gives only the messageContext. Any idea? Please help.
I got the solution.
In the bean class or validator class inside the validate method use this:
RequestContext rc = RequestContextHolder.getRequestContext();
RequestContextHolder is becoming available inside the validate method.

Collection/List property won't bind or update on form submit

So I have set up a wizard interface with spring web flow that gradually populates a single form object/model. It works fine for the first few steps that have to populate single String or primitive properties and a String array (from a checkbox interface).
Then I have a List<String> property. It renders properly as multiple textboxes with correct initialized values. But when I edit the textboxes on the browser and submit, the values do not take effect on the form bean. It still has the initial values.
Below is the detailed set-up:
Web flow on-start which creates the bean:
<on-start>
<evaluate expression="new mypackage.MyFormBean()" result="flowScope.myFormBean" />
</on-start>
Here are the relevant parts of my form bean:
public class MyFormBean implements Serializable {
...
private List<SlotBean> slots;
...
public List<SlotBean> getSlots() {
return slots;
}
public void setSlots(List<SlotBean> slots) {
this.slots= slots;
}
...
}
public class SlotBean {
...
private int quantity;
...
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity= quantity;
}
...
}
I have a series of view-states in my web flow with simple string or number field bindings set-up that are initialized, displayed and saved without issues to the form.
This view-state generates any number of SlotBean objects then initializes quantity with 2. These are set to the slots property.
<view-state id="generate-criteria" model="disciplineCatalogue">
...
<transition on="next" to="slots-grid">
<evaluate expression="myService.generateSlots(myFormBean)"/>
</transition>
...
</view-state>
Here is the jsp fragment. All it does is render a bunch of textboxes. There's also a next button:
<form:form id="slotsGrid" modelAttribute="myFormBean" action="${flowExecutionUrl}">
...
<c:forEach var="slot" items="${myFormBean.slots}" varStatus="idx">
<form:input path="slots[${idx.index}].quantity" />
</c:forEach>
...
<button type="submit" id="next" name="_eventId_next">Next</button>
...
</form:form>
The above code displays correctly with the initial values (2). It generates multiple textboxes like below:
<input id="slots0.quantity" name="slots[0].quantity" type="text" value="2"/>
So when this page is on the browser, I change the values of the quantity textboxes to different values and click the "next" button. On my browser's network debugger, I see that the form values are sent to the server:
slots[0].quantity:3
slots[1].quantity:1
slots[2].quantity:2
Here is the relevant web flow entry for the next button.
<view-state id="slots-grid" model="myFormBean">
<binder>
...
<binding property="slots" />
</binder>
...
<transition on="next" to="finished">
<evaluate expression="myService.create(myFormBean)"/>
</transition>
...
</view-state>
So I put a break point on the myService.create(myFormBean) method and it shows that all the quantity fields are still set to the original "2". The new values didn't bind to myFormBean.slots.
Is there anything you can see in my set-up that looks wrong?
Thanks for any time you can put into this
Spring Framework 3.1.1
Spring-Webflow 2.3.1
Tomcat 6.0.18
Eclipse Indigo
Cross-posted in:
http://forum.springsource.org/showthread.php?127809-Collection-List-property-won-t-bind-or-update-on-form-submit

Spring MVC 3, Interceptor on all excluding some defined paths

Is it possible to apply an interceptor to all controllers and actions, except some that are defined?
Just to be clear, I am not interested in applying an interceptor on a list of defined ones. I want to define those to exclude.
Thanks!
Since Spring 3.2 they added that feature with the tag
mvc:exclude-mapping
See this example from the Spring documentation:
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
<mvc:interceptor>
<mvc:mapping path="/**"/>
<mvc:exclude-mapping path="/admin/**"/>
<bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor" />
</mvc:interceptor>
<mvc:interceptor>
<mvc:mapping path="/secure/*"/>
<bean class="org.example.SecurityInterceptor" />
</mvc:interceptor>
Here's the link to the doc
For java based configuration, from the docs
#Configuration
#EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
#Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LocaleInterceptor());
registry.addInterceptor(new ThemeInterceptor()).addPathPatterns("/**").excludePathPatterns("/admin/**");
registry.addInterceptor(new SecurityInterceptor()).addPathPatterns("/secure/*");
}
}
When configuring an interceptor, you can specify a path pattern. The interceptor will be invoked only for controllers which the path matches the interceptor path pattern.
ref: http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/mvc.html#mvc-config-interceptor
But as you probably noticed it, the path pattern doesn't support exclusion.
So I think the only way is to code a blacklist of paths inside the interceptor. When the interceptor is invoked, retrieve the HttpServletRequest.getRequestURI() and check if the path is blacklisted or not.
You can build the blacklist inside a #PostConstruct annotated method of the interceptor, and so get the blacklisted path from a property file for instance.

Default formView for SimpleFormController?

Firstly I would like to say that I am quite new to Spring (in particular the MVC framework), and just trying to understand how everything works so please go easy on me.
I'm playing around with a dummy application that I've created, and I've created a simple login form that users can access via the /login.html bean. The bean definition is as follows:
<bean name="/login.html" class="test.controller.LoginController">
<property name="successView" value="list_messages.html" />
<property name="commandClass" value="test.domain.Login" />
<property name="commandName" value="login" />
</bean>
(the Login class is a simple object containing a username and password field with appropriate getters and setters).
The LoginController class does virtually nothing for now:
public class LoginController extends SimpleFormController
{
#Override
protected ModelAndView onSubmit(Object command, BindException errors) throws Exception
{
return new ModelAndView(new RedirectView(getSuccessView()));
}
}
Now I have one view resolver in my bean definition file, which goes as follows:
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
To support my Login form I have a login.jsp file in my jsp directory.
My question is as follows: why does accessing /login.html redirect me to login.jsp? I have not specified a formView property for my form, so how does the view resolver know to redirect me to login.jsp?
Thanks in advance for any help!
Joseph.
When you do not specify The logical view name, Spring relies on DefaultRequestToViewNameTranslator, which is installed by default. So if your request is something like
http://127.0.0.1:8080/app/<LOGICAL_NAME_EXTRACTED_BY_VIEW_NAME_TRANSLATOR_GOES_HERE>.html
Have you seen <LOGICAL_NAME_EXTRACTED_BY_VIEW_NAME_TRANSLATOR> ??? So if your request is
http://127.0.0.1:8080/app/login.html
The logical name extracted by ViewNameTranslator is login which is supplied To viewResolver and Translated To
/jsp/login.jsp
Nothing else

Resources