Re: Validation with DynaValidatorForm not working - help

2006-01-11 Thread Vishal Gaurav
I guess that would work if you have validations corresponding to a
form i.eyou are extending DynaValidatorForm.

If you need to extend DynaValidatorActionForm, i.e give validations
corresponding to a action (as single form can be reused in different actions
and not all fields need to be validated in each case) then I feel you need a
call to validate.

Correct me if I'm wrong :-)

Regards,
Vishal

On 1/12/06, Vasumathi <[EMAIL PROTECTED]> wrote:
>
> No mr.vishal i tried thats y im telling.
> u try without using validate method in local form.
> we have to mention the validation for each field in validation.xml file
> itself.
> no need of calling validate() in local form.
> definitely it will work.
>
>
>
> > You are right that there is no need to create a form bean if you are
> using
> > dyna form.
> >
> > However if you want to link your form with the validation framework then
> > you
> > do need to create a local form bean. This form bean would not have any
> > attributes and their getter and setter methods as they all are defined
> in
> > Struts config.
> >
> > All it would contain is a validate method with a call to super.validate
> ().
> > Please refer to the sample code in my last note for reference.
> >
> > Regards,
> > Vishal
> >
> > On 1/12/06, Vasumathi <[EMAIL PROTECTED]> wrote:
> > >
> > > no need to create a Form class in local. if we are using
> DynaActionForm,
> > > then
> > > no need of create form class in local.
> > > i tried in struts_config.xml only, it is working well.
> > >
> > >
> > >
> > >
> > >
> > >
> > > Quoting Vishal Gaurav <[EMAIL PROTECTED]>:
> > >
> > > > Hi,
> > > >
> > > > Simply having your dyna form bean of the type Dyna Validator form
> will
> > > not
> > > > work. You have to declare your form bean in the Struts Config as
> type
> > > any
> > > > local form bean you have. ( )
> > > >
> > > > Then your ABCForm will extend DynaValidatorForm or
> > > DynaValidatorActionForm
> > > > depending on yor requirement.
> > > >
> > > > It would have code similar to one given below
> > > >
> > > > public class LoginForm  extends DynaValidatorActionForm{
> > > > public ActionErrors validate(ActionMapping mapping,
> HttpServletRequest
> > > > request) {
> > > >
> > > >   ActionErrors errors = null;
> > > >   errors = super.validate(mapping, request);
> > > >
> > > >   return errors;
> > > >   }
> > > > }
> > > >
> > > > Hope this solves your problem.
> > > >
> > > >
> > > > On 1/12/06, Vasumathi <[EMAIL PROTECTED]> wrote:
> > > > >
> > > > > sorry u try this one. not previous one.
> > > > >
> > > > >  > > > > type="org.apache.struts.validator.DynaValidatorForm">
> > > > >
> > > > >
> > > > > 
> > > > >
> > > > >
> > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Quoting Mahadevan Venkataraman <[EMAIL PROTECTED]>:
> > > > > >
> > > > > > > Hi,
> > > > > > >
> > > > > > > I am having some problems in  getting struts to
> > > > > > > validate my input form. It seems to completely ignore
> > > > > > > the validation and starts executing the action.
> > > > > > >
> > > > > > > Here are the relevant files. Any help regarding this
> > > > > > > is highly appreciated.
> > > > > > >
> > > > > > > TIA
> > > > > > >
> > > > > > > Maha
> > > > > > >
> > > > > > > struts-config.xml
> > > > > > > --
> > > > > > >
> > > > > > > 
> > > > > > >   
> > > > > > >> > > > > >type="forms.ObjectTypeForm"
> > > > > > > dynamic="true">
> > >

Re: Validation with DynaValidatorForm not working - help

2006-01-11 Thread Vishal Gaurav
You are right that there is no need to create a form bean if you are using
dyna form.

However if you want to link your form with the validation framework then you
do need to create a local form bean. This form bean would not have any
attributes and their getter and setter methods as they all are defined in
Struts config.

All it would contain is a validate method with a call to super.validate().
Please refer to the sample code in my last note for reference.

Regards,
Vishal

On 1/12/06, Vasumathi <[EMAIL PROTECTED]> wrote:
>
> no need to create a Form class in local. if we are using DynaActionForm,
> then
> no need of create form class in local.
> i tried in struts_config.xml only, it is working well.
>
>
>
>
>
>
> Quoting Vishal Gaurav <[EMAIL PROTECTED]>:
>
> > Hi,
> >
> > Simply having your dyna form bean of the type Dyna Validator form will
> not
> > work. You have to declare your form bean in the Struts Config as type
> any
> > local form bean you have. ( )
> >
> > Then your ABCForm will extend DynaValidatorForm or
> DynaValidatorActionForm
> > depending on yor requirement.
> >
> > It would have code similar to one given below
> >
> > public class LoginForm  extends DynaValidatorActionForm{
> > public ActionErrors validate(ActionMapping mapping, HttpServletRequest
> > request) {
> >
> >   ActionErrors errors = null;
> >   errors = super.validate(mapping, request);
> >
> >   return errors;
> >   }
> > }
> >
> > Hope this solves your problem.
> >
> >
> > On 1/12/06, Vasumathi <[EMAIL PROTECTED]> wrote:
> > >
> > > sorry u try this one. not previous one.
> > >
> > >  > > type="org.apache.struts.validator.DynaValidatorForm">
> > >
> > >
> > > 
> > >
> > >
> > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Quoting Mahadevan Venkataraman <[EMAIL PROTECTED]>:
> > > >
> > > > > Hi,
> > > > >
> > > > > I am having some problems in  getting struts to
> > > > > validate my input form. It seems to completely ignore
> > > > > the validation and starts executing the action.
> > > > >
> > > > > Here are the relevant files. Any help regarding this
> > > > > is highly appreciated.
> > > > >
> > > > > TIA
> > > > >
> > > > > Maha
> > > > >
> > > > > struts-config.xml
> > > > > --
> > > > >
> > > > > 
> > > > >   
> > > > >> > > >type="forms.ObjectTypeForm"
> > > > > dynamic="true">
> > > > >  > > > > type="java.lang.String"/>
> > > > >  > > > > type="java.lang.String"/>
> > > > >   
> > > > >
> > > > > 
> > > > >
> > > > > the action - mappings contains
> > > > >
> > > > >> > > >  type="actions.ObjectTypeAction"
> > > > >   name="ObjectTypeForm"
> > > > >   scope="request"
> > > > >   validate="true"
> > > > >   input="/objecttype.jsp"
> > > > >   parameter="function">
> > > > >> > > > path="/error.jsp" />
> > > > >> > > > path="/index.jsp" />
> > > > >> > > > path="/objecttype.jsp" />
> > > > >   
> > > > >
> > > > > The ObjectTypeAction class extends DispatchAction.
> > > > >
> > > > > validate.xml
> > > > > 
> > > > >
> > > > > 
> > > > > 
> > > > > 
> > > > >  > > > > depends="required">
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> &

Re: Enabling links according to user's authorization

2006-01-11 Thread Vishal Gaurav
Hi,

To check the users access the best approach is to check the access on the
action by giving the roles attributes in the Struts Config and overriding
the processRoles() method of action class.

In addition to this if you want to limit weather a link is dispalyed to the
user or not you can take help from the following custom tag code and create
one for your application on similar grounds.

Tag Class

public class RolePresentTag extends TagSupport {
private String _role = null;

public void setRole(String sRole) {
_role = sRole;
}

public String getRole() {
return _role;
}

public int doStartTag() throws JspTagException {
boolean present = false;
ResourceBundle bundle = null;
HttpServletRequest request = null;
String roleName = null;
StringTokenizer st = null;

try {
bundle = ResourceBundle.getBundle(Constants.RESOURCES);
request = (HttpServletRequest) pageContext.getRequest();
st = new StringTokenizer(_role, ",", false);

while (st.hasMoreTokens()) {
try {
roleName = bundle.getString(st.nextToken());
} catch (MissingResourceException e) {
continue;
}

if (Util.isUserInRole(roleName, request)) {
present = true;
break;
}
}
} catch (Exception ex) {
throw new JspTagException(ex.getMessage());
}

return present ? EVAL_BODY_INCLUDE : SKIP_BODY;
}

