Re: Implementation of new row functionality of HTML table in Struts

2005-12-18 Thread atta-ur rehman
now i understand you're renaming the dynamically added textboxes thru
Javascript? right? if that's the case your renaming looks good to me. can
you do the trick in the form's reset() method; that is, set the a new
Customer array to the forms's property with something like:

String value = request.getParameter("customer[0].firstName");

  if (value != null) {
  int count = 1;
  while ((value = request.getParameter("customer[" + count +
"].firstName")) != null) {
  count++;
  }
  }

  Customer[] customers = new Customer[count];
  f.set("customer", customers);


On 12/18/05, Irfan Shaikh <[EMAIL PROTECTED]> wrote:
>
> No, user can add has many row he needed before submit... I had just added
> one row to handle this scenario... It should work for as many row user has
> added...
>
>
> On 12/19/05, atta-ur rehman <[EMAIL PROTECTED]> wrote:
> >
> > okay, so you're saying use can add only ONE row dynamically before
> submit?
> > and that the newly added row's HTML code is:
> >
> > 
> >  
> >   > value="John">
> >   > value="Mark">
> >  
> >  
> >
> >
> > if that's the case, in your ActionForm's reset method, detect that user
> > has
> > added a new row, maybe thru request.getParameter
> ("customer[?].firstName")
> > where ? will be an integer 0..n where reuqest.getParameter would return
> > null
> > for n+1. once you've done that do a:
> >
> > Customer[] customers = new Customer[n];
> > form.set("customer", customers);
> >
> > see if that helps.
> >
> > ATTA
> >
> >
> > On 12/18/05, Irfan Shaikh <[EMAIL PROTECTED]> wrote:
> > >
> > > Once again Generated HTML :
> > >
> > >  > > action="/GenerateHTMLTable/listtext.do">
> > >
> > > 
> > > 
> > >   
> > >   
> > >
> > > 
> > > 
> > > 
> > > 
> > >   
> > >
> > >   
> > >
> > > 
> > >   
> > >> > value="Irfan">
> > >
> > >> > value="Shaikh">
> > >   
> > > 
> > >
> > > 
> > >   
> > >> > value="Maruf1212">
> > >> > value="Dolani">
> > >> > value="Mumbai">
> > > 
> > >
> > > 
> > >   
> > >
> > >> > value="Azima12">
> > >> > value="Kacchi">
> > >> > value="Pune">
> > > 
> > >
> > > 
> > >   
> > >> > value="Ruhi11133">
> > >> > value="Khan">
> > >> > value="Pune">
> > > 
> > >
> > >
> > > 
> > >   
> > >> > value="John">
> > >> > value="Mark">
> > >   
> > >  (Hardcoded HTML row)
> > >
> > >   
> > >
> > >
> > > 
> > >
> > >
> >
> >
>
>


Re: Implementation of new row functionality of HTML table in Struts

2005-12-18 Thread Irfan Shaikh
No, user can add has many row he needed before submit... I had just added
one row to handle this scenario... It should work for as many row user has
added...


On 12/19/05, atta-ur rehman <[EMAIL PROTECTED]> wrote:
>
> okay, so you're saying use can add only ONE row dynamically before submit?
> and that the newly added row's HTML code is:
>
> 
>  
>   value="John">
>   value="Mark">
>  
>  
>
>
> if that's the case, in your ActionForm's reset method, detect that user
> has
> added a new row, maybe thru request.getParameter("customer[?].firstName")
> where ? will be an integer 0..n where reuqest.getParameter would return
> null
> for n+1. once you've done that do a:
>
> Customer[] customers = new Customer[n];
> form.set("customer", customers);
>
> see if that helps.
>
> ATTA
>
>
> On 12/18/05, Irfan Shaikh <[EMAIL PROTECTED]> wrote:
> >
> > Once again Generated HTML :
> >
> >  > action="/GenerateHTMLTable/listtext.do">
> >
> > 
> > 
> >   
> >   
> >
> > 
> > 
> > 
> > 
> >   
> >
> >   
> >
> > 
> >   
> >> value="Irfan">
> >
> >> value="Shaikh">
> >   
> > 
> >
> > 
> >   
> >> value="Maruf1212">
> >> value="Dolani">
> >> value="Mumbai">
> > 
> >
> > 
> >   
> >
> >> value="Azima12">
> >> value="Kacchi">
> >> value="Pune">
> > 
> >
> > 
> >   
> >> value="Ruhi11133">
> >> value="Khan">
> >> value="Pune">
> > 
> >
> >
> > 
> >   
> >> value="John">
> >> value="Mark">
> >   
> >  (Hardcoded HTML row)
> >
> >   
> >
> >
> > 
> >
> >
>
>


Re: Implementation of new row functionality of HTML table in Struts

2005-12-18 Thread atta-ur rehman
okay, so you're saying use can add only ONE row dynamically before submit?
and that the newly added row's HTML code is:


 
 
 
 
 


if that's the case, in your ActionForm's reset method, detect that user has
added a new row, maybe thru request.getParameter("customer[?].firstName")
where ? will be an integer 0..n where reuqest.getParameter would return null
for n+1. once you've done that do a:

Customer[] customers = new Customer[n];
form.set("customer", customers);

see if that helps.

ATTA


On 12/18/05, Irfan Shaikh <[EMAIL PROTECTED]> wrote:
>
> Once again Generated HTML :
>
>  action="/GenerateHTMLTable/listtext.do">
>
> 
> 
>   
>   
>
> 
> 
> 
> 
>   
>
>   
>
> 
>   
>value="Irfan">
>
>value="Shaikh">
>   
> 
>
> 
>   
>value="Maruf1212">
>value="Dolani">
>value="Mumbai">
> 
>
> 
>   
>
>value="Azima12">
>value="Kacchi">
>value="Pune">
> 
>
> 
>   
>value="Ruhi11133">
>value="Khan">
>value="Pune">
> 
>
>
> 
>   
>value="John">
>value="Mark">
>   
>  (Hardcoded HTML row)
>
>   
>
>
> 
>
>


Re: Implementation of new row functionality of HTML table in Struts

2005-12-18 Thread Irfan Shaikh
Once again Generated HTML :





  
  





  

  


  
  

  
  



  
  
  
  



  

  
  
  



  
  
  
  




  
  
  
  
 (Hardcoded HTML row)

  





Re: Implementation of new row functionality of HTML table in Struts

2005-12-18 Thread Irfan Shaikh
JSP Page :
  
  




  

  

  
  
  
  

  
  
  
  
  
  

  

row is hardcoded (with index) on JSP page for simplicity. Now, on submit it
give me this error..

javax.servlet.ServletException: BeanUtils.populate
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)

org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:804)

org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

*root cause*

java.lang.ArrayIndexOutOfBoundsException
java.lang.reflect.Array.get(Native Method)
org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:250)

org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:386)

org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:340)

org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:684)

org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715)

org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:884)

org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)

org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:804)

org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


Genetared HTML Code

 



  
  





  


  
  

  
  



  
  
  
  



  

  
  
  



  
  
  
  




  
  
  
  
  

  




Thanks, waiting for reply.



On 12/19/05, atta-ur rehman <[EMAIL PROTECTED]> wrote:
>
> Irfan,
>
> By looking at the HTML source of the your page, please show me the name of
> textboxes added thru  and name of the textboxes you've
> added
> thru Javascript.
>
> ATTA
>
>
> On 12/17/05, Irfan Shaikh <[EMAIL PROTECTED]> wrote:
> >
> > I am storing data objects into an Array for initial rows and when user
> > submit the form i am getting the updated values by using the code
> > highlighted below
> >
> > public ActionForward execute(ActionMapping mapping,
> >  ActionForm form,
> >  HttpServletRequest request,
> >  HttpServletResponse response){
> >
> > DynaActionForm f = (DynaActionForm) form;
> > Customer[] s = (Customer[])f.get("customer");
> >
> > System.out.println("Number of Rows on page :" + s.length);
> >
> >
> >if (s.length!=0) {
> > insertAllCustomer(s);
> > f.set("customer", s);
> > } else {
> > Customer[] custArray = getAllCustomer();
> > f.set("customer", custArray);
> > }
> >
> >   return (mapping.findForward("OK"));
> > }
> >
> >the problem here is when i populate the data on page for the first
> time
> > i
> > have 4 rows and then i add a new row by javascript, and i submit the
> page,
> > even then i get only 4 rows in execute method whereas i should get 5
> rows
> > so
> > that i can get the new added row data to create a new Customer bean and
> > put
> > it back to Customer[] array (this is my collection)
> >
> > Here is the loop for rows genration on JSP page :
> >
> > 
> > 
> >value="yes"/>
> >   
> >   
> >   
> > 
> >   
> >
> >
> >
> > Is there something i am missing here ?... Waiting for a reply
> desperately
> > Thanks a lot.
> >
> > On 12/17/05, atta-ur rehman <[EMAIL PROTECTED]> wrote:
> > >
> > > Irfan,
> > >
> > > How are you storing data required for initial rows? As a collection of
> > > objects in some scope that  uses to paint them on the
> > page?
> > >
> > > When user submits the page how are you getting the updated values?
> > > Populating the objects in the same collection or constructing a new
> > > collection and adding a object for each row?
> > >
> 

Re: Implementation of new row functionality of HTML table in Struts

2005-12-18 Thread atta-ur rehman
Irfan,

By looking at the HTML source of the your page, please show me the name of
textboxes added thru  and name of the textboxes you've added
thru Javascript.

ATTA


On 12/17/05, Irfan Shaikh <[EMAIL PROTECTED]> wrote:
>
> I am storing data objects into an Array for initial rows and when user
> submit the form i am getting the updated values by using the code
> highlighted below
>
> public ActionForward execute(ActionMapping mapping,
>  ActionForm form,
>  HttpServletRequest request,
>  HttpServletResponse response){
>
> DynaActionForm f = (DynaActionForm) form;
> Customer[] s = (Customer[])f.get("customer");
>
> System.out.println("Number of Rows on page :" + s.length);
>
>
>if (s.length!=0) {
> insertAllCustomer(s);
> f.set("customer", s);
> } else {
> Customer[] custArray = getAllCustomer();
> f.set("customer", custArray);
> }
>
>   return (mapping.findForward("OK"));
> }
>
>the problem here is when i populate the data on page for the first time
> i
> have 4 rows and then i add a new row by javascript, and i submit the page,
> even then i get only 4 rows in execute method whereas i should get 5 rows
> so
> that i can get the new added row data to create a new Customer bean and
> put
> it back to Customer[] array (this is my collection)
>
> Here is the loop for rows genration on JSP page :
>
> 
> 
>   
>   
>   
>   
> 
>   
>
>
>
> Is there something i am missing here ?... Waiting for a reply desperately
> Thanks a lot.
>
> On 12/17/05, atta-ur rehman <[EMAIL PROTECTED]> wrote:
> >
> > Irfan,
> >
> > How are you storing data required for initial rows? As a collection of
> > objects in some scope that  uses to paint them on the
> page?
> >
> > When user submits the page how are you getting the updated values?
> > Populating the objects in the same collection or constructing a new
> > collection and adding a object for each row?
> >
> > If that's the case, then all you need to do is reset the collection of
> > objects to the new number of rows submitted by the user.
> > Commons-Collection,
> > which is required by Sturts(?) have a lazy-list which could be used for
> > this
> > purpose.
> >
> > ATTA
> >
> >
> > On 12/16/05, Irfan Shaikh <[EMAIL PROTECTED]> wrote:
> > >
> > > Hi All,
> > >  I am new to Struts and  need to implement a functionality
> where
> > a
> > > new row is added to table (generated using logic:iterate tag on JSP
> page
> > )
> > > on the fly(using javascript)  and handling newly added row in
> > > DynaActionForm
> > > so that row gets saved to database. Need to know how to create a bean
> > for
> > > newly added row.
> > >
> > > Suggestion will be highly appreciated.
> > > Thanks in advance
> > >
> > >
> >
> >
>
>


