11 Replies Latest reply on Jan 11, 2008 10:47 AM by mmichalek

    Wildcard for pages action

    mustaghattack

      I'd like to use wildcard in the from-action attribute like this :

      <navigation from-action="#{logoEditor.editLogo(*)}">
       <redirect view-id="/logo/edit.xhtml"/>
      </navigation>
      


      So each time I use logoEditor.editLogo whatever the parameter is I'm redirected to edit.xhtml.

      I tried with 1.2.1 GA but it doesn't work. I didn't find anything like that in JIRA as well.

      Thanks

        • 1. Re: Wildcard for pages action
          monkeyden

          Did you try it without the per ens and the star?

          • 2. Re: Wildcard for pages action
            monkeyden

            ....which would be agnostic of the value passed.

            • 3. Re: Wildcard for pages action
              monkeyden

              Sorry for being so noisy, but on second look, that's not a page action. It's a navigation rule. A page action would be:

              <page view-id="/someFile.xhtml" action="#{logoEditor.editLogo(*)"/>

              • 4. Re: Wildcard for pages action
                mustaghattack

                Yes it's a navigation rule.
                Thanks anyway.

                • 5. Re: Wildcard for pages action
                  mmichalek

                  Is there any interest in this? I also thought this made sense because from-action's that involve parameter names seem a bit brittle.

                  • 6. Re: Wildcard for pages action

                    could you please rephrase your question and maybe give some detailed example?
                    I have no idea what you wanna do...

                    • 7. Re: Wildcard for pages action
                      mmichalek

                      I'm asking if there's any community interest in supporting wildcards in the from-action in pages.xml.

                      For example:
                      pages.xml:

                      <navigation from-action="#{logoEditor.editLogo(*)}">
                       <redirect view-id="/edit.xhtml"/>
                      </navigation>
                      

                      logoPage.xhtml:
                      <h:commandLink value="LinkOne" action="#{logoEditor.editLogo(goodLogo)}"/>
                      
                      <h:commandLink value="LinkTwo" action="#{logoEditor.editLogo(badLogo)}"/>
                      


                      For this example, both LinkOne and LinkTwo would navigate to /edit.xhtml because both of the actions match the #{logoEditor.editLogo(*)} pattern.

                      In other words, the specific variable names on an action don't matter when the navigation is evaluated because pages.xml specifies a wildcard (*) for the parameters.

                      • 8. Re: Wildcard for pages action
                        pmuir

                        File a JIRA and try to collect votes for it.

                        • 9. Re: Wildcard for pages action
                          mmichalek

                          Thanks. JIRA opened: http://jira.jboss.org/jira/browse/JBSEAM-2481

                          Two other quick things on this:
                          1) One thing that surprised me when I first used Seam navigation was that you cannot define navigation cases based on the outcome of an action. I know that rules can operate on outcomes, but I like to define navigation cases based on a known action and then have rules which inspect the state within that case. (Otherwise I get strange behavior where a user can back up and click through a wizard using any links because the state to satisfy the rules in still in the conversation).

                          Here's a code snippet that demonstrates what I mean (in Pages.navigate). Does something like this make sense in general for Seam?


                           Navigation navigation = page.getNavigations().get(actionExpression);
                           if (navigation==null)
                           {
                           // New Code here:
                           if (actionOutcomeValue != null) {
                           navigation = page.getNavigations().get(actionOutcomeValue);
                           }
                          



                          2) For anyone interested in doing something like this, you can always provide a custom "org.jboss.seam.navigation.pages" component. For example, I have:
                          @Scope(ScopeType.APPLICATION)
                          @BypassInterceptors
                          @Name("org.jboss.seam.navigation.pages")
                          @Install(precedence=APPLICATION, classDependencies="javax.faces.context.FacesContext")
                          public class Pages extends org.jboss.seam.navigation.Pages {
                          
                           @Override
                           public boolean navigate(FacesContext context, String actionExpression, String actionOutcomeValue) {...}
                          }
                          




                          • 10. Re: Wildcard for pages action
                            pmuir

                            (1) Whats wrong with

                            <navigation from-action="#{foo.bar}">
                             <rule if-outcome="baz">
                             <redirect view-id="/baz.xhtml" />
                             </rule>
                            </navigation>


                            • 11. Re: Wildcard for pages action
                              mmichalek

                              There's nothing wrong with that.

                              However, it's not possible for me to use from-action as defined by Seam because most of my actions are being passed into facelet components as strings. Inside the facelet component, I execute the action at the right time:

                              action="#{componentUtils.invokeAction(action)}"
                              


                              This causes a problem with navigation because all of the action expressions look the same!

                              Also, we are designing our actions to be very granular and only expose one execute() method. Action.exeucte() either returns NULL (failure) or it's component name (success). (This seems a lot more simple than asking developers to return different arbitrary outcomes). When an action succeeds and returns it's component name, I will want to be able to conditionally navigate based on the state of the system.

                              For example:

                               <navigation from-action="searchAction">
                               <rule if="#{searchManager.searchResults.size == 1}">
                               <redirect view-id="/showRecord.xhtml" />
                               </rule>
                               <rule if="#{searchManager.searchResults.size > 1}">
                               <redirect view-id="/SearchResults.xhtml" />
                               </rule>
                               </navigation>
                              


                              Let me know what you think of all of this and if you see any inherent problems with these approaches.

                              Thanks,
                              Mark