struts2 - Display content depends on radio button selection use jquery, switch action or roles interceptor? -


i have web application has 2 user type, admin , reader. reader has 1 function logout. admin has 2 functions user management , logout.

in jsp file use following code interface both user type

<s:if test="#session.user_sesssion_handle.admin.contains(\"y\")"> <td  width="100px" align="right">  <s:url var="usermaintindex" namespace="/usermaint" action="usermaint_view" /> <s:a href="%{usermaintindex}">user management</s:a> </td> </s:if>  <td> <s:url var="logouturl" namespace="/" action="logout" /> <s:a href="%{logouturl}">logout</s:a>  </td> 

so when reader logins application, reader finds logut url whereas admin finds 2 urls user management , logout.

recently users belong admin user type, want new feature allow them switch admin , reader type dynamincally in web application. reason users request switch user type want read different content when user type changed.

the first idea comes in mind use jquery achieve it, however, still new , not sure can switch interface dynamincally.

i have idea , try write code it.

in jsp file add code try fulfil requriement

<script type="text/javascript">      function toggle(value){  var modevalue;  modevalue = value;  alert(modevalue); } </script>  <s:if test="#session.user_sesssion_handle.admin.contains(\"y\")"> <td  width="100px" align="right">  <s:radio name="mode" label="mode" list="{'admin','reader'}" checked="reader"     onclick="toggle(this.value)"/> <s:url var="usermaintindex" namespace="/usermaint" action="usermaint_view" /> <s:a href="%{usermaintindex}">user management</s:a> </td> </s:if> 

in code intend use radio button admin users switch user type , set default user type reader. use onlick function because try test radio button returns proper value. therefore, when admin clicks radio button, there pop window show value admin user selects.

so far, test fine, radio button shows correct value when clicked. try set session variable radio button's value.

i have tried put

sessionstorage.sessname = "modevalue"  

in toggle function in script , add

&& #session.modevalue.contains(\"reader\") 

the full code this

<script type="text/javascript">      function toggle(value){  var modevalue;  modevalue = value;  alert(modevalue);  sessionstorage.sessname = "modevalue" } </script>  <s:if test="#session.user_sesssion_handle.admin.contains(\"y\") &&     #session.modevalue.contains(\"reader\")"> <td  width="100px" align="right">  <s:radio name="mode" label="mode" list="{'admin','reader'}" checked="reader"         onclick="toggle(this.value)"/> </td> </s:if>  <s:if test="#session.user_sesssion_handle.admin.contains(\"y\")> <td  width="100px" align="right">  <s:url var="usermaintindex" namespace="/usermaint" action="usermaint_view" /> <s:a href="%{usermaintindex}">user management</s:a> </td> </s:if> 

in code intend set session variable in script , use condition in . if admin logins application, he/she sees radio button , "reader" set default, he/she not find user management link. if admin user selects "admin" in radio button, user management link appear near radio button.

when test application, no matter radio button value "admin" or "reader", "user management" link still appear.

i have action class (usermode.java) issue, notice if commented of code, seems no effect jsp part.

package action.usermode; import com.opensymphony.xwork2.actionsupport;   public class usermodeaction extends actionsupport{      /* if commented part seems no effect jsp part private string mode;  public string getmode() {     return mode; }  public void setmode(string mode) {     this.mode = mode; }    */ } 

so ask how display link depends on radio button selection?

i read posts switch action , roles intercepter not sure should apply in application because application has 2 user types , switch action , roles intercepter seems use many user types in application or misunderstand concept them?

i grateful if gives advice please. lot.

references

display different results based on radio button selection

displaying content based on radio button selection

switch action in struts 2

what switch action & forwardaction in struts

make struts show different jsps different roles

https://struts.apache.org/docs/roles-interceptor.html

https://struts.apache.org/maven/struts2-core/apidocs/org/apache/struts2/interceptor/rolesinterceptor.html


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -