jQuery in Action, 3rd edition
The moose likes Struts and the fly likes Presentation question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Presentation question" Watch "Presentation question" New topic

Presentation question

Raj Bhandari
Ranch Hand

Joined: Oct 19, 2005
Posts: 97
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 ?

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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

Consultant, Sima Solutions
Raj Bhandari
Ranch Hand

Joined: Oct 19, 2005
Posts: 97
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 ?


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

Joined: Jun 20, 2004
Posts: 75
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
Raj Bhandari
Ranch Hand

Joined: Oct 19, 2005
Posts: 97
Thanks Manoj for the suggestion. Appreciate it!
[ May 15, 2006: Message edited by: Raj Bhandari ]
I agree. Here's the link: http://aspose.com/file-tools
subject: Presentation question
It's not a secret anymore!