   public int doEndTag() {
return EVAL_PAGE;
}
}


Util.isUserInRole :

In this method track the current role of the user from session and check if
it is one of the assigned role for this link

tld :


http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd";>

1.0
1.1
rolepresent

present
com.util.tag.RolePresentTag
JSP

role
true
true





JSP Code :

   


Hope this solves your problem.



On 1/11/06, shyam kishore alapati <[EMAIL PROTECTED]> wrote:
>
> While login itself you can have the permissions in the session and based
> on the permissions you can hide the links. Just for one variable i think
> there is no need to call the database.use can use  or
>  for this.
> -Original message-
> From: "Rivka Shisman" [EMAIL PROTECTED]
> Date: Wed, 11 Jan 2006 04:18:23 -0800
> To: "Struts Users Mailing List" user@struts.apache.org
> Subject: Enabling links according to user's authorization
>
> > Hi everyone,
> >
> > We have a web application running on Websphere Application Server V6.
> > Say I have a JSP page that enables working on Student details.
> > This JSP page enables users to view, insert, update or delete student
> > records.
> > Now, some users can only use the 'View' link, others can also use
> > 'Insert' link, and some other users can only update.
> >
> > From what i know, i can hold a DB table that indicates for each user and
> > table - which operations are allowed.
> > But, my question is - what is the right way to do that on the JSP page?
> > Do i call this security table on each page load and hide the
> > unauthorized links? Or, do always show all the links and just let the
> > database throw an exception and give a message to the user, when he/she
> > presses an unauthorized link? Or is there a third and better way?
> >
> > Thanks
> > Rivka
> >
>
>


Re: Validation with DynaValidatorForm not working - help

2006-01-11 Thread Vishal Gaurav
Hi,

Simply having your dyna form bean of the type Dyna Validator form will not
work. You have to declare your form bean in the Struts Config as type any
local form bean you have. ( )

Then your ABCForm will extend DynaValidatorForm or DynaValidatorActionForm
depending on yor requirement.

It would have code similar to one given below

public class LoginForm  extends DynaValidatorActionForm{
public ActionErrors validate(ActionMapping mapping, HttpServletRequest
request) {

  ActionErrors errors = null;
  errors = super.validate(mapping, request);

  return errors;
  }
}

Hope this solves your problem.


On 1/12/06, Vasumathi <[EMAIL PROTECTED]> wrote:
>
> sorry u try this one. not previous one.
>
>  type="org.apache.struts.validator.DynaValidatorForm">
>
>
> 
>
>
>
> >
> >
> >
> >
> >
> >
> >
> >
> > Quoting Mahadevan Venkataraman <[EMAIL PROTECTED]>:
> >
> > > Hi,
> > >
> > > I am having some problems in  getting struts to
> > > validate my input form. It seems to completely ignore
> > > the validation and starts executing the action.
> > >
> > > Here are the relevant files. Any help regarding this
> > > is highly appreciated.
> > >
> > > TIA
> > >
> > > Maha
> > >
> > > struts-config.xml
> > > --
> > >
> > > 
> > >   
> > >> >type="forms.ObjectTypeForm"
> > > dynamic="true">
> > >  > > type="java.lang.String"/>
> > >  > > type="java.lang.String"/>
> > >   
> > >
> > > 
> > >
> > > the action - mappings contains
> > >
> > >> >  type="actions.ObjectTypeAction"
> > >   name="ObjectTypeForm"
> > >   scope="request"
> > >   validate="true"
> > >   input="/objecttype.jsp"
> > >   parameter="function">
> > >> > path="/error.jsp" />
> > >> > path="/index.jsp" />
> > >> > path="/objecttype.jsp" />
> > >   
> > >
> > > The ObjectTypeAction class extends DispatchAction.
> > >
> > > validate.xml
> > > 
> > >
> > > 
> > > 
> > > 
> > >  > > depends="required">
> > > 
> > > 
> > > 
> > > 
> > > 
> > >
> > > validation-rules.xml
> > > 
> > >
> > > 
> > >   
> > >  > >
> > > classname=" org.apache.struts.validator.FieldChecks"
> > >  method="validateRequired"
> > >methodParams="java.lang.Object,
> > >
> > > org.apache.commons.validator.ValidatorAction ,
> > >
> > > org.apache.commons.validator.Field,
> > >
> > > org.apache.struts.action.ActionErrors,
> > >
> > > javax.servlet.http.HttpServletRequest"
> > > msg="errors.required">
> > > 
> > >   
> > > 
> > >
> > >
> > >
> > >
> > >
> > >
> > > __
> > > 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]
> > >
> >
> >
> >
> >
> > -
> > 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]
>
>


