You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by pa...@wipro.com on 2006/12/18 12:50:40 UTC

Double click again.....

Hi All,
 
I had posted a similar query earlier to prevent double click of a form
button.
I could use Shale's <s:token> but i ran into compatibility issues
between RAD6.0.1 and Shale-core.jar1.0.3.
So i had to give it up and try another approach using Synchronizer Token
pattern as in sytuts.
Please help me fine tune it.Please go ahead to provide me any other
elegant approach.
I want to call the method generateSaveToken() from phaseListener.
Is it possible.????
 
Jsp Page
 
<h:form>

<h:inputText id="text1"/>

<h:inputHidden value="#{visit.saveToken}" />

<h:commandButton value="Submit" id="button1"
action="#{reqBean.actionMethod}" />

</h:form>

FacesConfig.xml

<managed-bean>

<description>Session bean that holds data and delegates needed by
request beans.</description>

<managed-bean-name>visit</managed-bean-name>

<managed-bean-class>com.acs.click.Visit</managed-bean-class>

<managed-bean-scope>session</managed-bean-scope>

</managed-bean>

<managed-bean>

<description>Some request bean.</description>

<managed-bean-name>reqBean</managed-bean-name>

<managed-bean-class>com.acs.click.RequestBean</managed-bean-class>

<managed-bean-scope>request</managed-bean-scope>

<managed-property>

<property-name>visit</property-name>

<value>#{sessionScope.visit}</value>

</managed-property>

</managed-bean>

Visit.java

public class Visit extends BaseBean {
 
 private long activeToken;
 private long receivedToken;
   
 public long getSaveToken() {
        return this.activeToken;
    }
 public void setSaveToken(long aToken) {
        this.receivedToken = aToken;
    }
  public long getActiveToken() {
  return activeToken;
 }
  public void setActiveToken(long activeToken) {
  this.activeToken = activeToken;
 }
 public long getReceivedToken() {
  return receivedToken;
 }
 public void setReceivedToken(long receivedToken) {
  this.receivedToken = receivedToken;
 }
   boolean tokensMatch() {
        return (this.activeToken == this.receivedToken);
    }

}

RequestBean.java

public class RequestBean extends BaseBean  {
  
