- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 Spring Web Flow 主要是因为它的 PRG 功能。
假设我有像 /widget/edit/99
或 /widget/edit/123
这样的 URL,其中数字代表 id
的小部件。
如何启动 /widget/edit
流程,传入 id
?
默认情况下,流程 URL 必须与流程名称文件夹结构相匹配。
我想将 url 保留在 /widget/edit/99
而不是重定向。
(使用 2.4 版)
最佳答案
您需要尝试使用 FlowController 和 DefaultFlowUrlHandler。
FlowController - 它充当 Web Flow 定义的控制逻辑和 DispatcherServlet 的网关。
根据文档,在 DefaultFlowUrlHandler 中的 createFlowDefinitionUrl 方法中:
The flow definition URL for the given flow id will be built by appending
the flow id to the base app context and servlet paths.
Example - given a request originating at:
http://someHost/someApp/someServlet/nestedPath/foo
and a request for the flow id "nestedPath/bar", the new flow definition URL
would be:
http://someHost/someApp/someServlet/nestedPath/bar
因此,如果请求类似于:somehost/yourContextPath/yourServletContext/widget/edit/99 并且流 ID 是 widget/edit,则新的流定义 URL 将是:somehost/yourContextPath/yourServletContext/widget/edit
假设某些配置为:
web.xml 配置将“/widgetinventory/*”请求映射到 yourServletContext servlet:
<servlet>
<servlet-name>yourServletContext</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>yourServletContext</servlet-name>
<url-pattern>/widgetinventory/*</url-pattern>
</servlet-mapping>
你的ServletContext-servlet.xml:servlet 路径与“/widgetinventory//”匹配的所有请求都映射到“flowController”bean。
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="alwaysUseFullPath" value="true" />
<property name="mappings">
<value>/app/**/**=flowController</value>
</property>
</bean>
<bean name="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
<property name="flowExecutor" ref="flowExecutor" />
<property name="flowUrlHandler" ref="customDefaultUrlhandler" />
</bean>
<bean id="customDefaultUrlhandler" class="package.CustomDefaultFlowUrlHandler"/>
<flow:flow-executor id="flowExecutor" flow-registry="flowRegistry"/>
<flow:flow-builder-services id="flowBuilderServices" view-factory-creator="viewFactoryCreator" validator="validator"/>
<!-- Create the registry of flow definitions -->
<flow:flow-registry id="flowRegistry" base-path="/WEB-INF/flows/" flow-builder-services="flowBuilderServices">
<flow:flow-location-pattern value="**/*-flow.xml"/>
</flow:flow-registry>
请参阅映射到 customDefaultUrlhandler 的 flowUrlHandler,它是 DefaultFlowUrlHandler 的扩展.有助于更改您在其中指定的流 url 的两个方法是:getFlowId 和 createFlowDefinitionUrl。
重写 DefaultFlowUrlHandler 中的 flowId 和 createFlowDefinitionUrl 方法。
但这一切都假设您的流 url 的类型为:somehost/{yourContextPath}/{yourServletContext}/widget/edit/99,其中 widget/edit 是 flowId,99 是一些 widgetId。
public class CustomDefaultUrlhandler extends DefaultFlowUrlHandler{
You need to alter flowId and createFlowDefinitionUrl if request is something like this:
http://host/{yourContextPath}/{yourServletContext}/widget/edit/99 to direct to widget/edit flow
@Override
public String getFlowId(HttpServletRequest request) {
String pathInfo = request.getPathInfo(); // /widget/edit/99
if (pathInfo != null) {
String widgetId = pathInfo.substring(pathInfo.lastIndexOf("/") + 1);
if(widgetId != null){
return pathInfo.substring(1,pathInfo.lastIndexOf("/")); //return widget/edit by stripping /99
}else{
return pathInfo.substring(1); //return widget/edit
}
} else {
String servletPath = request.getServletPath();
if (StringUtils.hasText(servletPath)) {
int dotIndex = servletPath.lastIndexOf('.');
if (dotIndex != -1) {
return servletPath.substring(1, dotIndex);
} else {
return servletPath.substring(1);
}
} else {
String contextPath = request.getContextPath();
if (StringUtils.hasText(contextPath)) {
return request.getContextPath().substring(1);
} else {
return null;
}
}
}
}
@Override
public String createFlowDefinitionUrl(String flowId, AttributeMap input, HttpServletRequest request) {
//now flowId = "widget/edit"
StringBuffer url = new StringBuffer();
if (request.getPathInfo() != null) {
//for /{yourContextPath}/{yourServletContext}/widget/edit/99 - pathInfo is /widget/edit/99
url.append(request.getContextPath());
url.append(request.getServletPath());
url.append('/');
url.append(flowId);
} else {
String servletPath = request.getServletPath();
if (StringUtils.hasText(servletPath)) {
url.append(request.getContextPath());
url.append('/');
url.append(flowId);
int dotIndex = servletPath.lastIndexOf('.');
if (dotIndex != -1) {
url.append(servletPath.substring(dotIndex));
}
} else {
url.append('/');
url.append(flowId);
}
}
if (input != null && !input.isEmpty()) {
url.append('?');
if (request.getPathInfo() != null) {
//append your widget id here and retrieve this in flow by requestParameters el.
String widgetId = pathInfo.substring(pathInfo.lastIndexOf("/") + 1);
url.append("widgetId ="+widgetId);
}
appendQueryParameters(url, input.asMap(), getEncodingScheme(request));
}
return url.toString();
}
}
基本上,我们根据您的 URL 自定义 flowid,并将 id 作为请求参数传递。
确保您的流程 ID 在您的场景中是 widget/edit。
在此处查看有关如何以所需格式获取流 ID 的链接:Spring Webflow - How to Get List of FLOW IDs
关于spring-webflow - 如何从这样的 URL 启动 Spring Web Flow/resource/edit/n,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24539443/
我有 Site {{$url}} 和 $(function(){ $('#pencil').click
我在每一行都有一个编辑按钮,我已经设置了 defaultColDef: { editable: false, } 在网格选项中 当我点击编辑按钮时,我希望该行处于编辑模式。如果我设置
我在每一行都有一个编辑按钮,我已经设置了 defaultColDef: { editable: false, } 在网格选项中 当我点击编辑按钮时,我希望该行处于编辑模式。如果我设置
我有一个 html 文件,我想编辑其中的字段。以下是我的 html 代码: ID GROUP NAME GROUP DESCRIPTION IS A
我希望管理员能够编辑普通用户无法编辑的字段。例如作者或订阅者等。 我试过这个:Django admin: How to display a field that is marked as editab
如何将PS文件中间的数据移动到Mainframe的左侧?有什么快捷命令吗? 我有一个数据集,第 13 列有数据,必须将其移动到第 11 列,任何短键都可以移动它。 想要将 DS 中的其余行作为第一行对
我在 div 中有一个可编辑元素,它本身是可点击的。每当我单击 x-editable anchor 元素时,单击会在 DOM 中冒泡并触发对父 div 的单击。我怎样才能防止这种情况发生?我知道可以使
我有一个类似这样的模型: class Product(models.Model): third_party_id = models.CharField(max_length=64, blank
我有一个包含 2 个可编辑文本字段的页面 {{creator.name}} Tell us about yourself in less than 100 words
这是我的架构: id: 'EntryCode', fields: { EntryCode: {editable: true, validation: {required: true}, nul
有人可以帮助确定这个问题 - http://jsfiddle.net/xBB5x/8823/ 我正在尝试实现 x-editable (bootstrap 2) typeahead 功能。 上面的 js
如果我使用例如 g_object_set (renderer, "background", "red", "background-set", FALSE, NULL); 对于文本渲染器, TreeVi
我在创建和编辑页面上都使用了 Angular 文件,但我想知道是否有办法阻止用户在/edit 页面上编辑 Geo Segment 的名称。 geo-region-detail.html: G
我正在尝试向 QListWidget 添加一个项目,选择该项目,然后开始编辑新项目。 该项目被添加,它被选中,但该行没有被引入 QLineEdit,或者它试图使用的任何东西。 这是我的小部件的代码,相
我有一个表格,其中的单元格和列中有多个值。当用户单击 TD 单元格上的任意位置时,我希望它: 成为文本区域 将当前文本粘贴到文本区域 在其下方放置一个取消按钮 一旦按下取消按钮,我希望一切都变回以前的
在我的程序中,会有一个机会编辑框,它可以更改“掉率”或“获胜率” 但我想将其更改为如果用户输入大于 100 的数字并点击编辑框,编辑框文本将变回 100。 我不知道如何实现这个。 最佳答案 看看下面的
我想创建我的编辑表单,以便它将当前用户信息简单地显示为文本,而不是在文本字段中,当用户单击文本时,它将变成文本字段,用户可以编辑他的信息。仅当用户单击提交按钮时,更改才会反射(reflect)在数据库
我有一个 QTreeWidgetItem 添加到 QTreeWidget: QTreeWidgetItem* item = new QTreeWidgetItem(ui->trwPairs); ite
我检查了最新的 Dropbox 和 Excel for iOS。在 Dropbox 中,我们有一个编辑按钮。单击它会打开 Excel 的扩展程序,您可以在其中编辑文件。 保存后,更改也会反射(refl
我目前正在使用pycord创建一个Python语言的不和谐机器人。我有一个发送消息的命令,其中嵌入了两个字段。一个名为Yes,值为0;另一个名为No,值也为0。在选择菜单中,我创建了两个选项。选项是和
我是一名优秀的程序员,十分优秀!