Search code examples
jsfprettyfacescommandlinkocpsoft-rewrite

commandLink not invoke action with rewrite RewriteRule activated


I'm currently using rewrite-config-prettyfaces 3.4.0.Final with Mojarra 2.2.13 on JRE 8 in WildFly 10. With that setup (some details are below) everything works fine. Now I would like to drop the pretty-config.xml file and switch to the rule based RewriteConfiguration. Once I've created this and mapped my pretty-config url-mapping into rules, my application seems to work fine. However, I noticed that my h:commandLink action never gets invoked anymore. When I switch back to pretty-config.xml it works fine, switch back.. urgs. Do you have any clue why this is not working with the RewriteConfiguration?

My classpath contains the following rewrite jars:

  • rewrite-servlet-3.4.0.Final.jar
  • rewrite-config-prettyfaces-3.4.0.Final.jar (but this is dropped in the not working setup)

Below you can find some snippets of my code.

Thanks a lot!

My pretty-config has this configuration

<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>

My RewriteConfiguration file

@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;
    }
}

My simplified dummy.xhtml file looks like this:

Note: The relevant section with the commandLink is actually part of catalogDashboard.jsf. Please consider the missing dummy rewrite rule as present.

<?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>

My bean with the method to invoke via commandLink action

@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
}

Solution

  • Please make sure you include Rewrite JSF integration module in your dependencies:

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

    The rewrite-config-prettyfaces depends on this module since 3.4.0.Final. So if you drop the PrettyFaces integration, you will also loose the core JSF integration module which could lead to something like this.