tags:

views:

228

answers:

1

Hello,

I'm using seam page navigation rules. and did not experience any problem with adding rules which redirect from one page to another. But since I designed my page views using those redirection simply don't happen anymore for those pages. Tried to define the rule to the view that gets included, then to the view that includes the others (which to me was making more sense) but none work. Is there anything special about page navigation in seam using included view-id ?

main.xhtml:

<h:outputLabel value="Details:"/>

<a4j:include viewId="contacts.xhtml" id="contactsDetails"/>

<page view-id="/*" login-required="true"> <navigation> <rule if="#{myBean.readyToSee}"> <redirect view-id="/see-contat.xhtml"/> </rule> </navigation> </page>

I'm using jsf, xhtml as my page views.

Thanks

+2  A: 

Its difficult for me to answer this question because I simply don't understand it. However I will try to guess what you are asking.

You have a page ie: /somePage.xhtml and inside that page you include some other pages.

I tend to write all my page navigation in pages.xml. I like having everything in one place, because it makes things cleaner and easier to maintain.

You can use wildcards also in the pages.xml file.

So you can do something like this.

<page login-required="true" view-id="/admin/*">
    <restrict>#{s:hasRole('orgadmin') or s:hasRole('sysadmin')}</restrict>
    <navigation from-action="#{userAdmin.editUser}">
        <redirect view-id="/admin/create_user.xhtml" />
    </navigation>

    <navigation from-action="#{applicationProcessAdmin.saveScheme}">
        <rule if-outcome="failure">
            <redirect view-id="/admin/processes.xhtml" />
        </rule>
    </navigation>
</page>

In the above example, I am using a wildcard to say that all navigation that happens from /admin/* that uses some specific action, should redirect to some page i have.

You can also be very specific with the pages

<page login-required="true" view-id="/officer/admin/contacts.xhtml">
    <begin-conversation join="true" />
    <navigation from-action="#{officerAdmin.saveContact}">
        <redirect/>
    </navigation>
</page>

If this doesn't help you, you need to clarify your question better.

Update

Try changing your

<page view-id="/*" login-required="true"> 
  <navigation> 
    <rule if="#{myBean.readyToSee}">   
       <redirect view-id="/see-contat.xhtml"/> 
    </rule> 
  </navigation> 
</page>

To this instead

<page view-id="/*" login-required="true"> 
  <navigation from-action="#{myBean.readyToSee}"> 
    <rule if="#{myBean.readyToSee}">   
       <redirect view-id="/see-contat.xhtml"/> 
    </rule> 
  </navigation> 
</page>

UPDATE 2

Does all your navigation fail? Or is it only some?

Try removing the /* on page view and replace with just *

If you do this will work:

@Name("myBean")
public class MyBean {
  public String doSomething() {
    return "success";
  } 
}

Now from your xhtml (Does not matter which include page it is from)

<!-- Depending on what button you are using, <h:form> is mandatory --> 
<h:form>
  <h:commandButton value="TEST" action="#{myBean.doSomething}" />
</h:form>

And in your pages xml

<page view-id="*">
  <navigation from-action="#{myBean.doSomething}">
<rule if-outcome="success">
  <redirect view-id="/test.xhtml" />
</rule>
  </navigation>
</page>

The above will work. If it does not, the error is somewhere else in your code.

Shervin
I have pretty much the same rule as you have defined here (no wildcard use) which worked perfectly.Then, instead of having a simple contacts.xhtml containing my all my contacts, I 'included' contacts.xhtml into another page view, called let's say main.xhtmlIndeed I moved the navigation rule into the page main.xhtml. but it stopped working.
Marc
It should always be the parent that you declare. So even if you include page FOO in page BAR, you have to create navigation from `BAR.xhtml` and not `FOO.xhtml`
Shervin
Which is what I have done. Trying on the child was simply a random attempt. The action is triggered from the child. I thought maybe this event isn't caught because it doesn't happen in the parent itself.Do you have some pages included in others? do you have some page rules on those? does it work?
Marc
Yes I have tons of includes. Show some relevant code. Show the xhtml and pages.xml and I will take a look.
Shervin
You have tons of includes using a4j include or are you doing it a different way ?I have just edited the question with my rule. this rule does work and redirect to my specified page. but only not using the a4j include.
Marc
@Marc: Look at update. Try that
Shervin
readyToSee is a boolean. not a method.I had tried <navigation from-action="#{myBean.getReady}"> getReady being a void method. which didn't make any difference.I aslo tried if-outcome="success", with getReady being a method returning String "success" if everything ok. which didn't work either. really I don't think my rule is/was wrong.I have now changed my xhtml pages, to NOT use any include where I need redirection, now having duplicates of code, but I really need to move on. will get back to this and post an answer descriebing what was the issue.
Marc
@Shervin if you could paste some of the code using <a4j:include> that you have written, and which you know does work with page redirection, I would be able to make sure I'm doing the right thing.Thanks for the help.
Marc
There is no point for me to show you code using `a4j:include`. We use it and it works just fine.The problem is in your pages.xml file somewhere, or the java side.Look update again.
Shervin
Your code perfectly makes sense. I need to investigate what's going wrong. but it's not those rules, as they have not changed. you perfectly answered my initial question : there is nothing different going on with page redirection when 'including' view ids. Thanks a lot for the patient help
Marc