1 Reply Latest reply on Apr 5, 2009 4:42 AM by gonorrhea

    Seam Not capturing view

    seamsvictom

      Hi,


      I am facing an issue with seam to capture the old view. Here is the scenario:


      I've configured this in components.xml


           <event type="org.jboss.seam.security.notLoggedIn">
             <action execute="#{redirect.captureCurrentView}"/>
           </event>
           <event type="org.jboss.seam.security.postAuthenticate">
             <action execute="#{redirect.returnToCapturedView}"/>
           </event>
      


      Now I've defined a page which requires login, here is that page's xml file (Note that I am using a separate pages.xml file for each page)



      <page xmlns="http://jboss.com/products/seam/pages"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.1.xsd"
           no-conversation-view-id="/pages/view-cart.xhtml"
           login-required="true">
           
           <param name="itemId" value="#{viewCartAction.itemId}" converterId="javax.faces.Long"/>
      </page>



      Now, I want if a person is not logged in and access view cart, he should be redirected to login page first and then straight to view cart after logging in. It works fine if i use s link like this:


      <s:link view="/pages/view-cart.xhtml">
         <f:param name="itemId" value="1222"/>
      </s:link>
      


      But now consider this scenario, At one page on click of a button, i outject a list of objects in conversation scope. Then I redirect the page to view-cart.xhtml page but in this case the user is not redirected to the login page, instead it is taken to view-cart directly :(


      Just to give an examlple in my another bean I've the code:


      //declared at top in class
      @out(required=false)
      private List<Item> items;
      
      //method
      public String buyItem(){
      items = someitemsList; //list of some items
      return "/pages/view-cart.xhtml";
      }


      Now when buyItems method is invoked, it tries to redirect to view-cart page, in this case user should have taken to the login page, but this is not the case, instead it is taken to view-cart page :(


      Does anybody know what am i doing wrong here?


      Any help will be appreciated.


      Thank you

        • 1. Re: Seam Not capturing view
          gonorrhea

          this is the pages.xml for the hotel booking example:


          have you tried using the same strategy as below (mainly the login-view-id in the pages tag and the login-required attribute for the page tag)?  you can also configure it such that all pages require login (using *).


          <?xml version="1.0" encoding="UTF-8"?>
          <pages xmlns="http://jboss.com/products/seam/pages"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd"
          
                 no-conversation-view-id="/main.xhtml"
                           login-view-id="/home.xhtml">
          
              <page view-id="/register.xhtml">
              
                  <action if="#{validation.failed}"
                     execute="#{register.invalid}"/>
              
                  <navigation>
                      <rule if="#{register.registered}">
                          <redirect view-id="/home.xhtml"/>
                      </rule>
                  </navigation>
                  
              </page>
          
              <page view-id="/home.xhtml">
              
                  <navigation>
                      <rule if="#{identity.loggedIn}">
                          <redirect view-id="/main.xhtml"/>
                      </rule>
                  </navigation>
                  
              </page>
              
              <page view-id="/password.xhtml"
                    login-required="true">
              
                  <navigation>
                      <rule if="#{changePassword.changed}">
                          <redirect view-id="/main.xhtml"/>
                      </rule>
                  </navigation>
                  
              </page>
          
              <page view-id="/main.xhtml" 
                    login-required="true">
              
                  <navigation from-action="#{hotelBooking.selectHotel(hot)}">
                      <redirect view-id="/hotel.xhtml"/>
                  </navigation>
                  
                  <navigation from-action="#{bookingList.cancel}">
                      <redirect/>
                  </navigation>
                  
              </page>
              
               <page view-id="/hotel.xhtml" 
                     conversation-required="true" 
                     login-required="true">
                    
                  <description>View hotel: #{hotel.name}</description>
                  
                  <navigation from-action="#{hotelBooking.bookHotel}">
                      <redirect view-id="/book.xhtml"/>
                  </navigation>
                  
              </page>
          
               <page view-id="/book.xhtml" 
                     conversation-required="true" 
                     login-required="true">
                    
                  <description>Book hotel: #{hotel.name}</description>
                  
                  <navigation from-action="#{hotelBooking.setBookingDetails}">
                      <rule if="#{hotelBooking.bookingValid}">
                          <redirect view-id="/confirm.xhtml"/>
                      </rule>
                  </navigation>
                  
              </page>
          
               <page view-id="/confirm.xhtml" 
                     conversation-required="true" 
                     login-required="true">
                    
                  <description>Confirm booking: #{booking.description}</description>
                  
                  <navigation from-action="#{hotelBooking.confirm}">
                      <redirect view-id="/main.xhtml"/>
                  </navigation>
                  
              </page>
              
              <page view-id="*">
              
                  <navigation from-action="#{identity.logout}">
                      <redirect view-id="/home.xhtml"/>
                  </navigation>
          
                  <navigation from-action="#{hotelBooking.cancel}">
                      <redirect view-id="/main.xhtml"/>
                  </navigation>
                  
              </page>
              
              <exception class="org.jboss.seam.security.NotLoggedInException">
                  <redirect view-id="/home.xhtml">
                      <message severity="warn">You must be logged in to use this feature</message>
                  </redirect>
              </exception>
          
          </pages>