ofbiz总结——当有很多条消息时右下角“显示全部”乱码

78 篇文章 6 订阅
49 篇文章 2 订阅

问题:ofbiz操作完成后提示的消息有很多条时,右下角的“显示全部”乱码



解决方案:

参考lookup查找选中后输入框乱码解决方案,他们原理是相同的。

具体步骤:

1. 把系统语言切换到en

2. 再次操作弹出消息框,可以看奥右下角显示“show all”字符串。

3. 在framework\common\config\CommonUiLabels.xml中找到en对应为show all的定义。对应的key是CommonShowAll

4. 使用notepad++在ofbiz项目目录下搜索字符串“CommonShowAll”。

5. 找到我们想要的的信息在framework\common\template\includes\Messages.ftl

6. 参照lookup乱码解决方案,修改Messages.ftl文件。

修改后的Messages.ftl文件

<#--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->
<script type="text/javascript">  

//字符实体转字符串  
function entityToString(entity){  
  var entities=entity.split(';')  
  entities.pop()  
  var tmp=''  
  for(var i=0;i<entities.length;i++){  
    var num=entities[i].trim().slice(2)  
    if(num[0]==='x')//10进制还是16进制  
      num=parseInt(num.slice(1),16);  
    else num=parseInt(num);  
    tmp+=String.fromCharCode(num)  
  }  
  return tmp  
}  

//----------------------------------------------------UTF-8变换为GBK--------------------------------------------------------  
var unicodeReg=/&#[\da-fA-Fx]{1,6};/ig;  
  
/***********************************************Changetheunicodetostring*@paramstr*@returns*/  
  
function Unicode2oStr(str){  
	str = str.replace(/&/g,"&")
    var arr=str.match(unicodeReg);  
    if(arr==null) return(str);  
  
    var index=str.indexOf(arr[0]);  
  
    var LastIndex=str.lastIndexOf(arr[arr.length-1]);  
    LastIndex=LastIndex+arr[arr.length-1].length;  
    for(var i=0;i<arr.length;i++){  
        //arr[i]=String.fromCharCode(arr[i].replace(/[&#;]/g,""));  
        arr[i]=entityToString(arr[i]);  
    }  
  
    var changedStr=str.substring(0,index)+(arr.toString().replace(/,/g,""));  
    if(LastIndex!=-1){  
        changedStr=changedStr+str.substring(LastIndex);  
    }  
    return changedStr;  
}  
</script>  

<#escape x as x?html>
  <#if requestAttributes.errorMessageList?has_content><#assign errorMessageList=requestAttributes.errorMessageList></#if>
  <#if requestAttributes.eventMessageList?has_content><#assign eventMessageList=requestAttributes.eventMessageList></#if>
  <#if requestAttributes.serviceValidationException??><#assign serviceValidationException = requestAttributes.serviceValidationException></#if>
  <#if requestAttributes.uiLabelMap?has_content><#assign uiLabelMap = requestAttributes.uiLabelMap></#if>

  <#if !errorMessage?has_content>
    <#assign errorMessage = requestAttributes._ERROR_MESSAGE_!>
  </#if>
  <#if !errorMessageList?has_content>
    <#assign errorMessageList = requestAttributes._ERROR_MESSAGE_LIST_!>
  </#if>
  <#if !eventMessage?has_content>
    <#assign eventMessage = requestAttributes._EVENT_MESSAGE_!>
  </#if>
  <#if !eventMessageList?has_content>
    <#assign eventMessageList = requestAttributes._EVENT_MESSAGE_LIST_!>
  </#if>

  <#-- display the error messages -->
  <#if (errorMessage?has_content || errorMessageList?has_content)>
    <div id="content-messages" class="content-messages errorMessage"
        οnclick="document.getElementById('content-messages').parentNode.removeChild(this)">
      <#noescape><p>${uiLabelMap.CommonFollowingErrorsOccurred}:</p></#noescape>
      <#if errorMessage?has_content>
        <p>${StringUtil.wrapString(errorMessage)}</p>
      </#if>
      <#if errorMessageList?has_content>
        <#list errorMessageList as errorMsg>
          <p>${StringUtil.wrapString(errorMsg)}</p>
        </#list>
      </#if>
    </div>
  </#if>
  <#assign jGrowlPosition = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.jgrowl.position", delegator)>
  <#assign jGrowlWidth = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.jgrowl.width", delegator)>
  <#assign jGrowlHeight = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.jgrowl.height", delegator)>
  <#assign jGrowlSpeed = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.jgrowl.speed", delegator)>

  <script>showjGrowl(
          Unicode2oStr("${uiLabelMap.CommonShowAll}"), Unicode2oStr("${uiLabelMap.CommonCollapse}"), "${uiLabelMap.CommonHideAllNotifications}",
          "${jGrowlPosition}", "${jGrowlWidth}", "${jGrowlHeight}", "${jGrowlSpeed}");</script>
  <#-- display the event messages -->
  <#if (eventMessage?has_content || eventMessageList?has_content)>
  <div id="content-messages" class="content-messages eventMessage"
      οnclick="document.getElementById('content-messages').parentNode.removeChild(this)">
    <#noescape><p>${uiLabelMap.CommonFollowingOccurred}:</p></#noescape>
    <#if eventMessage?has_content>
      <p>${StringUtil.wrapString(eventMessage)}</p>
    </#if>
    <#if eventMessageList?has_content>
      <#list eventMessageList as eventMsg>
        <p>${StringUtil.wrapString(eventMsg)}</p>
      </#list>
    </#if>
  </div>
  <#assign jGrowlPosition = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.jgrowl.position", delegator)>
  <#assign jGrowlWidth = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.jgrowl.width", delegator)>
  <#assign jGrowlHeight = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.jgrowl.height", delegator)>
  <#assign jGrowlSpeed = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.jgrowl.speed", delegator)>
  <script>showjGrowl(
          Unicode2oStr("${uiLabelMap.CommonShowAll}"), Unicode2oStr("${uiLabelMap.CommonCollapse}"), "${uiLabelMap.CommonHideAllNotifications}",
          "${jGrowlPosition}", "${jGrowlWidth}", "${jGrowlHeight}", "${jGrowlSpeed}");</script>
  </#if>
</#escape>

注意:

这里注意Unicode2oStr方法根之前的有点改变。在前面加了下面代码:

str = str.replace(/&amp;/g,"&")

这个是因为发现中文会被2次转义。一次是中文转为html实体编码,第二次是“&”符合转义为“&amp;”。所以加上上面的代码才能正常显示中文。

CommonCollapse表示收起,也是要同CommonShowAll一样处理。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值