Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

validation problem

 
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi all,

I am using validation 'required' on one JSP and it has 2 buttons named Next and Back. I want my required or any other validation mentioned in validation.xml fire only when user clicks on Next button (implemented by me)but not when user clicks on Back button. Is there any solution to this problem?

Regards,
Rahul
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
One solution would be to use an html:cancel tag for your back button. Struts will skip validation when this button is pressed. In your action, you can tell whether the cancel button was pressed by calling the isCancelled() method on your action's superclass.

An important point to remember, though, is that if you're using Struts version 1.2.9 or later, you must specify cancellable="true" in your action mapping.
 
Rauhl Roy
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Originally posted by Merrill Higginson:
One solution would be to use an html:cancel tag for your back button. Struts will skip validation when this button is pressed. In your action, you can tell whether the cancel button was pressed by calling the isCancelled() method on your action's superclass.

An important point to remember, though, is that if you're using Struts version 1.2.9 or later, you must specify cancellable="true" in your action mapping.


Thaks for your reply. But ..
I am already using cancel button along with Next, Back buttons. And for cancel, I am already using isCancelled() method in action .. so how can I use it twice. please let me know if there is any solution.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Both buttons could still be html:cancel buttons. You could add a hidden field to your form and then use the onclick event of the buttons to set the hidden field to different values depending on which button was pressed. You could then use the value of the hidden field in your action class to determine which cancel button was pressed.

Another solution would be to make the back button a link rather than a submit button. I'm guessing that if the user hits the back button, you don't care about preserving any of the data she might have entered or changed on the form. If it has to be a button, you can use the html:button tag with an onclick event using JavaScript to navigate to the previous page.
[ September 08, 2007: Message edited by: Merrill Higginson ]
 
Rauhl Roy
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Originally posted by Merrill Higginson:
Both buttons could still be html:cancel buttons. You could add a hidden field to your form and then use the onclick event of the buttons to set the hidden field to different values depending on which button was pressed. You could then use the value of the hidden field in your action class to determine which cancel button was pressed.

Another solution would be to make the back button a link rather than a submit button. I'm guessing that if the user hits the back button, you don't care about preserving any of the data she might have entered or changed on the form. If it has to be a button, you can use the html:button tag with an onclick event using JavaScript to navigate to the previous page.

[ September 08, 2007: Message edited by: Merrill Higginson ]



First One may be useful for me because when i click on Back button, user entered values in the privious pages should appear.

So, can you please give me some sample code for the fisrt solution[hidden values]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
In the JSP:

In the Action:
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Thanks a lot for your reply to the mentioned query....
really it was of great help to me as i was stuck with the same problem...
great job!!!
thanks again!!
 
Ranch Hand
Posts: 137
Hibernate Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hello Rahul & Shally,

There seems another solution to your problem which could be rectified if make Validation nullable for the event upon clicking "Next".This could done if you have a property for the next nutton input have a specified value on click, so that the ActionForm could identify it. Based on the value set to the form property, you can configure the validate method to have ActionErrors to null.
Like ..
 
Shally Raina
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
[Thread hijack removed]
[ June 26, 2008: Message edited by: Bear Bibeault ]
 
Shally Raina
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
posted Today 3:19 PM
--------------------------------------------------------------------------------
Hi,

I am having problems with "validateUrl" method of org.apache.struts.validator.FieldChecks. I have following validation configured in my "validation.xml" for validating a URL in struts farmework.

<field property="instCustomerServiceURL" depends="url">
<arg key="InstitutionFormBean.instCustomerServiceURL"/>
<var>
<var-name>allow2slashes</var-name>
<var-value>true</var-value>
</var>
<var>
<var-name>nofragments</var-name>
<var-value>true</var-value>
</var>
<var>
<var-name>schemes</var-name>
<var-value>http,https,telnet,file</var-value>
</var>
</field>
But for some reason, I am always getting an error that this is not a valid URL and I wonder what could be the reason. This is how rule looks in "validator-rules.xml"

<validator name="url"
classname="org.apache.struts.validator.FieldChecks"
method="validateUrl"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.url"/>

Please guide me in this regard as i have done all hits and trials
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Shally,

Because these forums are searchable, we try to make it so the topic of a posting thread is descriptive of the problem discussed in that thread, and to keep the postings in that thread to the topic at hand. Bear removed a previous post of yours because it didn't pertain to the specific topic being discussed in this thread. Your last post also does not pertain to the topic of this thread.

I see you've posted this question to a different thread appropriately titled, so I'm closing this thread.
[ June 30, 2008: Message edited by: Merrill Higginson ]
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic