Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts2 disable <s:textfield> using some expression

I have two roles in my app, ROLE_ADMIN & ROLE_USER Also I have a form with some fields. I would like to have the following: When user has ADMIN role he is able to edit specific group of fields, when user has USER role he is not able to edit these fields. I don't want to have two different forms, or two copies of fields for every role.

I tried to do something like that:

<s:textfield key="..." disabled="${myFlag}" >, where myFlag evaluated from roles.

But I have warning "disabled" does not support runtime expressions.

Is there any way to do this? Or maybe there's better way, for example, by replacing generated input to label ?

Thanks in advance.

like image 409
Alexander K Avatar asked Dec 13 '22 08:12

Alexander K


1 Answers

You should use the OGNL expression by %{expression} syntax in a Struts2 tag.

<s:textfield disabled="%{myFlag}" />

how can I set such variable on page?

Doesn't work with %{myFlag}? Or you could set the the variable by

<s:set var="flag">${myFlag}</s:set>

Implementation :

<s:textfield disabled="#flag" />
like image 164
lschin Avatar answered Jan 23 '23 03:01

lschin