  public String actionMethod() {
        // prevent identical requests from being processed
        String normalOutcome = "Google-NOT-OK";
        if (this.saveTokenIsInValid() ) 
            return this.logInvalidSaveAndReturn(normalOutcome);
      
        this.expireSaveToken();
              
        System.out.println("save token is valid.  attempting to
save....");
        try {
              // invoke some business logic here
        } catch (Exception exc) {
              this.generateSaveToken();
              return null;
        }
        this.generateSaveToken();
       return "success";
    }

BaseBean.java

public class BaseBean {
 
  protected void generateSaveToken() {
        System.out.println("generateSaveToken()");
        Random random = new Random();
        long token = random.nextLong();
        while (token == 0) {
            token = random.nextLong();
        }
        System.out.println("Save token generated =>"+ token);
        this.getVisit().setActiveToken(token);
        this.getVisit().setReceivedToken(0);
    }
 
        protected boolean saveTokenIsInValid() {
        
       System.out.println("saveTokenIsValid():\n active token: " +
this.getVisit().getActiveToken() + "\n recv'd token: " +
this.getVisit().getReceivedToken() );
     
        boolean isValid = this.getVisit().tokensMatch();
        return !isValid;
    }
    
        protected void expireSaveToken() {
        System.out.println("expireSaveToken()");
        this.getVisit().setActiveToken(0);
    }


      protected String logInvalidSaveAndReturn(String outcome) {
     
     System.out.println("User submitted a save request that was not " +
        "processed because the save token was not valid.  Returning
outcome: '" + outcome + "'.");
      
        return outcome;
    }


    // Used by JSF managed bean creation facility
    public Visit getVisit() {
     FacesContext context = FacesContext.getCurrentInstance();
     HttpSession session = (HttpSession)
context.getExternalContext().getSession(false);
     Visit visit = (Visit) session.getAttribute("visit");
     
        return visit;
    }


    // Used by JSF managed bean creation facility
    public void setVisit(Visit visit) {
     FacesContext context = FacesContext.getCurrentInstance();
     HttpSession session = (HttpSession)
context.getExternalContext().getSession(false);
     session.setAttribute("visit",visit);
    }

}

Best Regards,

Pallavi 



 

 
 
 

 

 

 
 



The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
 
www.wipro.com

RE: Sanbox: DojoSplitPane error - Some more Info

Posted by "Oellien, F (Frank)" <Fr...@intervet.com>.
Some of the methods in DojoSplitPane and DojoSplitPaneRenderer are
misspelled: get/setSplitOrientanation instead of
get/setSplitOrientation.
 
Furthermore, the Orientation part in the setProperties funtion of the
DojoContentPaneTag has to be changed from setIntegerProperty to
setStringProperty.
 
After all these changes, orientation can be set in the DojoSplitPane
component.
 
Regards
 
Frank


________________________________

	From: Oellien, F (Frank) 
	Sent: Mittwoch, 20. Dezember 2006 17:12
	To: 'MyFaces Discussion'
	Subject: Sanbox: DojoSplitPane error
	
	
	The DojoSplitPane component in the sandbox package seems to have
an error in DojoSplitPaneTag.java.
	 
	I receive an error set the setter method vor set
SplitOrientatation is not set in the tag file. Indeed when I look to the
DojoSplitPaneTag.java class the setter method is called setOrientation
instead of setSplitOrientation. This true for sandbox 1.1.4 and 1.1.5
	 
	Furthermore I can not set the styleClass attribute for the
layoutContentPane component: Everytime I receive an error that one of
the attributes can be null.
	 
	 
	Regards
	Frank


--------------------------------------
This message, including attachments, is confidential and may be privileged.
If you are not an intended recipient, please notify the sender then delete
and destroy the original message and all copies. You should not copy, forward
and/or disclose this message, in whole or in part, without permission of
the sender.
--------------------------------------

Sanbox: DojoSplitPane error

Posted by "Oellien, F (Frank)" <Fr...@intervet.com>.
The DojoSplitPane component in the sandbox package seems to have an
error in DojoSplitPaneTag.java.
 
I receive an error set the setter method vor set SplitOrientatation is
not set in the tag file. Indeed when I look to the DojoSplitPaneTag.java
class the setter method is called setOrientation instead of
setSplitOrientation. This true for sandbox 1.1.4 and 1.1.5
 
Furthermore I can not set the styleClass attribute for the
layoutContentPane component: Everytime I receive an error that one of
the attributes can be null.
 
 
Regards
Frank

--------------------------------------
This message, including attachments, is confidential and may be privileged.
If you are not an intended recipient, please notify the sender then delete
and destroy the original message and all copies. You should not copy, forward
and/or disclose this message, in whole or in part, without permission of
the sender.
--------------------------------------

Re: Double click again.....

Posted by Adrian Mitev <ad...@googlemail.com>.
You could just download the token's source code and use only the component
without the other features of shale-core

2006/12/18, pallavi.roy@wipro.com <pa...@wipro.com>:
>
>  Hi All,
>
> I had posted a similar query earlier to prevent double click of a form
> button.
> I could use Shale's <s:token> but i ran into compatibility issues between
> RAD6.0.1 and Shale-core.jar1.0.3.
> So i had to give it up and try another approach using Synchronizer Token
> pattern as in sytuts.
> Please help me fine tune it.Please go ahead to provide me any other
> elegant approach.
> I want to call the method generateSaveToken() from phaseListener.
> Is it possible.????
>
> *Jsp Page*
>
>
> <
> h:form>
>
> <h:inputText id="text1"/>
>
> <h:inputHidden value="#{visit.saveToken}" />
>
> <h:commandButton value="Submit" id="button1" action="#{
> reqBean.actionMethod}" />
>
> </h:form>
>
> *FacesConfig.xml*
>
> <
> managed-bean>
>
> <description>Session bean that holds data and delegates needed by request
> beans.</description>
>
> <managed-bean-name>visit</managed-bean-name>
>
> <managed-bean-class>com.acs.click.Visit</managed-bean-class>
>
> <managed-bean-scope>session</managed-bean-scope>
>
> </managed-bean>
>
> <managed-bean>
>
> <description>Some request bean.</description>
>
> <managed-bean-name>reqBean</managed-bean-name>
>
> <managed-bean-class>com.acs.click.RequestBean</managed-bean-class>
>
> <managed-bean-scope>request</managed-bean-scope>
>
> <managed-property>
>
> <property-name>visit</property-name>
>
> <value>#{sessionScope.visit}</value>
>
> </managed-property>
>
> </managed-bean>
>
> *Visit.java*
>
> public class Visit extends BaseBean {
>
>  private long activeToken;
>  private long receivedToken;
>
>  public long getSaveToken() {
>         return this.activeToken;
>     }
>  public void setSaveToken(long aToken) {
>         this.receivedToken = aToken;
>     }
>   public long getActiveToken() {
>   return activeToken;
>  }
>   public void setActiveToken(long activeToken) {
>   this.activeToken = activeToken;
>  }
>  public long getReceivedToken() {
>   return receivedToken;
>  }
>  public void setReceivedToken(long receivedToken) {
>   this.receivedToken = receivedToken;
>  }
>    boolean tokensMatch() {
>         return (this.activeToken == this.receivedToken);
>     }
>
> }
>
> *RequestBean.java*
>
> public class RequestBean extends BaseBean  {
>
>   public String actionMethod() {
>         // prevent identical requests from being processed
>         String normalOutcome = "Google-NOT-OK";
>         if (this.saveTokenIsInValid() )
>             return this.logInvalidSaveAndReturn(normalOutcome);
>
>         this.expireSaveToken();
>
>         System.out.println("save token is valid.  attempting to
> save....");
>         try {
>               // invoke some business logic here
>         } catch (Exception exc) {
>               this.generateSaveToken();
>               return null;
>         }
>         this.generateSaveToken();
>        return "success";
>     }
>
> *BaseBean.java*
>
> public class BaseBean {
>
>   protected void generateSaveToken() {
>         System.out.println("generateSaveToken()");
>         Random random = new Random();
>         long token = random.nextLong();
>         while (token == 0) {
>             token = random.nextLong();
>         }
>         System.out.println("Save token generated =>"+ token);
>         this.getVisit().setActiveToken(token);
>         this.getVisit().setReceivedToken(0);
>     }
>
>         protected boolean saveTokenIsInValid() {
>
>        System.out.println("saveTokenIsValid():\n active token: " +
> this.getVisit().getActiveToken() + "\n recv'd token: " + this.getVisit().getReceivedToken()
> );
>
>         boolean isValid = this.getVisit().tokensMatch();
>         return !isValid;
>     }
>
>         protected void expireSaveToken() {
>         System.out.println("expireSaveToken()");
>         this.getVisit().setActiveToken(0);
>     }
>
>
>       protected String logInvalidSaveAndReturn(String outcome) {
>
>      System.out.println("User submitted a save request that was not " +
>         "processed because the save token was not valid.  Returning
> outcome: '" + outcome + "'.");
>
>         return outcome;
>     }
>
>
>     // Used by JSF managed bean creation facility
>     public Visit getVisit() {
>      FacesContext context = FacesContext.getCurrentInstance();
>      HttpSession session = (HttpSession) context.getExternalContext
> ().getSession(false);
>      Visit visit = (Visit) session.getAttribute("visit");
>
>         return visit;
>     }
>
>
>     // Used by JSF managed bean creation facility
>     public void setVisit(Visit visit) {
>      FacesContext context = FacesContext.getCurrentInstance();
>      HttpSession session = (HttpSession) context.getExternalContext
> ().getSession(false);
>      session.setAttribute("visit",visit);
>     }
>
> }
>
> Best Regards,
>
> Pallavi
>
>
>
>
>
>
>
>
>
>
>
>
> The information contained in this electronic message and any attachments
> to this message are intended for the exclusive use of the addressee(s) and
> may contain proprietary, confidential or privileged information. If you are
> not the intended recipient, you should not disseminate, distribute or copy
> this e-mail. Please notify the sender immediately and destroy all copies of
> this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient
> should check this email and any attachments for the presence of viruses. The
> company accepts no liability for any damage caused by any virus transmitted
> by this email.
>
> www.wipro.com
>