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

时间:2016-08-18 21:22:42

标签: jsf prettyfaces commandlink ocpsoft-rewrite

我目前在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
}

1 个答案:

答案 0 :(得分:1)

请确保在依赖项中包含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集成模块,这可能导致类似这样的事情。