commandLink 不调用重写 RewriteRule 激活的操作

commandLink not invoke action with rewrite RewriteRule activated

我目前在 WildFly 10 的 JRE 8 上使用带有 Mojarra 2.2.13 的 rewrite-config-prettyfaces 3.4.0.Final。使用该设置(下面有一些细节)一切正常。现在我想删除 pretty-config.xml 文件并切换到基于规则的 RewriteConfiguration。一旦我创建了这个并将我的 pretty-config url-mapping 映射到规则中,我的应用程序似乎工作正常。但是,我注意到我的 h:commandLink 操作再也没有被调用过。当我切换回 pretty-config.xml 时它工作正常,切换回来.. urgs。您知道为什么这不适用于 RewriteConfiguration 吗?

我的类路径包含以下重写 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
}

请确保在依赖项中包含 Rewrite JSF 集成模块:

  <dependency>
     <groupId>org.ocpsoft.rewrite</groupId>
     <artifactId>rewrite-integration-faces</artifactId>
     <version>3.4.0.Final</version>
  </dependency>

rewrite-config-prettyfaces 自 3.4.0.Final 起依赖此模块。因此,如果您放弃 PrettyFaces 集成,您也会失去核心 JSF 集成模块,这可能会导致类似的情况。