4 Replies Latest reply on Jan 30, 2013 10:26 AM by Marek Schmidt

    partial-response xml displayed in browser on seam redirect after ajax request

    Charles Akalugwu Newbie

      I have a webapp for photos where users are able to like, dislike and add photos to favorites. Naturally, the users have to be logged in before these functions can be called.



      The JSF code for the like function is as follows:



      <h:form style="border-bottom: 1px solid #E8E8E8; padding-bottom: 20px; text-align: center;">
                                                                  <p:outputPanel rendered="#{not likeDislikePhoto.userLikesPhoto( viewPhoto.photo.id )}">
                                                                                       <h:commandButton value="I Like" style="cursor: pointer; padding: 10px; min-width: 90px;" styleClass="button buttoncolor">
                                                                                                <f:ajax event="click" listener="#{likeDislikePhoto.like( viewPhoto.photo.id, true )}" render="@form :votestats :ratingstats"/>
                                                                                      <h:commandButton value="I Dislike" style="cursor: pointer;padding: 10px; min-width: 90px; margin-left: 20px;" styleClass="button buttoncolor">
                                                                                                <f:ajax event="click" listener="#{likeDislikePhoto.like( viewPhoto.photo.id, false )}" render="@form :votestats :ratingstats"/>
                                                                  <p:outputPanel rendered="#{likeDislikePhoto.userLikesPhoto( viewPhoto.photo.id )}">
                                                                            <div class="like-fact">You rated this photo</div>
                                                                            <div style="display: none;" class="like-remove">
                                                                                      <h:commandLink value="Remove your like" styleClass="greenlink pointer">
                                                                                                <f:ajax event="click" listener="#{likeDislikePhoto.removeLike( viewPhoto.photo.id )}" render="@form :votestats :ratingstats"/>






      When the user clicks the like button, if they are not logged in, I would like to redirect them to the login page and after they log in, redirect them to the photo page they were on before clicking the like button. After logging in, I want the function to be executed.



      Below is the bean code for the like method:






          public String like( int photoId, boolean likeState ){
                                        if ( loggedInUser != null ) {
                                                  if( everythingElseOk){
                                              // perform the like
                                                            return "success";
                                                  } else {
                                                            return "failed";
                                                  Redirect.instance().setViewId( FacesContext.getCurrentInstance().getViewRoot().getViewId() );
                                                  Redirect.instance().setParameter("id", photoId );
                                                  Pages p = Pages.instance();
                                                  return "notLoggedIn";
                              catch( Exception e ){
                                        return "failed";

      The redirection and logging in all work fine but the problem is that due to the fact that I use the f:ajax for the like action, all sorts of jsf partial update params are added to the url of the redirected page. And worse, the inclusion of these parameters makes the page display <partial-response> xml as shown below:




          <update id="favestats">
          <span id="favestats" style="float: right; text-align: center; width: 110px;"> <div style="font-size: 30px;"> 4 </div> <div style="font-size: 11px;"> Favorites </div></span>
          <update id="j_idt114">
          <form id="j_idt114" name="j_idt114" method="post" action="/photo/116" enctype="application/x-www-form-urlencoded" style="border-bottom: 1px solid #E8E8E8; padding-bottom: 20px; text-align: center;"> <input type="hidden" name="j_idt114" value="j_idt114" /> <br /><span id="j_idt114:j_idt118"> <div class="fave-fact"> <div style="background: url('/img/favorite.png') no-repeat 10px 100%; height: 16px; margin-left: 10px;" align="center">You added this to favorites</div> </div> <div style="display: none;" class="fave-remove"><a id="j_idt114:j_idt120" href="#" onclick="mojarra.ab(this,event,'click',0,'@form favestats');return false" class="greenlink pointer">Remove from favorites</a> </div></span> </form>
          <update id="javax.faces.ViewState">
          <![CDATA[ -4743453278638707233:2218559108323062779 ]]>








      The url redirected to is:






      but all I want is:



      http://www.example.com/photo/55?c=4 (the c=4 is just conversation id parameter in seam apps and is normal).





      In addition, I am using the seam redirect functionality and in my components.xml, I have:



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





      My loginRedirector bean is shown below:




          public class LoginRedirector implements Serializable{
                    private static final long serialVersionUID = -3921511488811869974L;
                    Log log;
              private Redirect _redirect;
              private Identity _identity;
              private Redirect _savedRedirect;
              public void captureCurrentView() {
                  if (_identity != null && !_identity.isLoggedIn()) {
                      _savedRedirect = _redirect;
              public void returnToCapturedView()  {
                  if (_savedRedirect != null && _savedRedirect.getViewId() != null ) {



      What can I do to solve this problem?


      My project environment: Jboss seam 2.3.0 beta2, primefaces 3.4 RC1, JSF 2.1.11, JBoss AS 7.2


      Message was edited by: Charles Akalugwu