Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Different Views using Struts

Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"/>


It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic