我目前在 WildFly 10 的 JRE 8 上使用 rewrite-config-prettyfaces 3.4.0.Final 和 Mojarra 2.2.13。使用该设置(下面有一些细节)一切正常。现在我想删除 pretty-config.xml 文件并切换到基于规则的 RewriteConfiguration。一旦我创建了这个并将我的漂亮配置 url 映射映射到规则中,我的应用程序似乎工作正常。但是,我注意到我的 h:commandLink 操作不再被调用。当我切换回 pretty-config.xml 时,它工作正常,切换回.. urgs。您是否知道为什么这不适用于 RewriteConfiguration?
我的类路径包含以下重写 jar:
- 重写-servlet-3.4.0.Final.jar
- rewrite-config-prettyfaces-3.4.0.Final.jar (但这在不工作的设置中被删除)
您可以在下面找到我的一些代码片段。
非常感谢!
我的漂亮配置有这个配置
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">
<url-mapping id="start">
<pattern value="/#{lang}"/>
<view-id value="/dashboard.jsf"/>
</url-mapping>
<url-mapping id="download">
<pattern value="/#{lang}/downloadReport.html"/>
<view-id value="/downloadReport.jsf"/>
</url-mapping>
<url-mapping id="catalog">
<pattern value="/#{lang}/catalogue/#{catalogName}"/>
<view-id value="/catalogDashboard.jsf"/>
</url-mapping>
<url-mapping id="violations">
<pattern value="/#{lang}/catalogue/#{catalogName}/violations"/>
<view-id value="/violations.jsf"/>
</url-mapping>
<url-mapping id="distributions">
<pattern value="/#{lang}/catalogue/#{catalogName}/distributions"/>
<view-id value="/distributions.jsf"/>
</url-mapping>
</pretty-config>
我的 RewriteConfiguration 文件
@RewriteConfiguration
public class ApplicationNavigationConfigurationProvider extends HttpConfigurationProvider {
@Override
public Configuration getConfiguration(ServletContext servletContext) {
return ConfigurationBuilder.begin()
.addRule(TrailingSlash.remove())
.addRule(Join.path("/{lang}").to("/dashboard.jsf"))
.addRule(Join.path("/{lang}/downloadReport.html").to("/downloadReport.jsf"))
.addRule(Join.path("/{lang}/catalogue/{catalogName}").to("/catalogDashboard.jsf"))
.addRule(Join.path("/{lang}/catalogue/{catalogName}/violations").to("/violations.jsf"))
.addRule(Join.path("/{lang}/catalogue/{catalogName}/distributions").to("/distributions.jsf"));
}
@Override
public int priority() {
return 0;
}
}
我简化的 dummy.xhtml 文件如下所示:
注意:与 commandLink 相关的部分实际上是 catalogDashboard.jsf 的一部分。请考虑存在缺失的虚拟重写规则。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<h:body>
<h:outputText value="#{harvesterBean.currentRepository.name}"/>
<h:form>
<h:commandLink action="#{harvesterBean.updateAttachment(1)}" value="Test action invocation">
<f:param name="catalogName" value="#{request.getParameter('catalogName')}"/>
</h:commandLink>
</h:form>
</h:body>
</f:view>
</html>
我的 bean 具有通过 commandLink 操作调用的方法
@ViewScoped
@Named
public class HarvesterBean implements Serializable { // updated: implements Serializable
@Inject
private HarvesterClientActionImpl harvesterClientAction;
@Inject
private CurrentCatalogBean currentCatalogBean;
private Repository currentRepository;
private Harvester currentHarvester;
private Run currentRun;
private List<RunLog> logs;
private String selectedAttachment;
@PostConstruct
public void init() {
currentRepository = harvesterClientAction.retrieveRepository(currentCatalogBean.getCurrentCatalog().getTitle());
currentHarvester = harvesterClientAction.retrieveHarvester(currentRepository.getSourceHarvester());
currentRun = harvesterClientAction.retrieveLastRun(currentHarvester.getId());
logs = harvesterClientAction.retrieveRunLogs(currentHarvester.getId(), currentRun.getId());
}
// This method is not invoked when using the RewriteConfiguration instead of pretty-config.xml
public void updateAttachment(long logId) {
selectedAttachment = harvesterClientAction.retrieveAttachment(currentHarvester.getId(), currentRun.getId(), logId);
}
// getter and setter
}