Re: Implementation of new row functionality of HTML table in Struts

2005-12-18 Thread Irfan Shaikh
Thanks for the reply Michael,

   1. Yes, I am adding a row into the browser's DOM. Basically, client
   requirement is to implement a table like structure where user can add a new
   row to save new record. i need to know how to handle scenario where client
   changes (adding a new row) gets notified to server to create a new bean for
   the added row.
2. I am submitting all rows because any changes to existing should
   get udpated to database.

Suggestion will be greatly appreciated. Thanks once again.

Irfan.


On 12/18/05, Michael Jouravlev <[EMAIL PROTECTED]> wrote:
>
> On 12/17/05, Irfan Shaikh <[EMAIL PROTECTED]> wrote:
> >the problem here is when i populate the data on page for the first
> time i
> > have 4 rows and then i add a new row by javascript
>
> Do you add a row right into the browser's DOM?
>
> >, and i submit the page,
> > even then i get only 4 rows in execute method whereas i should get 5
> rows
>
> You submit *all* rows back? What for? Why don't you want to submit
> only a new row? Does this look like something you would like to do:
> http://superinterface.com/strutsdialog/crudactionlite.do or is too
> simplistic for your tastes?
>
> Michael.
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


Re: Input validation and repair

2005-12-18 Thread Dakota Jack
Paul's solution, in this regard, seems more design consistent.

