简体   繁体   English

使用bean消息标签(i18n)在jsp中初始化输入标签(html)

[英]Initializing an input tag(html) in a jsp using a bean message tag (i18n)

Am new to JavaEE,so am still trying to find my feet. 我是JavaEE的新手,因此仍在努力寻找自己的脚。 Well,in order to internationalize my pages,am trying to initialize an input text tag using a bean message tag. 好吧,为了使我的页面国际化,我尝试使用bean消息标签初始化输入文本标签。

This is what i would have done if i wasn't interested in internationalizing my value attribute : 如果我对国际化value属性不感兴趣,这就是我会做的事情:

<tr>
 <td><bean:message key="form.birthdate" /><span>:</span></td>
   <td><html:text property="day" value="day" /></td>
     <td><html:text property="month" value="month" /></td>
    <td><html:text property="year" value="year" /></td>
</tr>

Now,i decided to initialize using a javascript file : 现在,我决定使用javascript文件进行初始化:

function initialise(){
document.getElementById("day").value="<bean:message key="form.day" />";
document.getElementById("month").value="<bean:message key="form.month" />";
document.getElementById("year").value="<bean:message key="form.year" />";
 }

so i call the function initialise() in my jsp : 所以我在我的jsp中调用了函数initialise():

<body onLoad="initialise();">

But it doesn't have any effect and i don't know why. 但这没有任何效果,我也不知道为什么。 I'lld really appreciate your help. 非常感谢您的帮助。 Thanks 谢谢

html:text should generate input box with an attribute name . html:text应该生成带有属性name输入框。 In your javascript you try to access this textbox by Id. 在您的JavaScript中,您尝试通过ID访问此文本框。 In order to make it possible try to add styleId attribute to your html:text elements. 为了使其成为可能,请尝试将styleId属性添加到html:text元素。 So it will look like: 因此它看起来像:

<html:text property="day" styleId="day" value="day" />

And do the same for month and year. 并对月份和年份进行相同的操作。

I finally figured out i had to use simple quotes in my initialise() function coupled with the styleId attribute already mentioned. 我终于发现我必须在我的initialize()函数中使用简单的引号,再加上已经提到的styleId属性。 So,in my jsp file i'll have : 因此,在我的jsp文件中,我将有:

<script type="text/javascript>
  function initialise(){
document.getElementById("day").value='<bean:message key="form.day" />';
document.getElementById("month").value='<bean:message key="form.month" />';
document.getElementById("year").value='<bean:message key="form.year" />';
}
</script>


<tr>
<td><bean:message key="form.birthdate" /><span>:</span></td>
 <td><html:text property="day" value="day" styleId="day" /></td>
 <td><html:text property="month" value="month" styleId="month" /></td>
<td><html:text property="year" value="year" styleId="year" /></td>
</tr>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM