|
View:
New views
20 Messages
—
Rating Filter:
Alert me
|
| < Prev | 1 - 2 | Next > |
|
|
Struts 2 ValidationHello People,
i´m using the struts 2 in a project and i´m with a problem on the validation. When i try validate a form, the struts say the validation failed, even when the field is with correct value, in addition, it is not going back to the field with the old value here is my struts.xml. The action is the Cliente_insert: <package name="cliente" namespace="/" extends="struts-default"> <default-interceptor-ref name="defaultStack"/> <action name="Cliente_input" > <result >/cliente/inputCliente.jsp</result> </action> <action name="Cliente_edit" class="br.com.robson.modelo.ClienteAction" method="editar"> <interceptor-ref name="paramsPrepareParamsStack" /> <result >/cliente/editCliente.jsp</result> </action> <action name="Cliente_list" class="br.com.robson.modelo.ClienteAction" method="listar"> <result name="success">/cliente/listaClientes.jsp</result> </action> <action name="Cliente_insert" class="br.com.robson.modelo.ClienteAction" method="inserir"> <interceptor-ref name="validationWorkflowStack"/> <result name="input">/cliente/inputCliente.jsp</result> <result name="success" type="redirect">Cliente_list.action</result> </action> <action name="Cliente_delete" class="br.com.robson.modelo.ClienteAction" method="deletar"> <result name="success" type="redirect">Cliente_list.action</result> </action> <action name="Cliente_update" class="br.com.robson.modelo.ClienteAction" method="atualizar"> <result name="success" type="redirect">Cliente_list.action</result> </action> </package> Here is my validation archive: <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> <validators> <!-- <field name="nome"> <field-validator type="required"> true <message> O campo nome é obrigatório </message> </field-validator> </field> --> <field name="telefone"> <field-validator type="required"> true <message> O campo telefone é obrigatório </message> </field-validator> <field-validator type="stringlength"> true 6 14 <message> O campo telefone deve ter entre 6 e 14 caracteres </message> </field-validator> </field> </validators> here is my jsp: <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page import="br.com.robson.modelo.Cliente" %> <%@page import ="java.util.*" %> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html:html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <script language="javascript"> </script> </head> <body> Novo Cliente <s:debug/> <s:form action="Cliente_insert.action" method="POST" > <s:textfield name="idCli" label="Id" /> <s:textfield name="nome" label="Nome"/> <s:textfield name="telefone" label="Ielefone"/> <s:submit></s:submit> </s:form> </body> </html:html> I hope you can help me Hugs! |
|
|
dynamic return when validation failedHello,
I'm new to struts2, and learning the validation in struts 2 at the moment. I'm not able to get the validation work in the way I want in the webflow (or wizard kind of page) design. Everytime when validation failed, it always return to INPUT page, I wondering is there a way I can tell struts return to different result page depand on what validation failed. For e.g, I got page1.jsp, page2.jsp both are calling the same action, when page1 submit and the validation failed, I want it to go back to page1, if page2 submit I want to control it to go back to page2 if the validation fail. What I can possible think of the solutions right now is write my own custom validation interceptor which allow to dynamic set where to return. Another solution I'm not sure whether I can achive or not, for e.g below is the configuration of my action <action name="MyAction" class="MyAction"> <result name="page1">/WEB-INF/pages/page1.jsp</result> <result name="page2">/WEB-INF/pages/page2.jsp</result> <result name="input">${input}</result> </action> In the action I want to get the value of result name="page1" or "page2", is it possible? If so then I can pass it to ${input} Or is there any other better way to solve this? Regards Louis |
|
|
Re: dynamic return when validation failedOne way would be to pass a hidden parameter that tells you which page you
came from. In page1.jsp form you could add: <s:hidden name="page" value="page1" /> You would need to add a setter and getter in you action for page variable. Then your result could be: <result name="input">/WEB-INF/pages/${page}.jsp</result> Another way would to have different actions defined for each page so they know where to return to: <action name="MyActionPage1" class="MyAction"> <result name="page1">/WEB-INF/pages/page1.jsp</result> <result name="page2">/WEB-INF/pages/page2.jsp</result> <result name="input">/WEB-INF/pages/page1.jsp</result> </action> <action name="MyActionPage2" class="MyAction"> <result name="page1">/WEB-INF/pages/page1.jsp</result> <result name="page2">/WEB-INF/pages/page2.jsp</result> <result name="input">/WEB-INF/pages/page2.jsp</result> </action> On Wed, Jul 8, 2009 at 4:05 AM, <mailtolouis2020-struts@...> wrote: > Hello, > > I'm new to struts2, and learning the validation in struts 2 at the moment. > > I'm not able to get the validation work in the way I want in the webflow > (or wizard kind of page) design. Everytime when validation failed, it always > return to INPUT page, I wondering is there a way I can tell struts return to > different result page depand on what validation failed. > > For e.g, I got page1.jsp, page2.jsp both are calling the same action, when > page1 submit and the validation failed, I want it to go back to page1, if > page2 submit I want to control it to go back to page2 if the validation > fail. > > What I can possible think of the solutions right now is write my own custom > validation interceptor which allow to dynamic set where to return. > > Another solution I'm not sure whether I can achive or not, for e.g below is > the configuration of my action > > > <action name="MyAction" class="MyAction"> > <result name="page1">/WEB-INF/pages/page1.jsp</result> > <result name="page2">/WEB-INF/pages/page2.jsp</result> > <result name="input">${input}</result> > </action> > > In the action I want to get the value of result name="page1" or "page2", is > it possible? If so then I can pass it to ${input} > > Or is there any other better way to solve this? > > > Regards > Louis |
|
|
Re: dynamic return when validation failedHi,
Thanks for the reply, I try not to hardcode any file name in the jsp, prefer to put it in the struts config file, but don't know how to get the value out of it. Regards Louis ________________________________ From: Greg Lindholm <greg.lindholm@...> To: Struts Users Mailing List <user@...> Sent: Wednesday, July 8, 2009 2:46:00 PM Subject: Re: dynamic return when validation failed One way would be to pass a hidden parameter that tells you which page you came from. In page1.jsp form you could add: <s:hidden name="page" value="page1" /> You would need to add a setter and getter in you action for page variable. Then your result could be: <result name="input">/WEB-INF/pages/${page}.jsp</result> Another way would to have different actions defined for each page so they know where to return to: <action name="MyActionPage1" class="MyAction"> <result name="page1">/WEB-INF/pages/page1.jsp</result> <result name="page2">/WEB-INF/pages/page2.jsp</result> <result name="input">/WEB-INF/pages/page1.jsp</result> </action> <action name="MyActionPage2" class="MyAction"> <result name="page1">/WEB-INF/pages/page1.jsp</result> <result name="page2">/WEB-INF/pages/page2.jsp</result> <result name="input">/WEB-INF/pages/page2.jsp</result> </action> On Wed, Jul 8, 2009 at 4:05 AM, <mailtolouis2020-struts@...> wrote: > Hello, > > I'm new to struts2, and learning the validation in struts 2 at the moment. > > I'm not able to get the validation work in the way I want in the webflow > (or wizard kind of page) design. Everytime when validation failed, it always > return to INPUT page, I wondering is there a way I can tell struts return to > different result page depand on what validation failed. > > For e.g, I got page1.jsp, page2.jsp both are calling the same action, when > page1 submit and the validation failed, I want it to go back to page1, if > page2 submit I want to control it to go back to page2 if the validation > fail. > > What I can possible think of the solutions right now is write my own custom > validation interceptor which allow to dynamic set where to return. > > Another solution I'm not sure whether I can achive or not, for e.g below is > the configuration of my action > > > <action name="MyAction" class="MyAction"> > <result name="page1">/WEB-INF/pages/page1.jsp</result> > <result name="page2">/WEB-INF/pages/page2.jsp</result> > <result name="input">${input}</result> > </action> > > In the action I want to get the value of result name="page1" or "page2", is > it possible? If so then I can pass it to ${input} > > Or is there any other better way to solve this? > > > Regards > Louis |
|
|
Re: Struts 2 ValidationSomeone can solve my problem? the validator always say the validation failed :(
![]() ![]() ![]() |
|
|
Re: dynamic return when validation failedThere is nothing in a request that will tell you which page you came from
unless you put it there (as with the hidden parameter). If you don't like that then use the multiple actions so the action name tells you where the request came from (and where to go back). On Wed, Jul 8, 2009 at 11:05 AM, <mailtolouis2020-struts@...> wrote: > Hi, > > Thanks for the reply, I try not to hardcode any file name in the jsp, > prefer to put it in the struts config file, but don't know how to get the > value out of it. > > > > Regards > Louis > > > > ________________________________ > From: Greg Lindholm <greg.lindholm@...> > To: Struts Users Mailing List <user@...> > Sent: Wednesday, July 8, 2009 2:46:00 PM > Subject: Re: dynamic return when validation failed > > One way would be to pass a hidden parameter that tells you which page you > came from. > In page1.jsp form you could add: > <s:hidden name="page" value="page1" /> > You would need to add a setter and getter in you action for page variable. > Then your result could be: > <result name="input">/WEB-INF/pages/${page}.jsp</result> > > Another way would to have different actions defined for each page so they > know where to return to: > > <action name="MyActionPage1" class="MyAction"> > <result name="page1">/WEB-INF/pages/page1.jsp</result> > <result name="page2">/WEB-INF/pages/page2.jsp</result> > <result name="input">/WEB-INF/pages/page1.jsp</result> > </action> > <action name="MyActionPage2" class="MyAction"> > <result name="page1">/WEB-INF/pages/page1.jsp</result> > <result name="page2">/WEB-INF/pages/page2.jsp</result> > <result name="input">/WEB-INF/pages/page2.jsp</result> > </action> > > On Wed, Jul 8, 2009 at 4:05 AM, <mailtolouis2020-struts@...> wrote: > > > Hello, > > > > I'm new to struts2, and learning the validation in struts 2 at the > moment. > > > > I'm not able to get the validation work in the way I want in the webflow > > (or wizard kind of page) design. Everytime when validation failed, it > always > > return to INPUT page, I wondering is there a way I can tell struts return > to > > different result page depand on what validation failed. > > > > For e.g, I got page1.jsp, page2.jsp both are calling the same action, > when > > page1 submit and the validation failed, I want it to go back to page1, if > > page2 submit I want to control it to go back to page2 if the validation > > fail. > > > > What I can possible think of the solutions right now is write my own > custom > > validation interceptor which allow to dynamic set where to return. > > > > Another solution I'm not sure whether I can achive or not, for e.g below > is > > the configuration of my action > > > > > > <action name="MyAction" class="MyAction"> > > <result name="page1">/WEB-INF/pages/page1.jsp</result> > > <result name="page2">/WEB-INF/pages/page2.jsp</result> > > <result name="input">${input}</result> > > </action> > > > > In the action I want to get the value of result name="page1" or "page2", > is > > it possible? If so then I can pass it to ${input} > > > > Or is there any other better way to solve this? > > > > > > Regards > > Louis > |
|
|
Re: dynamic return when validation failedGreg Lindholm wrote:
> There is nothing in a request that will tell you which page you came from > unless you put it there (as with the hidden parameter). While this is mostly true, it's not 100% true. HTTP has a "referer" (yes, misspelled in the spec) field so most of the time you can know from where a link came or a post was posted (assuming this value is provided by the browser). Note, all it provides is the URL of that previous page, so if that's not specific enough you're still SOL. -Dale --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: dynamic return when validation failedThe referer header will contain the URL of the last request, which will be
the action URL not the jsp page that rendered the result. So this wouldn't help the OP if I understood his problem. On Wed, Jul 8, 2009 at 11:50 AM, Dale Newfield <dale@...> wrote: > Greg Lindholm wrote: > >> There is nothing in a request that will tell you which page you came from >> unless you put it there (as with the hidden parameter). >> > > While this is mostly true, it's not 100% true. HTTP has a "referer" (yes, > misspelled in the spec) field so most of the time you can know from where a > link came or a post was posted (assuming this value is provided by the > browser). Note, all it provides is the URL of that previous page, so if > that's not specific enough you're still SOL. > > -Dale > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > > |
|
|
Re: dynamic return when validation failedGreg Lindholm wrote:
> The referer header will contain the URL of the last request, which will be > the action URL not the jsp page that rendered the result. So this wouldn't > help the OP if I understood his problem. I think you misunderstand what the referer field contains. It'll be the url that was displaying in the address field on the page from which the form was submitted. http://en.wikipedia.org/wiki/HTTP_referrer Note that it can be forged, etc. -Dale --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: dynamic return when validation failedwhat I mean is since in the action I already define the result, which has the jsp name, if struts2 provide a way that I can get this info, then I can set it to ${input} easily.
E.g if there is something like xxxx.getResult("page1") and it give me the value "/WEB-INF/pages/page1.jsp" then this solve my problem, so I don't need to store another hidden value in the jsp. <action name="MyAction" class="MyAction"> <result name="page1">/WEB-INF/pages/page1.jsp</result> <result name="page2">/WEB-INF/pages/page2.jsp</result> <result name="input">${input}</result> </action> regards Louis ________________________________ From: Greg Lindholm <greg.lindholm@...> To: Struts Users Mailing List <user@...> Sent: Wednesday, July 8, 2009 5:52:25 PM Subject: Re: dynamic return when validation failed The referer header will contain the URL of the last request, which will be the action URL not the jsp page that rendered the result. So this wouldn't help the OP if I understood his problem. On Wed, Jul 8, 2009 at 11:50 AM, Dale Newfield <dale@...> wrote: > Greg Lindholm wrote: > >> There is nothing in a request that will tell you which page you came from >> unless you put it there (as with the hidden parameter). >> > > While this is mostly true, it's not 100% true. HTTP has a "referer" (yes, > misspelled in the spec) field so most of the time you can know from where a > link came or a post was posted (assuming this value is provided by the > browser). Note, all it provides is the URL of that previous page, so if > that's not specific enough you're still SOL. > > -Dale > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > > |
|
|
Re: dynamic return when validation failed> Greg Lindholm wrote:
Not sure why you think I don't understand referer. In a struts app what you
> >> The referer header will contain the URL of the last request, which will be >> the action URL not the jsp page that rendered the result. So this wouldn't >> help the OP if I understood his problem. >> > > I think you misunderstand what the referer field contains. It'll be the > url that was displaying in the address field on the page from which the form > was submitted. http://en.wikipedia.org/wiki/HTTP_referrer Note that it > can be forged, etc. > > see in the address field is the "action URL" (e.g. http://host/MyAction.action) you don't ever see the JSP page name that rendered the page. The OP seemed to be looking for the name of the jsp page so don't see how this would help. |
|
|
Re: dynamic return when validation failedHi...
Try to get the Ian Roughley's "Starting Struts2 online" ebook for free, and study "PRODUCTIVITY TIPS" -> "Re-Using Action Configurations"... and see if there are some other tips for you. HTH 2009/7/8 Greg Lindholm <greg.lindholm@...> > > Greg Lindholm wrote: > > > >> The referer header will contain the URL of the last request, which will > be > >> the action URL not the jsp page that rendered the result. So this > wouldn't > >> help the OP if I understood his problem. > >> > > > > I think you misunderstand what the referer field contains. It'll be the > > url that was displaying in the address field on the page from which the > form > > was submitted. http://en.wikipedia.org/wiki/HTTP_referrer Note that it > > can be forged, etc. > > > > > Not sure why you think I don't understand referer. In a struts app what you > see in the address field is the "action URL" (e.g. > http://host/MyAction.action) you don't ever see the JSP page name that > rendered the page. The OP seemed to be looking for the name of the jsp page > so don't see how this would help. > -- Atentamente Óscar Álvarez Vielma (09) 8416 4052 |
|
|
Re: dynamic return when validation failed2009/7/8 Oscar Alvarez <oialvarez@...>
> Hi... > > Try to get the Ian Roughley's "Starting Struts2 online" ebook for free, and > study "PRODUCTIVITY TIPS" -> "Re-Using Action Configurations"... and see if > there are some other tips for you. > And of course "PRODUCTIVITY TIPS" -> "Use Pattern Matching Wildcards in Configurations" too. > > HTH > > 2009/7/8 Greg Lindholm <greg.lindholm@...> > > > Greg Lindholm wrote: >> > >> >> The referer header will contain the URL of the last request, which will >> be >> >> the action URL not the jsp page that rendered the result. So this >> wouldn't >> >> help the OP if I understood his problem. >> >> >> > >> > I think you misunderstand what the referer field contains. It'll be the >> > url that was displaying in the address field on the page from which the >> form >> > was submitted. http://en.wikipedia.org/wiki/HTTP_referrer Note that it >> > can be forged, etc. >> > >> > >> Not sure why you think I don't understand referer. In a struts app what >> you >> see in the address field is the "action URL" (e.g. >> http://host/MyAction.action) you don't ever see the JSP page name that >> rendered the page. The OP seemed to be looking for the name of the jsp >> page >> so don't see how this would help. >> > > > > -- > Atentamente > Óscar Álvarez Vielma > (09) 8416 4052 > -- Atentamente Óscar Álvarez Vielma (09) 8416 4052 |
|
|
Re: dynamic return when validation failedGreg Lindholm wrote:
> Not sure why you think I don't understand referer. I already quoted the bits that illustrate this perceived misunderstanding, but since you apparently want me to be more specific: >> Greg Lindholm wrote: >>> The referer header will contain the URL of the last request It won't contain the url of the last request. The last request (chronologically, since you don't specify any other binding for 'last') was likely an image or style sheet or something to fill in something on the previously rendered page, or even something in another tab. >>> which will be the action URL not the jsp page that rendered the >>> result. This is completely dependent upon how you handle posts. If you use the post-redirect style, it won't be the "action url" (I'm not sure what you mean by that phrase, but I assume you're differentiating those urls from ones that are not side-effecting), but the GET url that resulted in the display of the form. Assuming post-redirect-only-if-successful, then it'll be the url of the step before this one: "submit-multi-page-form-step-2" when the step that's failing validation is "submit-multi-page-form-step-3" (or "submit-multi-page-form-3" if this step failed validation again, which illustrates where this path will break down). >>> So this wouldn't help the OP if I understood his problem. The problem is that the OP doesn't understand his problem. If the validation step knows what the result page should be, he shouldn't be returning "input", but rather the name of the logical step to be rendered. He's right that the code shouldn't need to know what jsp page renders that step, just the logical name of the page, fleshed out in the .xml file. -Dale --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: dynamic return when validation failed Dale Newfield <dale@...> wrote:
> Greg Lindholm wrote: > > Not sure why you think I don't understand referer. > > I already quoted the bits that illustrate this perceived misunderstanding, > but since you apparently want me to be more specific: > Actually I just wanted to move off the whole referer topic since It was not likely going to be of any help to the OP. > > > Greg Lindholm wrote: >>> >>>> The referer header will contain the URL of the last request >>>> >>> > It won't contain the url of the last request. The last request > (chronologically, since you don't specify any other binding for 'last') was > likely an image or style sheet or something to fill in something on the > previously rendered page, or even something in another tab. > Yes I gave an imprecise usage of "last request". Was it really confusing to you? Did you really think I meant the last chronological request received by the server? > > > which will be the action URL not the jsp page that rendered the >>>> result. >>>> >>> By "action URL" I simply meant the URL contains the name of the "action" and not the name of the jsp that rendered the page. Sorry if this was confusing. > > This is completely dependent upon how you handle posts. If you use the > post-redirect style, it won't be the "action url" (I'm not sure what you > mean by that phrase, but I assume you're differentiating those urls from > ones that are not side-effecting), but the GET url that resulted in the > display of the form. Assuming post-redirect-only-if-successful, then it'll > be the url of the step before this one: "submit-multi-page-form-step-2" when > the step that's failing validation is "submit-multi-page-form-step-3" (or > "submit-multi-page-form-3" if this step failed validation again, which > illustrates where this path will break down). > Yes, very nice description, so what you are saying is the referer header isn't going to be of any use in solving the OP problem? > > > So this wouldn't help the OP if I understood his problem. >>>> >>> > The problem is that the OP doesn't understand his problem. If the > validation step knows what the result page should be, he shouldn't be > returning "input", but rather the name of the logical step to be rendered. > He's right that the code shouldn't need to know what jsp page renders that > step, just the logical name of the page, fleshed out in the .xml file. > > -Dale > Yes your right but I was trying to be helpful. Can we just stop this OT discussion now? |
|
|
Re: Struts 2 ValidationPeople,
If someone want help me about my university project, here is my e-mail: robsonsilvar@gmail.com . I can send to you the entire projcect. This project is about control of stock and MRP. I´m using Struts2, Hibernate and MYSQL. It is separate on three layers with MVC.
|
|
|
RE: Struts 2 Validationyou are taking this course to learn about J2EE apps? did you even read the email i sent you on setting up min and max params <field name="integerValidatorField"> <field-validator type="int"> <param name="min">1</param> <param name="max">10</param> <message><![CDATA[ must be integer min 1 max 10 if supplied ]]></message> </field-validator> </field> better to get the fundamentals straight before you hire americans to work at min wage Martin Gainty ______________________________________________ Jogi és Bizalmassági kinyilatkoztatás/Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Ez az üzenet bizalmas. Ha nem ön az akinek szánva volt, akkor kérjük, hogy jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának készítése nem megengedett. Ez az üzenet csak ismeret cserét szolgál és semmiféle jogi alkalmazhatósága sincs. Mivel az electronikus üzenetek könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet ezen üzenet tartalma miatt. Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. > Date: Wed, 8 Jul 2009 15:23:53 -0700 > From: robsonsilvar@... > To: user@... > Subject: Re: Struts 2 Validation > > > People, > > If someone want help me about my university project, here is my e-mail: > robsonsilvar@... . I can send to you the entire projcect. > > This project is about control of stock and MRP. I´m using Struts2, Hibernate > and MYSQL. It is separate on three layers with MVC. > > > > Robson Rodrigues wrote: > > > > Hello People, > > > > > > > > i´m using the struts 2 in a project and i´m with a problem on the > > validation. When i try validate a form, the struts say the validation > > failed, even when the field is with correct value, in addition, it is not > > going back to the field with the old value > > > > > > > > here is my struts.xml. The action is the Cliente_insert: > > > > > > > > <package name="cliente" namespace="/" extends="struts-default"> > > > > <default-interceptor-ref name="defaultStack"/> > > > > > > > > <action name="Cliente_input" > > > > > <result >/cliente/inputCliente.jsp</result> > > > > </action> > > > > <action name="Cliente_edit" class="br.com.robson.modelo.ClienteAction" > > method="editar"> > > > > <interceptor-ref name="paramsPrepareParamsStack" /> > > > > <result >/cliente/editCliente.jsp</result> > > > > </action> > > > > <action name="Cliente_list" class="br.com.robson.modelo.ClienteAction" > > method="listar"> > > > > <result name="success">/cliente/listaClientes.jsp</result> > > > > </action> > > > > <action name="Cliente_insert" class="br.com.robson.modelo.ClienteAction" > > method="inserir"> > > > > <interceptor-ref name="validationWorkflowStack"/> > > > > > > > > <result name="input">/cliente/inputCliente.jsp</result> > > > > <result name="success" type="redirect">Cliente_list.action</result> > > > > </action> > > > > <action name="Cliente_delete" class="br.com.robson.modelo.ClienteAction" > > method="deletar"> > > > > <result name="success" type="redirect">Cliente_list.action</result> > > > > </action> > > > > <action name="Cliente_update" class="br.com.robson.modelo.ClienteAction" > > method="atualizar"> > > > > <result name="success" type="redirect">Cliente_list.action</result> > > > > </action> > > > > > > > > </package> > > > > > > > > Here is my validation archive: > > > > > > > > <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator > > 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> > > > > <validators> > > > > <!-- <field name="nome"> > > > > <field-validator type="required"> > > > > true > > > > <message> O campo nome é obrigatório </message> > > > > </field-validator> > > > > </field> --> > > > > <field name="telefone"> > > > > <field-validator type="required"> > > > > true > > > > <message> O campo telefone é obrigatório </message> > > > > </field-validator> > > > > <field-validator type="stringlength"> > > > > true > > > > 6 > > > > 14 > > > > <message> O campo telefone deve ter entre 6 e 14 caracteres </message> > > > > </field-validator> > > > > </field> > > > > </validators> > > > > > > > > here is my jsp: > > > > > > > > <%@ page language="java" contentType="text/html; charset=ISO-8859-1" > > > > pageEncoding="ISO-8859-1"%> > > > > <%@page import="br.com.robson.modelo.Cliente" %> > > > > <%@page import ="java.util.*" %> > > > > <%@ taglib prefix="s" uri="/struts-tags" %> > > > > > > > > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > > "http://www.w3.org/TR/html4/loose.dtd"> > > > > <html:html> > > > > <head> > > > > <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> > > > > <title>Insert title here</title> > > > > <script language="javascript"> > > > > </script> > > > > </head> > > > > <body> > > > > Novo Cliente > > > > <s:debug/> > > > > > > > > <s:form action="Cliente_insert.action" method="POST" > > > > > > > > > <s:textfield name="idCli" label="Id" /> > > > > > > > > <s:textfield name="nome" label="Nome"/> > > > > > > > > <s:textfield name="telefone" label="Ielefone"/> > > > > > > > > <s:submit></s:submit> > > > > </s:form> > > > > > > > > > > > > > > > > > > > > </body> > > > > </html:html> > > > > > > > > I hope you can help me > > > > > > > > Hugs! > > > > > > > > -- > View this message in context: http://www.nabble.com/Struts-2-Validation-tp24382602p24400471.html > Sent from the Struts - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > _________________________________________________________________ Windows Live™: Keep your life in sync. http://windowslive.com/explore?ocid=TXT_TAGLM_WL_BR_life_in_synch_062009 |
|
|
Re: dynamic return when validation failedHi Dale & Greg,
Thanks for all your discussion. >>> > The problem is that the OP doesn't understand his problem. If the > validation step knows what the result page should be, he shouldn't be > returning "input", but rather the name of the logical step to be rendered. > He's right that the code shouldn't need to know what jsp page renders that > step, just the logical name of the page, fleshed out in the .xml file. > Yes, my validation step know what the result page should be (I mean the logical name of the result page), why I said it returning to the "input" that is because the workflow interceptor always return to the logical name "input" when there is error, that is why come to this idea to replace the value of "input" Well, if I remove my validation code in the validate() method and put it into execute() method, then I can easily control which logical name to be return, but I thought that is not a good way to do that right? There must be other way to solve this kind of validation problem, what I call this wizard validation, I think it is quite common in many web project. Like in my case, create employee wizard, it break into 5 pages and handle by CreateEmpAction, I can use Greg solution 2, but then I need to create CreateEmpAction1, CreateEmpAction2, etc, thats not look so tidy to me. Hopefully someone done this before can give me some light. Regards Louis |
|
|
Re: dynamic return when validation failedThanks for let me know another struts2 book, have a quick look in it, didn't found any good tip to solve my problem.
Regards Louis ________________________________ From: Oscar Alvarez <oialvarez@...> To: Struts Users Mailing List <user@...> Sent: Wednesday, July 8, 2009 7:09:35 PM Subject: Re: dynamic return when validation failed 2009/7/8 Oscar Alvarez <oialvarez@...> > Hi... > > Try to get the Ian Roughley's "Starting Struts2 online" ebook for free, and > study "PRODUCTIVITY TIPS" -> "Re-Using Action Configurations"... and see if > there are some other tips for you. > And of course "PRODUCTIVITY TIPS" -> "Use Pattern Matching Wildcards in Configurations" too. > > HTH > > 2009/7/8 Greg Lindholm <greg.lindholm@...> > > > Greg Lindholm wrote: >> > >> >> The referer header will contain the URL of the last request, which will >> be >> >> the action URL not the jsp page that rendered the result. So this >> wouldn't >> >> help the OP if I understood his problem. >> >> >> > >> > I think you misunderstand what the referer field contains. It'll be the >> > url that was displaying in the address field on the page from which the >> form >> > was submitted. http://en.wikipedia.org/wiki/HTTP_referrer Note that it >> > can be forged, etc. >> > >> > >> Not sure why you think I don't understand referer. In a struts app what >> you >> see in the address field is the "action URL" (e.g. >> http://host/MyAction.action) you don't ever see the JSP page name that >> rendered the page. The OP seemed to be looking for the name of the jsp >> page >> so don't see how this would help. >> > > > > -- > Atentamente > Óscar Álvarez Vielma > (09) 8416 4052 > -- Atentamente Óscar Álvarez Vielma (09) 8416 4052 |
|
|
Re: dynamic return when validation failed Use Pattern Matching Wildcards in Configurations
Action configuration files are somehow able to grow to extremely large at incredible speeds. On way to combat this phenomenon is to use pattern matching. Pattern matching works by defining one or more patterns that URLs will conform to. An example will be an easy way to see how things work. Let’s say that the URLs in your web application always follows the pattern “/{module}/{entity}/{action}.action”. This is a common pattern; examples would be the URL’s “/admin/User/edit.action”, “/admin/User/list.action” and “/admin/User/add.action”. The class configuration is such that there is a Struts2 action class with the name “{entity}Action”, and each {action} is method on the action class. All the results from invoking the action’s methods will result in either the update page for the entity being displayed, or a list of all the entities being displayed. For our example, the “struts.xml” configuration will look like this: *<action name=”*/*/*” method=”{3}” class=”com.infoq.actions.{1}.{2}Action”> <result name=”view”>/{1}/update{2}.jsp</result> <result name=”list”>/{1}/list.jsp</result> </action>* Each asterisk in the actions name is a wildcard. In the example, only asterisks are used – but this need not be the case. For example, say you wish to map all entity view actions together. Something like ‘name=”/*/View*”’ would do the trick. Token identifiers, {1}, {2}, etc., are then used to obtain the text values harvested from the wildcards (where the numeric value correlating to the position of the asterisk, ascending from left to right). In the “struts.properties” configuration file (or using the constant tag in the “struts.xml” configuration file) you need to ensure the following property is correctly set: struts.enable.SlashesInActionNames = true This property allows slashes in the name of the action. Struts2’s default configuration is to not have slashes in the action name, instead using packages for namespace separation. Finally, there is no shortcut if you are providing validation and conversion property files rather than using annotations. We’ll talk about this more in following sections. Each needs to contain the full name of the action, along with the necessary extension: i.e. “edit-validation.xml” and “edit-conversion.xml” for the original example, in the “com.infoq.actions.admin” package. 2009/7/9 <mailtolouis2020-struts@...> > Thanks for let me know another struts2 book, have a quick look in it, > didn't found any good tip to solve my problem. > > Regards > Louis > > > > ________________________________ > From: Oscar Alvarez <oialvarez@...> > To: Struts Users Mailing List <user@...> > Sent: Wednesday, July 8, 2009 7:09:35 PM > Subject: Re: dynamic return when validation failed > > 2009/7/8 Oscar Alvarez <oialvarez@...> > > > Hi... > > > > Try to get the Ian Roughley's "Starting Struts2 online" ebook for free, > and > > study "PRODUCTIVITY TIPS" -> "Re-Using Action Configurations"... and see > if > > there are some other tips for you. > > > > > And of course "PRODUCTIVITY TIPS" -> "Use Pattern Matching Wildcards in > Configurations" too. > > > > > > > HTH > > > > 2009/7/8 Greg Lindholm <greg.lindholm@...> > > > > > Greg Lindholm wrote: > >> > > >> >> The referer header will contain the URL of the last request, which > will > >> be > >> >> the action URL not the jsp page that rendered the result. So this > >> wouldn't > >> >> help the OP if I understood his problem. > >> >> > >> > > >> > I think you misunderstand what the referer field contains. It'll be > the > >> > url that was displaying in the address field on the page from which > the > >> form > >> > was submitted. http://en.wikipedia.org/wiki/HTTP_referrer Note that > it > >> > can be forged, etc. > >> > > >> > > >> Not sure why you think I don't understand referer. In a struts app what > >> you > >> see in the address field is the "action URL" (e.g. > >> http://host/MyAction.action) you don't ever see the JSP page name that > >> rendered the page. The OP seemed to be looking for the name of the jsp > >> page > >> so don't see how this would help. > >> > > > > > > > > -- > > Atentamente > > Óscar Álvarez Vielma > > (09) 8416 4052 > > > > > > -- > Atentamente > Óscar Álvarez Vielma > (09) 8416 4052 > -- Atentamente Óscar Álvarez Vielma (09) 8416 4052 |
| < Prev | 1 - 2 | Next > |
| Free embeddable forum powered by Nabble | Forum Help |