On 12/18/05, Dakota Jack <[EMAIL PROTECTED]> wrote:
>
> I would think that doing validation in your action would be
> contra-indicated as a design matter, if you are doing Struts struts rather
> than one of the other struts.
>
> On 12/18/05, Rick R <[EMAIL PROTECTED]> wrote:
> >
> > On 12/18/05, Josh McDonald <[EMAIL PROTECTED]> wrote:
> > >
> > > What's the best place to put input validation and possible repair?
> >
> >
> >
> > I actually prefer to do the validation checks in my DispatchAction. The
> > reason being is that, inevitably, you'll end up with a case where you'll
> > have some Lists you'll want to populate on your input JSP that are setup
> >
> > before you get to the JSP and if validation fails and you use the struts
> > built in approach calling validate="true" in your action mapping, you'll
> > end
> > up with all kinds of problems when you are brought back to the JSP after
> >
> > validation fails (request scoped lists won't be in scope). Unless you
> > use
> > some other plans to keep the lists around (Session, reset,etc... all of
> > which I don't like much and I talk more about here:
> > http://www.reumann.net/struts/articles/request_lists.jsp).
> > I find it saves
> > you from headaches down the line if you just do your validation calls
> > from
> > your Action class. You can still use the validation framework (commons
> > validator stuff that Paul mentions) to set up validation checks if
> > that's
> > your pleasure... it's just that the call to invoke those checks ends up
> > being initiated from the Action. As an example:
> >
> > //notice the prep method which will put stuff back in request scope when
> >
> > validation fails and would also be used by other dispatch methods in
> > this
> > action class
> >
> > public ActionForward yourActionMethod(ActionMapping mapping, ActionForm
> > form, HttpServletRequest request, HttpServletResponse response) throws
> > Exception {
> > YourForm yourForm = (YourForm)form;
> > if (validationSuccessful(request, yourForm)) {
> >//do stuff.
> >   return mapping.findForward(Constants.SUCCESS);
> >   } else {
> >   prep(request);
> >   return mapping.findForward(Constants.FAILURE);
> >   }
> > }
> >
> > private void prep(HttpServletRequest request) {
> >   request.setAttribute(Constants.SOME_LIST_NAME,
> > service.getSomeKindOfList());
> >   }
> >
> > private boolean validationSuccessful(HttpServletRequest request,
> > EmployeeForm form) {
> > boolean isOk = true;
> > ActionMessages errors = new ActionMessages();
> > //do your validation checks...
> > //ie...
> > if (form.getFirstName() == null || form.getFirstName
> > ().trim().length()
> > == 0) {
> > errors.add("firstName", new ActionMessage("errors.required",
> > "First
> > Name"));
> > }
> > //or you could even call the form's validate...
> > //errors = form.validate( mapping, request );
> >
> > //continue with other checks
> >
> > if (!errors.isEmpty()) {
> > saveErrors(request, errors);
> > isOk = false;
> > }
> > return isOk;
> >   }
> >
> > --
> > Rick
> >
> >
>
>
> --
> "You can lead a horse to water but you cannot make it float on its back."
> ~Dakota Jack~
>



--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~


Re: Input validation and repair

2005-12-18 Thread Dakota Jack
I would think that doing validation in your action would be contra-indicated
as a design matter, if you are doing Struts struts rather than one of the
other struts.

On 12/18/05, Rick R <[EMAIL PROTECTED]> wrote:
>
> On 12/18/05, Josh McDonald <[EMAIL PROTECTED]> wrote:
> >
> > What's the best place to put input validation and possible repair?
>
>
>
> I actually prefer to do the validation checks in my DispatchAction. The
> reason being is that, inevitably, you'll end up with a case where you'll
> have some Lists you'll want to populate on your input JSP that are setup
> before you get to the JSP and if validation fails and you use the struts
> built in approach calling validate="true" in your action mapping, you'll
> end
> up with all kinds of problems when you are brought back to the JSP after
> validation fails (request scoped lists won't be in scope). Unless you use
> some other plans to keep the lists around (Session, reset,etc... all of
> which I don't like much and I talk more about here:
> http://www.reumann.net/struts/articles/request_lists.jsp). I find it saves
> you from headaches down the line if you just do your validation calls from
> your Action class. You can still use the validation framework (commons
> validator stuff that Paul mentions) to set up validation checks if that's
> your pleasure... it's just that the call to invoke those checks ends up
> being initiated from the Action. As an example:
>
> //notice the prep method which will put stuff back in request scope when
> validation fails and would also be used by other dispatch methods in this
> action class
>
> public ActionForward yourActionMethod(ActionMapping mapping, ActionForm
> form, HttpServletRequest request, HttpServletResponse response) throws
> Exception {
> YourForm yourForm = (YourForm)form;
> if (validationSuccessful(request, yourForm)) {
>//do stuff.
>   return mapping.findForward(Constants.SUCCESS);
>   } else {
>   prep(request);
>   return mapping.findForward(Constants.FAILURE);
>   }
> }
>
> private void prep(HttpServletRequest request) {
>   request.setAttribute(Constants.SOME_LIST_NAME,
> service.getSomeKindOfList());
>   }
>
> private boolean validationSuccessful(HttpServletRequest request,
> EmployeeForm form) {
> boolean isOk = true;
> ActionMessages errors = new ActionMessages();
> //do your validation checks...
> //ie...
> if (form.getFirstName() == null || form.getFirstName().trim().length()
> == 0) {
> errors.add("firstName", new ActionMessage("errors.required",
> "First
> Name"));
> }
> //or you could even call the form's validate...
> //errors = form.validate( mapping, request );
>
> //continue with other checks
>
> if (!errors.isEmpty()) {
> saveErrors(request, errors);
> isOk = false;
> }
> return isOk;
>   }
>
> --
> Rick
>
>


--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~


Re: Struts Menu Vs Struts Layout

2005-12-18 Thread Yves Sy
Another option would be SiteMesh.

If you like working on the fringes of technology though, I recommend AJAX or
OpenLaszlo...

Br,
-Yves-

On 12/18/05, Agnisys <[EMAIL PROTECTED]> wrote:
>
> Hi,
>   I need to create an application with lots of Dynamic GUI features (like
> dynamic number of
> Panes). Which one is more suitable for the job: Struts Menu or Struts
> Layout?
>   Or is there a more appropriate 3rd option?
>
> Thanks for any pointers.
> Anupam.
>
>
> __
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


--
A bus station is where a bus stops. A train station is where a train stops.
On my desk I have a work station...


Re: Input validation and repair

2005-12-18 Thread Josh McDonald
Sweet, that's good to know. Not much use in an environment of such
inertia and red tape tho :) I believe it'll be 1.1 for many moons after
my contract is up

-- 

"His comrades fought beside him, Van Owen and the rest...
   But of all the thompson gunners- Roland was the best."

Josh McDonald
Analyst Programmer
Information Technology
Ph: 61 7 3006 6460
Email: [EMAIL PROTECTED]


>>> [EMAIL PROTECTED] 19/12/2005 2:50:22 pm >>>
>>it should be an URL and patch it up (like > 'www.google.com' into
'http://www.google.com/'). 

This is a bug which was fixed in Struts 1.2.8 by upgrading to commons
validator 1.1.4.

Paul

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-
To unsubscribe, e-mail: [EMAIL PROTECTED] 
For additional commands, e-mail: [EMAIL PROTECTED] 







***
Messages included in this e-mail and any of its attachments are those
of the author unless specifically stated to represent WorkCover Queensland. The 
contents of this message are to be used for the intended purpose only and are 
to be kept confidential at all times.
This message may contain privileged information directed only to the intended 
addressee/s. Accidental receipt of this information should be deleted promptly 
and the sender notified.
This e-mail has been scanned by Sophos for known viruses.
However, no warranty nor liability is implied in this respect.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Input validation and repair

2005-12-18 Thread Paul Benedict
>>it should be an URL and patch it up (like > 'www.google.com' into 
>>'http://www.google.com/'). 

This is a bug which was fixed in Struts 1.2.8 by upgrading to commons validator 
1.1.4.

Paul

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Input validation and repair

2005-12-18 Thread Josh McDonald
Thanks for your feedback guys, what I've got is some URL validation
(just regexes, nothing magic) but I've also got some smaller regexes to
detect stuff that looks like it should be an URL and patch it up (like
'www.google.com' into 'http://www.google.com/'). For now I've just got
it in the validate() function of the view/form (not sure where struts
terminology ends and local cruft terminology begins) and it's working
just about perfect :) I'll definitely be coming back to these posts if I
have any lists that need checking etc.

Cheers,
-Josh

-- 

"His comrades fought beside him, Van Owen and the rest...
   But of all the thompson gunners- Roland was the best."

Josh McDonald
Analyst Programmer
Information Technology
Ph: 61 7 3006 6460
Email: [EMAIL PROTECTED]


>>> [EMAIL PROTECTED] 19/12/2005 1:39:02 pm >>>
On 12/18/05, Josh McDonald <[EMAIL PROTECTED]> wrote:
>
> What's the best place to put input validation and possible repair?



I actually prefer to do the validation checks in my DispatchAction.
The
reason being is that, inevitably, you'll end up with a case where
you'll
have some Lists you'll want to populate on your input JSP that are
setup
before you get to the JSP and if validation fails and you use the
struts
built in approach calling validate="true" in your action mapping,
you'll end
up with all kinds of problems when you are brought back to the JSP
after
validation fails (request scoped lists won't be in scope). Unless you
use
some other plans to keep the lists around (Session, reset,etc... all
of
which I don't like much and I talk more about here:
http://www.reumann.net/struts/articles/request_lists.jsp). I find it
saves
you from headaches down the line if you just do your validation calls
from
your Action class. You can still use the validation framework (commons
validator stuff that Paul mentions) to set up validation checks if
that's
your pleasure... it's just that the call to invoke those checks ends
up
being initiated from the Action. As an example:

//notice the prep method which will put stuff back in request scope
when
validation fails and would also be used by other dispatch methods in
this
action class

public ActionForward yourActionMethod(ActionMapping mapping,
ActionForm
form, HttpServletRequest request, HttpServletResponse response) throws
Exception {
YourForm yourForm = (YourForm)form;
if (validationSuccessful(request, yourForm)) {
   //do stuff.
  return mapping.findForward(Constants.SUCCESS);
  } else {
  prep(request);
  return mapping.findForward(Constants.FAILURE);
  }
}

private void prep(HttpServletRequest request) {
  request.setAttribute(Constants.SOME_LIST_NAME,
service.getSomeKindOfList());
  }

private boolean validationSuccessful(HttpServletRequest request,
EmployeeForm form) {
boolean isOk = true;
ActionMessages errors = new ActionMessages();
//do your validation checks...
//ie...
if (form.getFirstName() == null ||
form.getFirstName().trim().length()
== 0) {
errors.add("firstName", new ActionMessage("errors.required",
"First
Name"));
}
//or you could even call the form's validate...
//errors = form.validate( mapping, request );

//continue with other checks

if (!errors.isEmpty()) {
saveErrors(request, errors);
isOk = false;
}
return isOk;
  }

--
Rick






***
Messages included in this e-mail and any of its attachments are those
of the author unless specifically stated to represent WorkCover Queensland. The 
contents of this message are to be used for the intended purpose only and are 
to be kept confidential at all times.
This message may contain privileged information directed only to the intended 
addressee/s. Accidental receipt of this information should be deleted promptly 
and the sender notified.
This e-mail has been scanned by Sophos for known viruses.
However, no warranty nor liability is implied in this respect.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Input validation and repair

2005-12-18 Thread Rick R
On 12/18/05, Josh McDonald <[EMAIL PROTECTED]> wrote:
>
> What's the best place to put input validation and possible repair?



I actually prefer to do the validation checks in my DispatchAction. The
reason being is that, inevitably, you'll end up with a case where you'll
have some Lists you'll want to populate on your input JSP that are setup
before you get to the JSP and if validation fails and you use the struts
built in approach calling validate="true" in your action mapping, you'll end
up with all kinds of problems when you are brought back to the JSP after
validation fails (request scoped lists won't be in scope). Unless you use
some other plans to keep the lists around (Session, reset,etc... all of
which I don't like much and I talk more about here:
http://www.reumann.net/struts/articles/request_lists.jsp). I find it saves
you from headaches down the line if you just do your validation calls from
your Action class. You can still use the validation framework (commons
validator stuff that Paul mentions) to set up validation checks if that's
your pleasure... it's just that the call to invoke those checks ends up
being initiated from the Action. As an example:

//notice the prep method which will put stuff back in request scope when
validation fails and would also be used by other dispatch methods in this
action class

public ActionForward yourActionMethod(ActionMapping mapping, ActionForm
form, HttpServletRequest request, HttpServletResponse response) throws
Exception {
YourForm yourForm = (YourForm)form;
if (validationSuccessful(request, yourForm)) {
   //do stuff.
  return mapping.findForward(Constants.SUCCESS);
  } else {
  prep(request);
  return mapping.findForward(Constants.FAILURE);
  }
}

private void prep(HttpServletRequest request) {
  request.setAttribute(Constants.SOME_LIST_NAME,
service.getSomeKindOfList());
  }

private boolean validationSuccessful(HttpServletRequest request,
EmployeeForm form) {
boolean isOk = true;
ActionMessages errors = new ActionMessages();
//do your validation checks...
//ie...
if (form.getFirstName() == null || form.getFirstName().trim().length()
== 0) {
errors.add("firstName", new ActionMessage("errors.required", "First
Name"));
}
//or you could even call the form's validate...
//errors = form.validate( mapping, request );

//continue with other checks

if (!errors.isEmpty()) {
saveErrors(request, errors);
isOk = false;
}
return isOk;
  }

--
Rick


Re: Input validation and repair

2005-12-18 Thread Paul Benedict
Josh,

You can use a combination of the Commons Validator plus any addition complex 
validation in the
validate() method of the action form. No one forces you to use any method. 
However, the Commons
Validator is sufficient for 95% of the data validation you need so make sure 
you take good
advantage of this feature.

The Validator does not change data. It only flags which properties of the form 
failed validation.
When that happens, the "input" forward of the Action will be invoked. Usually 
the "input" forward
is configured to go back to the origin page so that the user can see the errors 
and correct his
bad input.

Paul


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Input validation and repair

2005-12-18 Thread Josh McDonald
What's the best place to put input validation and possible repair?
Should I extend some struts validator and put it in the
struts-config.xml attached to every form that uses it? Just wondering
what's the "best practice" on that sort of thing, and if the strut
validator framework allows me to change the data if it's fixable, or
just flag it as being bad?

Cheers, 
-Josh

-- 

"His comrades fought beside him, Van Owen and the rest...
   But of all the thompson gunners- Roland was the best."

Josh McDonald
Analyst Programmer
Information Technology
Ph: 61 7 3006 6460
Email: [EMAIL PROTECTED]




***
Messages included in this e-mail and any of its attachments are those
of the author unless specifically stated to represent WorkCover Queensland. The 
contents of this message are to be used for the intended purpose only and are 
to be kept confidential at all times.
This message may contain privileged information directed only to the intended 
addressee/s. Accidental receipt of this information should be deleted promptly 
and the sender notified.
This e-mail has been scanned by Sophos for known viruses.
However, no warranty nor liability is implied in this respect.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to keep a request Attribute available (from first action) after second action is called

2005-12-18 Thread Paul Benedict
Neils,

The only thing in common between request 1 and request 2 is the user session. 
If you want
something to persist between requests, place it in the session; then clean the 
session when
finished.

Paul


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



How to keep a request Attribute available (from first action) after second action is called

2005-12-18 Thread niels
An action (ActionOne with scope=request) is called which
puts a result list on an attribute like:
request.setAttribute("listResult", list);
This result is displayed in a jsp.

After that a second action (ActionTwo) is called
which forward to another jsp. How can I make the "listResult" available in
ActionTwo?


Thanks in advance,
Niels


Struts Menu Vs Struts Layout

2005-12-18 Thread Agnisys
Hi,
  I need to create an application with lots of Dynamic GUI features (like 
dynamic number of
Panes). Which one is more suitable for the job: Struts Menu or Struts Layout?
  Or is there a more appropriate 3rd option?

Thanks for any pointers.
Anupam.


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Specify a file name when using DownloadAction

2005-12-18 Thread Vu, Thai
Sorry everybody. I don't understand why I didn't see the last part of
that wiki page. Sorry again.

Another question: I use a BaseAction to make sure that everybody who
accesses all my actions in the application must login first. This is
what I do:

abstract class BaseAction extends Action {
public execute() {
// check some session-scoped variables to make sure that this
user logged in already.
executeAction();
}
abstract executeAction();
}

class AllOtherActions extends BaseAction {
executeAction() {
// do something here
}
}

So OurOwnDownloadAction cannot extend both DownloadAction and
BaseAction. What do you suggest? Do you think making BaseAction extend
the DownloadAction is the only choice?

Sincerely,

Thai

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 
Sent: Friday, December 16, 2005 1:47 PM
To: user@struts.apache.org
Subject: RE: Specify a file name when using DownloadAction

Vu, Thai asked
> I looked at these examples
> (http://wiki.apache.org/struts/StrutsFileDownload) on using 
> DownloadAction and saw nothing like your code :( So I wonder 
> if you could post your whole Action file here.

Did you look at
http://wiki.apache.org/struts/StrutsFileDownload#head-188719b69a6e7f2c42
d6cafef3ffab61e6129539 ?

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: chinese characters and bean tags

2005-12-18 Thread news
Hello Jose,

exactly! This solves my problem. Fortunately I do not have so many chinese
fields in my allplication. So it should not be complicated to close all
possible security holes.

Thanks a lot,
Milan

> Have you tried using  filter="false"/>?
>
> filter="false" means the tag will not "escape" HTML characteres... the
> default value is true IIRC. Maybe during that filtering it is also
> escaping
> non-ASCII characters? (wild guess here, since the last Struts version I
> used
> was 1.1)
>
> The problem with filter="false" is that is opens your app to all sorts of
> cross-site scripting security holes... so you would have to guarantee the
> user cannot enter some javascript code that will end up being printed by
> this tag later on... =(
>



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]