Struts 2
  1. Struts 2
  2. WW-3289

Error when rendering <s:select> tag that contains UTF-8 characters in "listValue" attribute AFTER client-side validation

    Details

    • Type: Temp Temp
    • Status: Closed
    • Priority: Trivial Trivial
    • Resolution: Not a Problem
    • Affects Version/s: 2.1.8
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Centos 5.3
      Java 1.6
      Tomcat 6.0.20
      Struts 2.1.8

      Description

      Hi:
      I really don't know what component is the one that is failing (I guess the validation interceptor), so I'll try to explain as many details as possible.

      I have my form.jsp as follows:

      <s:form action="saveTeam" namespace="/2" method="post" enctype="multipart/form-data" validate="true">
      <s:textfield name="team.name" value="%

      {team.name}

      " label="%

      {getText('label.name')}

      " size="25" required="true" maxlength="50"/>
      <s:select name="team.stadium.idStadium" value="%

      {team.stadium.idStadium}

      " label="%

      {getText('label.stadium')}

      " list="stadiums" listKey="idStadium" listValue="name"/>
      <s:file name="image" label="label.image" accept="image/jpeg"/>
      <s:hidden name="team.idTeam" value="%

      {team.idTeam}

      "/>
      <s:submit value="%

      {getText('button.label.submit')}

      "/>
      </s:form>

      I used the "Preparable interface approach" to repopulate controls when validation fails, and it worked flawlessly, but... in this example, when the name of the stadium has UTF-8 characters (for example: á, ñ, ö), the HTML page doesn't finish rendering AFTER validation errors (the first time, the form.jsp is displayed correctly without problems), and it stops at the <select> tag before the "weird" character.

      This is the HTML code:

      <form id="saveTeam" name="saveTeam" onsubmit="return validateForm_saveTeam();" action="/2/saveTeam.action" method="post" enctype="multipart/form-data" onreset="clearErrorMessages(this);clearErrorLabels(this);">
      <table class="wwFormTable">
      <tbody><tr errorfor="saveTeam_team_name">
      <td colspan="2" align="center" valign="top"><span class="errorMessage">You must enter a name!</span></td>
      </tr>
      <tr>
      <td class="tdLabel"><label for="saveTeam_team_name" class="errorLabel">Name<span class="required">*</span>:</label></td>
      <td><input name="team.name" size="25" maxlength="50" value="" id="saveTeam_team_name" type="text"></td>
      </tr>

      <tr>
      <td class="tdLabel"><label for="saveTeam_team_stadium_idStadium" class="label">Stadium:</label></td>
      <td><select name="team.stadium.idStadium" id="saveTeam_team_stadium_idStadium">
      <option value="3" selected="selected">Deportivo Espa

      The stadium name is "Deportivo España", but somehow the "ñ" isn't displayed, and everything after that is ignored.
      I also tried with other characters like á or ö, and every time the <select> tag reaches the firs UTF-8 character it stops displaying the rest of the page.
      This ONLY happens AFTER validation errors. The first time the page is rendered, "Deportivo España" is shown correctly, and if I submit the form without any validation errors it works without problems.
      Also if there aren't any "strange" characters like "ñ", when there are validation errors the select tag displays correctly AFTER validation too.
      I think this is an UTF8 problem...

        Activity

        Lukasz Lenart made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Assignee Fernando Manrique [ lostlink ]
        Resolution Not A Problem [ 8 ]
        Jeff Turner made changes -
        Project Import Mon Feb 01 01:17:42 UTC 2010 [ 1264987062082 ]
        Fernando Manrique made changes -
        Field Original Value New Value
        Assignee Fernando Manrique [ lostlink ]
        Summary Bug when rendering <s:select> tag that contains UTF-8 characters in "listValue" attribute AFTER client-side validation Error when rendering <s:select> tag that contains UTF-8 characters in "listValue" attribute AFTER client-side validation
        Priority Major [ 3 ] Trivial [ 5 ]
        Issue Type Bug [ 1 ] Temp [ 6 ]
        Hide
        Fernando Manrique added a comment -

        I found a solution to my problem, it is NOT a struts2 bug!

        I was including the JSP <s:form> with the <s:include> tag from another JSP, and somehow, the first time it rendered the <s:select> tag in the JSP form everything was fine.
        But AFTER any validation errors the page wouldn't render correctly if the <s:select> tag had UTF-8 characters in it.

        To solve this problem I make sure I included
        <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
        at the top of ALL my JSPs, and I mean ALL... Even JSPs called with <s:include> tag.

        Also I had to make sure that inside the standard HTML tag <head> in the main JSP, the following meta tag was included:
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
        This is to force the browsers to render the page as UTF-8

        Thanks for reading!

        Show
        Fernando Manrique added a comment - I found a solution to my problem, it is NOT a struts2 bug! I was including the JSP <s:form> with the <s:include> tag from another JSP, and somehow, the first time it rendered the <s:select> tag in the JSP form everything was fine. But AFTER any validation errors the page wouldn't render correctly if the <s:select> tag had UTF-8 characters in it. To solve this problem I make sure I included <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> at the top of ALL my JSPs, and I mean ALL... Even JSPs called with <s:include> tag. Also I had to make sure that inside the standard HTML tag <head> in the main JSP, the following meta tag was included: <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> This is to force the browsers to render the page as UTF-8 Thanks for reading!
        Fernando Manrique created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Fernando Manrique
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development