Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Presentation question

 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • 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!
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Manoj Raghuwanshi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Manoj for the suggestion. Appreciate it!
[ May 15, 2006: Message edited by: Raj Bhandari ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic