0

I have a form which the user fills with its details & the same form is visible to the admin in the disable mode. Also there are few fields the admin can edit according to its role. So basically in the admin mode there are two buttons to UPDATE & VIEW. I tried implementing it using a session variable opMode. And added a scriptlet in jsp according to the opMode the fields are visible. But here I had to COPY the same fields thrice. Example :

     <% String opMode=(String)session.getAttribute("opMode");%>

       <%if(opMode.equals("ADD")){ %>          
        <s:textfield name="caserecord.case_Name" label="Case Name." size="25" />
        <%}%>  

       <%if((opMode.equals("VIEW")){ %>          
       <s:textfield name="caserecord.case_Name" label="Case Name." size="25" disabled="true"/>
        <%}%> 

        <%if((opMode.equals("UPDATE")){ %>          
       <s:textfield name="caserecord.case_Name" label="Case Name." size="25" />
        <%}%>

So is there a way in which I can use the same jsp for all the three tasks ie. ADD, VIEW & UPDATE without having to duplicate the fields.

Thanks in advance.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Pradnya
  • 649
  • 2
  • 6
  • 17
  • I had to COPY the same fields thrice. I didn't understand this point. please explain what code is duplicated. – Braj Jul 19 '14 at 11:07
  • I used a scriplet & for all 3 values in the session I made 3 form tags with same fields in it. – Pradnya Jul 19 '14 at 11:12
  • please share the code that is duplicate to make a clear picture. – Braj Jul 19 '14 at 11:15
  • see i have update my question. For the same case name I had to add three text boxes for different modes. – Pradnya Jul 19 '14 at 11:29
  • what is difference between first and third case. – Braj Jul 19 '14 at 11:33
  • it is just for example purpose. According to different user roles the update fields(unable/disable) will change. Anyways the question is, is there a way to use one single textbox and keep it disabled for view mode & unable for update mode – Pradnya Jul 19 '14 at 11:36
  • @Pradnya Set a variable based on whatever business logic you have and use that variable as the disabled attribute value. – Dave Newton Jul 19 '14 at 13:15

1 Answers1

0

You can modify the field using OGNL like

<s:if test="#session.opMode in {'ADD', 'VIEW', 'UPDATE'}">
  <s:textfield name="caserecord.case_Name" label="Case Name." size="25" disabled="%{#session.opMode == 'VIEW'?true:false}"/>
</s:if>
Roman C
  • 49,761
  • 33
  • 66
  • 176