Struts 2
  1. Struts 2
  2. WW-2171

Label tag does not use key attribute to lookup value in resources when using simple theme

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.9
    • Fix Version/s: 2.1.1
    • Component/s: Plugin - Tags
    • Labels:
      None
    • Flags:
      Patch

      Description

      When using the simple theme (setting property "struts.ui.theme" to "simple"), the struts label tag does not use the key attribute to look up label value in resources.
      It does when using the css_xhtml theme.

      Example jsp fragment:

      <s:label key="company.name"/>

      Resource file fragment:

      company.name=Company name

      Html produced by css_xhtml theme (minus some space and divs):

      <label class="label" for="xxxxx_company_name">Company name:</label>

      (I am not sure where the "for" attribute comes from. I suspect that the html label tag is produced
      by css_xhtml/controlheader-core.ftl).

      Html produced by simple theme:

      <label id="xxxxx_company_name"/>

      Html that I expected simple theme to produce:

      <label id="xxxxx_company_name">Company name</label>

      1. label-patch.txt
        3 kB
        Maja S Bratseth

        Issue Links

          Activity

          Hide
          Maja S Bratseth added a comment -

          Patch

          Show
          Maja S Bratseth added a comment - Patch
          Hide
          Maja S Bratseth added a comment -

          Attached patch

          Show
          Maja S Bratseth added a comment - Attached patch
          Hide
          Maxx added a comment -

          I also had this problem populating the "value" for a label, so after looking at the .ftl file, I found this:
          You have to use
          <s:label value="%

          {getText('company.name')}

          "/>

          But I agree, this is not obvious regarding the other tags...

          Note: the "label" tag is generated through the template file: <theme>/label.ftl

          Example:

          test.jsp:
          --------------
          <pre>
          s:label for "firstname" with name="test.user.firstname"
          <s:label id="l_firstname" for="firstname" name="test.user.firstname" />

          s:label for "firstname" with name="%

          {getText('test.user.firstname')}"
          <s:label id="l_firstname" for="firstname" name="%{getText('test.user.firstname')}

          " />

          s:label for "firstname" with value="%

          {getText('test.user.firstname')}"
          <s:label id="l_firstname" for="firstname" value="%{getText('test.user.firstname')}

          "></s:label>
          <pre>
          --------------

          with test.user.firstname=Firstname in a global message resource

          HTML output:
          ---------------
          <pre>
          s:label for "firstname" with name="test.user.firstname"
          <label id="l_firstname" for="firstname"></label>

          s:label for "firstname" with name="%

          {getText('test.user.firstname')}"
          <label id="l_firstname" for="firstname"></label>

          s:label for "firstname" with value="%{getText('test.user.firstname')}

          "
          <label id="l_firstname" for="firstname">Firstname</label>
          </pre>
          ---------------

          Show
          Maxx added a comment - I also had this problem populating the "value" for a label, so after looking at the .ftl file, I found this: You have to use <s:label value="% {getText('company.name')} "/> But I agree, this is not obvious regarding the other tags... Note: the "label" tag is generated through the template file: <theme>/label.ftl Example: test.jsp: -------------- <pre> s:label for "firstname" with name="test.user.firstname" <s:label id="l_firstname" for="firstname" name="test.user.firstname" /> s:label for "firstname" with name="% {getText('test.user.firstname')}" <s:label id="l_firstname" for="firstname" name="%{getText('test.user.firstname')} " /> s:label for "firstname" with value="% {getText('test.user.firstname')}" <s:label id="l_firstname" for="firstname" value="%{getText('test.user.firstname')} "></s:label> <pre> -------------- with test.user.firstname=Firstname in a global message resource HTML output: --------------- <pre> s:label for "firstname" with name="test.user.firstname" <label id="l_firstname" for="firstname"></label> s:label for "firstname" with name="% {getText('test.user.firstname')}" <label id="l_firstname" for="firstname"></label> s:label for "firstname" with value="%{getText('test.user.firstname')} " <label id="l_firstname" for="firstname">Firstname</label> </pre> ---------------
          Hide
          Ted Husted added a comment -

          Completed: At revision: 614842 – Thanks Maja!

          Show
          Ted Husted added a comment - Completed: At revision: 614842 – Thanks Maja!
          Hide
          Ted Husted added a comment -

          I think this commit missed today's build, Maja, but if you can grab the JAR tomorrow, and try it in your application, that would be great!

          Show
          Ted Husted added a comment - I think this commit missed today's build, Maja, but if you can grab the JAR tomorrow, and try it in your application, that would be great! http://people.apache.org/builds/struts/nightlies/2.x/

            People

            • Assignee:
              Ted Husted
              Reporter:
              Maja S Bratseth
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development