Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Presentation question

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can someone suggest where should the logic for this go - In action or presentation?

I have a text box which I want to display if user has the role of ADMIN otherwise don't want to show that text box.

I'm thinking I should set the formbean variable in action to true or false and then check for that in the jsp. Is that a right approach ?

If yes, then this is kind of what I'm thinking in action:


And this in jsp:


But I get a null pointer exception with above in jsp.

If I use this instead:

<bean:write name="formbean" property="show_customer"/>

I do get the true and false appropriately depending on roles, but then how do I perform if else using JSTL ?

Thanks!
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your reasoning is sound. The idea is to put as much logic as possible in the Action class and as little as possible in the JSP.

I'm not entirely sure why your JSP code isn't working, but try this: Eliminate the <bean efine> tag and just code:

<c:if test="${formbean.map.show_customer}" >
// show text box
</c:if>
 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill,
Thanks for the reply.
I did try what you suggested, but that too gives me Null pointer exception.
What else should I try ?

Regards

Note - I've kind of noticed that EL doesn't work for me. Till now I've been avoiding it. I don't know why it doesn't work.
[ May 12, 2006: Message edited by: Raj Bhandari ]
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use <logic:equal> tag
<bean define id="show_cust" name="formbean" property="show_customer"/>
<logic:equal name="show_cust" value="true">
show text fied
</logic:equal>
 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Manoj for the suggestion. Appreciate it!
[ May 15, 2006: Message edited by: Raj Bhandari ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic