Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Different Views using Struts

 
Krishna Attravanam
Greenhorn
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

~K
 
Michal Bienek
Greenhorn
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:
 
Danilo Gurovich
author
Greenhorn
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....
 
bas duijzings
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"/>

</logic:equal>


regardz
baz
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic