I think h:link is generated wrong

Splash Forums Rewrite Users I think h:link is generated wrong

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by  welyab 1 year, 8 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #26530

    welyab
    Participant

    Hey.

    I’m using rewrite 2.0.9.Final.

    Supose that my application is on “nota-avulsa” context path.

    My ApplicationConfigurationProvider looks like:

    return ConfigurationBuilder.begin()
                    .addRule(Join.path("/pesquisa-nota-avulsa")
                            .to("/faces/nota-avulsa/pesquisar-notas.xhtml"));

    When I write

    <h:link outcome="/faces/nota-avulsa/pesquisar-notas.xhtml">Pesquisar Notas</h:link>

    A gente negerated HTML like that:

    <a href="/pesquisa-nota-avulsa">Pesquisar Notas</a> (without context path name: "nota-avulsa")

    Is this the right behavior?

    I expected a generated link with context path, because if a click on link with contextpath, I get 404 error pager.

    <a href="/nota-avulsa/pesquisa-nota-avulsa">Pesquisar Notas</a>

    If a write the URL manually on browser, the write RULE works fine.

    Thanks.

    #26531

    I think you have to remove the /faces prefix when using h:link.

    Try:

    <h:link outcome="/nota-avulsa/pesquisar-notas.xhtml">Pesquisar Notas</h:link>

    Instead of:

    <h:link outcome="/faces/nota-avulsa/pesquisar-notas.xhtml">Pesquisar Notas</h:link>

    #26532

    welyab
    Participant

    I found the cause of problem.

    The method org.ocpsoft.rewrite.servlet.config.Substitute,performHttp(....) performs a check by testing if the generated URL starting with the context path.
    In my first post, I do not expose the real URL configuration (sorry my mistake).

    A real case is fallow:

    .addRule(Join.path("/nota-avulsa-produtor-rural")
                 .to("/faces/produtor-rural/emissao-nota-avulsa.xhtml"));

    (register invoice for farmers)

    The context path of application is "/nota-avulsa", and notice that Join.path starts with "/nota-avulsa..."as well. This cause my problem.

    The Rewrite calls the fallow method in org.ocpsoft.rewrite.servlet.config.Substitute

    @Override
       public void performHttp(final HttpServletRewrite event, final EvaluationContext context)
       {
          if (event instanceof HttpInboundServletRewrite)
          {
             String target = location.getBuilder().build(event, context, Transpositions.encodePath());
             ((HttpInboundServletRewrite) event).forward(target);
          }
          else if (event instanceof HttpOutboundServletRewrite)
          {
             ParameterizedPatternBuilder builder = location.getBuilder();
    
             String target = builder.build(event, context, Transpositions.encodePath());
             if (((HttpOutboundServletRewrite) event).getOutboundAddress().getPath().startsWith(event.getContextPath())
                      && target.startsWith("/")
                      && !target.startsWith("//")
                      // ------------------------------------------------------------------
                      // -- Here the cause of problem
                      && !target.startsWith(event.getContextPath())) // <<<<<<<<<
             {
                target = event.getContextPath() + target;
             }
             ((HttpOutboundServletRewrite) event).setOutboundAddress(AddressBuilder.create(target));
          }
       }

    My question is, is this a known restriction, which Join.path can not start with the same context name of the application?

    By now, I will continue the software production just change Join.path values to others different of context path name.

    Thanks.

    • This reply was modified 1 year, 8 months ago by  welyab.
    • This reply was modified 1 year, 8 months ago by  welyab.
    • This reply was modified 1 year, 8 months ago by  welyab.
    • This reply was modified 1 year, 8 months ago by  welyab.
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

Comments are closed.