How to create onPostback="false" at HttpConfigurationProvider

Splash Forums Rewrite Users How to create onPostback="false" at HttpConfigurationProvider

This topic contains 9 replies, has 3 voices, and was last updated by  Christian Kaltepoth 2 years, 11 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #24516

    persapiens
    Participant

    I used to work with prettyfaces. In my pretty-config.xml, I have:

    <url-mapping id=”loginSistema”>
    <pattern value=”/#{sistema}” />
    <view-id value=”/login.jsf” />
    <action onPostback=”false”>#{loginMBean.paginaLoginOuRedirecionaSistemaExterno()}</action>
    </url-mapping>

    I’m using rewrite now. I have:

    @Override
    public Configuration getConfiguration(ServletContext t) {
    return ConfigurationBuilder.begin()
    .addRule(Join.path(“/{sistema}”).to(“/login.jsf”))
    .perform(PhaseOperation.enqueue(Invoke.binding(El.retrievalMethod(“loginMBean.paginaLoginOuRedirecionaSistemaExterno”))).after(PhaseId.RESTORE_VIEW))
    .where(“sistema”).bindsTo(PhaseBinding.to(El.property(“loginMBean.sistema”)).after(PhaseId.RESTORE_VIEW));
    }

    How can I convert onPostback=”false” from prettyfaces to rewrite configuration?
    The rewrite IgnorePostback annotation is the only possible way to use onPostback?

    I look forward you answer.

    #24526

    Hi there!

    It looks like we have not included a convenient way of doing this in the API! We’ll have to remedy that. Until then, however you can use the IgnorePostbackOperation class directly from the rewrite-integration-faces module:

    org.ocpsoft.rewrite.faces.annotation.config.IgnorePostbackOperation

    @Override
    public Configuration getConfiguration(ServletContext t) {
    return ConfigurationBuilder.begin()
    .addRule(Join.path(“/{sistema}”).to(“/login.jsf”))
    .perform(PhaseOperation.enqueue(new IgnorePostbackOperation(
       Invoke.binding(El.retrievalMethod(“loginMBean.paginaLoginOuRedirecionaSistemaExterno”)))
    ).after(PhaseId.RESTORE_VIEW))
    .where(“sistema”).bindsTo(PhaseBinding.to(El.property(“loginMBean.sistema”)).after(PhaseId.RESTORE_VIEW));
    }
    #24527

    I’ve created an issue to track this. If you wanted, you could actually implement it! It should not be hard, and we provide a very simple test-harness to test the change! Contributions from community members really help things happen faster 🙂

    https://github.com/ocpsoft/rewrite/issues/121

    Let me know if you are interested in trying this one out!

    ~Lincoln

    #24701

    persapiens
    Participant

    Hi Lincoln! Thanks for your answer.

    The convenient method should be two:

    public static PhaseOperation<?> ignorePostBack(final Operation operation)
    public static PhaseOperation<?> ignorePostBack(final Operation operation, final int priority)

    How could I help?
    I forked rewrite from git, but I could not compile rewrite-integration-faces using netbeans. I think I miss some configuration 🙁

    “Tests in error:
    org.ocpsoft.rewrite.faces.cdn.SchemalessCDNRuleTest: Could not create a new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor see cause.
    org.ocpsoft.rewrite.faces.DeferredOperationTest: Could not create a new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor see cause.
    org.ocpsoft.rewrite.faces.PhaseOperationTest: Could not create a new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor see cause.
    org.ocpsoft.rewrite.faces.resolver.FacesBeanNameResolverTest: Could not create a new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor see cause.
    org.ocpsoft.rewrite.faces.error.ErrorPageTest: Could not create a new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor see cause.
    org.ocpsoft.rewrite.faces.navigate.NavigateOutcomeTest: Could not create a new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor see cause.
    org.ocpsoft.rewrite.faces.outcome.OutcomeEncodingTest: Could not create a new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor see cause.”

    #24702

    I think this is because you need to set the appropriate Maven Profile for the test runner! If you were building on the command-line, for instance, you would use one the following profiles:

    mvn clean install -PJBOSS_AS_MANAGED_7.X
    mvn clean install -PJETTY_EMBEDDED_8.X
    mvn clean install -PJBOSS_AS_REMOTE_7.X
    mvn clean install -PGLASSFISH_MANAGED_3.1
    mvn clean install -PGLASSFISH_REMOTE_3.1
    mvn clean install -PTOMCAT_MANAGED_7_WELD
    mvn clean install -PJBOSS_AS_MANAGED_7.X
    mvn clean install -PTOMCAT_MANAGED_7_OWB

    Some of these profiles may have some test failures, but just try not to add any failures 🙂 since we only test regularly on JBoss AS7 and GlassFish – those are the two most spec compliant systems, respectively.

    #24706

    persapiens
    Participant

    I could run rewrite-parent with profile JBOSS_AS_MANAGED_7.X,
    but rewrite-integration-faces build fails 🙁

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project rewrite-integration-faces: An Ant BuildException has occured: Warning: Could not find file /home/marcelo/workspace/rewrite/integration-faces/test-harness/src/main/resources/jbossas-managed-standalone.xml to copy.
    [ERROR] around Ant part ...<copy todir="/home/marcelo/workspace/rewrite/integration-faces/target/container/jboss-as-7.1.1.Final/standalone/configuration" file="/home/marcelo/workspace/rewrite/integration-faces/test-harness/src/main/resources/jbossas-managed-standalone.xml"/>... @ 4:251 in /home/marcelo/workspace/rewrite/integration-faces/target/antrun/build-main.xml
    

    Well, we should add the following methods at org.ocpsoft.rewrite.faces.config.PhaseOperation:

    public static PhaseOperation<?> enqueueIgnorePostback(final Operation operation)
    {
    return enqueue(new IgnorePostbackOperation(operation));
    }

    public static PhaseOperation<?> enqueueIgnorePostback(final Operation operation, final int priority)
    {
    return enqueue(new IgnorePostbackOperation(operation), priority);
    }

    How could I test it? I don’t work with junit regularly, I’m a bit familiar with maven and jsf. I’m learning git too.

    #24713

    Strange, does this file exist? “/home/marcelo/workspace/rewrite/integration-faces/test-harness/src/main/resources/jbossas-managed-standalone.xml”

    Also, I’m not sure that adding a overloaded method names to PhaseOperation is what we want. I think maybe what would be preferred is:

    PhaseOperation.enqueue(...).onPostback(false);

    What do you think? Then any PhaseOperation can select wether or not it should operate onPostback().

    #24739

    I prefer Lincoln’s syntax suggestion. It’s more fluent and therefore more consistent with other parts of the Rewrite API.

    #24754

    persapiens
    Participant

    So, the method could be:

       
       /**
        * Check if operation should not run onPostback, using {@link IngorePostbackOperation}.
        */
       public Operation onPostback(boolean onPostback)
       {
           Operation result = this;
           
           if (!onPostback)
           {
               result = new IgnorePostbackOperation(result);
           }
           
           return result;
       }
    

    Lincoln, the generated file is:
    ‘/home/marcelo/workspace/rewrite/integration-faces/target/container/jboss-as-7.1.1.Final/standalone/configuration/jbossas-managed-standalone.xml’

    More, how could I write the test case?

    #24771

    Just a thought: Perhaps it would be simpler to add support for the “ignore postback” case directly into PhaseOperation? In this case the PhaseOperation could have a boolean field “onPostback” and check for postbacks in the corresponding method which executes the operation.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.

Comments are closed.