*
The moose likes Struts and the fly likes Different Views using Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Different Views using Struts" Watch "Different Views using Struts" New topic
Author

Different Views using Struts

Krishna Attravanam
Greenhorn

Joined: Oct 21, 2004
Posts: 16
Hi I have an data-entry jsp which needs to offer three different views based on a certain set of conditions


There are three text fields

1) Old password
2) New Password
3) Enter New Password again

1,2 and 3 will be shown if the user is an owner
1 will be replaced by a label if the user is a moderator
1 will not be shown for all the other users

how do i go about doin validation for this??

Any other please let me know

~K
Michal Bienek
Greenhorn

Joined: Jun 17, 2002
Posts: 29
This wouldn't necessarily be struts-specific, but all you need to do is identify the user in the action that is executed prior to your jsp display. In your jsp, you can use <logic:equal> and <logic:notEqual> tags to figure out what type your user is in order to display your form fields.
You can do this much cleaner with JSTL tags, but I don't know them well enough to provide a code sample. Here it is with struts tags:
Danilo Gurovich
author
Greenhorn

Joined: Aug 08, 2002
Posts: 7
It really depends on how "production level" your code is going to be, and what you'll be doing with it from there. I would suggest a tiles based solution that loads an independent template and then you can load tiles in and out of the page depending upon your view.

Think of Tiles as a "controller" for your view layer, with the individual tiles and templates controlled by your definitions. Your Actions then call definitions only, and you can then fully encapulate your application and really lower the amount of duplicated code, so anytime you change something once, it changes it everywhere.

There's always a trade off. Sometimes it's the speed of development, sometimes it's in maintenance, sometimes it's just philosophy. I don't like to have logic on my page that says "well, show this, unless something here is happening, or something here, or....". You end up getting into some maintenance issues....


Danilo Gurovich<br />Manager, Web Development<br /> <br />dgurovich@lowermybills.com<br />2401 Colorado Ave., 2nd Floor <br />Santa Monica, CA 90404<br />(310) 998-6412
bas duijzings
Ranch Hand

Joined: Apr 07, 2004
Posts: 83
maybe it is just an extra, but the sample chapter of struts recipes does give more information about how the below can be set up

<!-- these lines handle field 1 --!>

<logic:equal name="user" property="type" value="owner">

<html assword name="oldPassword"/>

</logic:equal>


regardz
baz


have a nice one
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Different Views using Struts
 
Similar Threads
need help with design of a Login page in JSP
can not understand
For loop not executing
Combination of many-to-many and findAll
Edit the profile