--
Thanks and Regards,
Vishal Gaurav
Ph : 9810482236
Email : [EMAIL PROTECTED]


Re: Validation Problem - very urgent please reply

2006-01-10 Thread Vishal Gaurav
Hi,

I feel that the approach given by Peter would be fine.

You might be populating the drop down by iterating a collection fetched from
Database. When you submit the form only the selected value is submitted from
the drop down not the entire collection (That is why you do not get the
collection back on page load after validation failure).

Ideal workaround is to iterate the entire collection again within the JSP
and submit the same as hidden.

If your collection is of some object having attributes like id and value
then you need to submit two separate collections one for each type of
attribute.

In this case you need to ensure that in your form bean if there is a
validation error you need to map the hidden collection back into the form
just the way you do it while loading the page from the action class. You
will need to iterate through both the collections and remake the collection
of objects from the same and set it into the appropriate form property.

Please let me know if you need any further information.

Regards,
Vishal

On 1/10/06, Meenakshi Singh <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I would suggest that manually call validate and use Request Scope
> Not many people seem to be using this approach, yet I have found it to be
> the best overall solution.
>
> This is how it works:
> First of all make sure you do not have validate="true" set in your action
> mapping.You should call form.validate(..) manually.
>
> Then create a method to set up your request with any lists in scope. For
> example if you are using a DispatchAction you can simply have a private
> setUp(..) method in this Action. If you are creating separate Action
> classes
> for all of your different actions you might want to make this a separate
> class, or put it in a base Action class that your Actions can extend from.
> Now manually call your form's validate method, and then, based on whether
> ActionErrors return or not, you can decide what to do. If ActionErrors
> returns null/empty then validation was successful and you can continue
> your
> processing and forward on to success. If ActionErrors is not null/not
> empty,
> you have validation errors and need to call the setUp method to repopulate
> any lists then forward back to the JSP form.
>
> I am pasting a sample code from an article from a website to implement the
> above.
> You can look at this sample code & then try to implement it at your end.
>
>
> //class EmployeeDispatchAction
>
> private void setUp( HttpServletRequest request ) {
> Collection jobCodes = Service.getJobCodes();
> request.setAttribute("jobCodes", jobCodes);
> }
>
> public ActionForward setUpForm(ActionMapping mapping, ...) throws
> Exception {
> setUp( request );
> return (mapping.findForward(UIconstants.TO_FORM));
> }
>
> public ActionForward update(ActionMapping mapping, ...) throws
> Exception
> {
> ActionErrors errors = form.validate( mapping, request );
> if ( errors != null && !errors.isEmpty ) {
> saveErrors(request, errors);
> setUp(request);
> return (mapping.findForward(UIconstants.VALIDATION_FAILURE));
> }
> //Everything OK, continue on...
> return (mapping.findForward(UIconstants.SUCCESS));
> }
>
>
> Give it a try!!!
>
> Thanks & Regards,
> Meenakshi.
>
> PS: Let me know whether it worked for you or not.
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>