0

I got three Radio Buttons:

<input type="radio" name="is_active" value="true">Active&nbsp;&nbsp;&nbsp;
<input type="radio" name="is_active" value="false">Inactive&nbsp;&nbsp;&nbsp;
<input type="radio" name="is_active" value="both" checked>Both<br>

And then some JSP. When I write:

<%=request.getParameter("is_active")%>

I get "both", "true" or "false" in my HTML. But when I write:

<s:if test='%{#request.getParameter("is_active") == ("both")}'>

The output of <%=request.getParameter("is_active")%> is always: true or false or both. One of this three options. The server does not go into the if block even if I choose "Both" radiobutton. What is wrong?

TheKolanN
  • 61
  • 3
  • 13
  • [http://stackoverflow.com/questions/17817767/how-can-i-use-request-parameter-in-struts2-if-tag](http://stackoverflow.com/questions/17817767/how-can-i-use-request-parameter-in-struts2-if-tag) – Braj May 26 '14 at 12:56
  • Why do you have all parameters in the request? – Roman C May 26 '14 at 13:07
  • @Braj: my if statement already looks exactly like the one in the link you provided: , so I do not understand your comment. Can you please explain? – TheKolanN May 26 '14 at 13:14
  • @RomanC: What do you by all parameters? – TheKolanN May 26 '14 at 13:15
  • "both", "true" or "false", also what is the order they printed? – Roman C May 26 '14 at 13:20
  • @RomanC: I still do not understand what are you asking about. I just put one parameter into request.getParameter("is_active") because this are radio buttons. – TheKolanN May 26 '14 at 13:26
  • If you place one parameter, how could you get all three ones? – Roman C May 26 '14 at 13:28
  • @RomanC: Still I do not know what are you talking about ;(. If I select 'both' in the radiobutton, I would like to display something, but the if does not work, the code processing do not go into the if block when I debug. Only one selection can be made in one time – TheKolanN May 26 '14 at 13:58
  • What is the output of `<%=request.getParameter("is_active")%>`? – Roman C May 26 '14 at 14:14
  • @RomanC: The output of <%=request.getParameter("is_active")%> is always: true or false or both. One of this three options. – TheKolanN May 26 '14 at 14:22
  • Why do you use parameters from request? Map your inputs into action variables. – Aleksandr M May 27 '14 at 10:50

1 Answers1

0

You are using Java comparison inside the OGNL expression. Strings are compared in Java using equals method.

<s:if test='#request.getParameter("is_active").equals("both")'> 

or with OGNL comparison

<s:if test="#parameters.is_active[0] == 'both'">
Roman C
  • 49,761
  • 33
  • 66
  • 176