How to change an html property depending on the value of a profile collected from java class

1

I have a text box in which I would like to be able to write or not depending on the profile that the application uses. This text box is in html code inside a .jsp and the verification of this profile is done in its action. How could I do it so that if the profile is the one I want, I can write in that text box and if it is not, no?

    <tr>
                <td>
                    <bean:message key="depen.insert.alas"/>
                </td>
                <td>
                    <html:text readonly="false" property="alas">
                    </html:text>
                </td>
            </tr>

And in the action I have to check a profile:

    String p = P.getP(request);

if it is a, the property will be readonly if it is b, but I do not know how to link these things to do this, I know it will not be very difficult but it is the first time I do it.

    
asked by Javier GT 01.09.2016 в 09:19
source

2 answers

1

As I imagined it was simple, only that having no experience and not having touched this never happen these things. In the same jsp I import the library where I have the method with which I capture the profile:

    <%@ page import="java.util.*" %>
    <%@ page import="libreria.capturar.perfil.*"%>

This is the way to write java code in jsp and import libraries, we will continue to see it (I am referring to <%% > [I did not know it]).

Now I write the change that my code has suffered by knowing how to write java in jsp and how to capture the profile to make the condition:

    <tr>
        <td>
            <bean:message key="depen.insert.alas"/>
        </td>
        <td>
            <%String p = P.getP(request);
            if(p.equals("Admin")){%>
                  <html:text readonly="false" property="alas">
                  </html:text>
            <%}else{%>
                  <html:text readonly="true" property="alas">
                  </html:text>
            <%}%>
        </td>
    </tr>

I hope it can help someone lost as I help in the future.

    
answered by 02.09.2016 / 14:02
source
2

Is your text box a input or a testarea ? In any case you have the property disabled that specifies whether it is enabled or not.

<input type="text" name="name" disabled>
<textarea disabled>Loren ipsum dolor sit..</textarea>

In jsp I think you have the property disabled and the property readonly that accept a boleado value.

<html:text readonly="true" disabled="true" ></html:text>

You can make a condition that checks the type of profile and enable or not depending on your needs. I have never worked with jsp, but I think it would work something like that.

var deshabitado = false
if (p === a) {
  deshabitado = true
} else {
  deshabitado = false
}
<html:text disabled="<%= deshabitado %>" ></html:text>
    
answered by 01.09.2016 в 09:24