1 Reply Latest reply on Sep 14, 2010 8:12 AM by Shane Bryzak

    messages inside javascript functions are not getting translated

    Joshua D Novice

      The label inside onclick method is not getting translated from the resource bundle. how should I fix this?


                      <s:link view="/Assignment"
                          onclick="if (confirm('#{messages['label.assignment.open']}')) {
                              var f = $('assignment');
                              f.method = 'POST';
                              f.action = f.submit();
                              } return false;">
                          <span>
                              <h:outputText value="#{messages['label.assignment.name']}"/>
                          </span>
                      </s:link>



        • 1. Re: messages inside javascript functions are not getting translated
          Shane Bryzak Master

          You could try assigning the message strings to JavaScript variables instead, and then reference them when you call confirm()


          E.g:


          var msg_label_assignment_open = "#{messages['label.assignment.open']";



          <s:link view="/Assignment"
                              onclick="if (confirm(msg_label_assignment_open)) {
                                  var f = $('assignment');
                                  f.method = 'POST';
                                  f.action = f.submit();
                                  } return false;">
                              <span>
                                  <h:outputText value="#{messages['label.assignment.name']}"/>
                              </span>
                          </s:link>



          When JSF renders the page it should replace the EL expression with the actual message string.  Note that I haven't tested this, so you might have to tweak the code a little bit.