wood burning stoves 2.0*
The moose likes Struts and the fly likes validation problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Reply locked New topic
Author

validation problem

Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

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
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

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

Joined: Feb 15, 2005
Posts: 4864
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

Joined: Aug 01, 2006
Posts: 401

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

Joined: Feb 15, 2005
Posts: 4864
In the JSP:

In the Action:
Shally Raina
Greenhorn

Joined: Jun 26, 2008
Posts: 8
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!!
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

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 ..


Thanks & Regards
Sidharth Pallai
Shally Raina
Greenhorn

Joined: Jun 26, 2008
Posts: 8
[Thread hijack removed]
[ June 26, 2008: Message edited by: Bear Bibeault ]
Shally Raina
Greenhorn

Joined: Jun 26, 2008
Posts: 8
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

Joined: Feb 15, 2005
Posts: 4864
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validation problem
 
Similar Threads
validatation should not work for some actions
No validation before LookupDispatchAction
history.back problem
how to tell when ie 7 is done rendering?
skip validation