Its a problem whenever your form submits don't result in a different view
being display. I had a similar problem. It is a hack but its the only way
I've foundl. All my backing beans inherit from an common abstract class so I
just added a utility method that gets called whenever an action navigates
back to the same view. I just update the first instance of token I find the
view root. I think its a fair assumption that there should only be one
token.

  /**
    * Attribute key under which the shale token stores its value.
    */
   private static final String TOKEN_ATTRIBUTE_KEY
                                       = "
org.apache.shale.Token.TOKEN_VALUE";

   /**
    * Resets the current shale token so future submits
    * are allowed.
    */
   protected void resetToken() {
       UIViewRoot root = FacesContext.getCurrentInstance().getViewRoot();
       Token token = findToken(root);
       if (token != null) {
           token.getAttributes().remove(TOKEN_ATTRIBUTE_KEY);
       }
   }

   /**
    * Returns the first Token instance found in the JSF UI
    * tree.
    * @param component root of the component tree to search for token
    * @return first component of type [EMAIL PROTECTED] Token}
    */
   @SuppressWarnings("unchecked")
   private Token findToken(UIComponent component) {
       List<UIComponent> children = component.getChildren();
       for (UIComponent child : children) {
           if (child instanceof Token) {
               return (Token) child;
           }
           Token token = findToken(child);
           if (token != null) {
               return token;
           }
       }
       return null;
   }

On 7/6/07, Costa Basil <[EMAIL PROTECTED]> wrote:

Hi,

I am trying to use s:token and I have the following scenario where I think
token doesn't behave as I expect (I accept I might be wrong). In a few words
the token value is not refreshed as I expected.

I use shale 1.0.3, myfaces 1.1.5. The org.apache.shale.component.Tokenclass is 
the same in shale
1.0.3 and 1.0.4 (except comments).

The page that I have contains a table and a link for deleting the rows
from the table. I select a row by clicking on it then I click on the delete
link to delete the row. All these actions are posts to the same page.
Selecting a row is an "immediate" event and it bypasses any validation (in
the action listener method I call getFacesContext().renderResponse() to
bypass any validation). The delete link has immediate set to false. The
problem is that after I delete one row, the value of the token is not
refreshed, and I cannot delete any other row!

I would have thought that after the validation is passed the token value
should be refreshed but that is not the case. The token value is saved in
the component attributes map and the attributes map is saved and restored
to/from the state, and then used in Token.getToken(). One could trigger
the refresh by removing the TOKEN_ATTRIBUTE_KEY attribute but I think it is
a hack.

Any thoughts?

Thanks



---------------------------------
All new Yahoo! Mail
---------------------------------
Get news delivered. Enjoy RSS feeds right on your Mail page.

Reply via email to