headerKey=“-1"有什么问题? [英] What is wrong with headerKey="-1"?

查看:23
本文介绍了headerKey=“-1"有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么问题:

<s:select list="fruits" name="fruitSelect" id="fruitSelect"
listKey="fid" listValue="fname" headerKey="-1" headerValue="Pick a fruit!" />

大量在线示例使用此值:http://www.coderanch.com/t/439139/Struts/wrong-selecthttp://www.mkyong.com/struts2/struts-2-sselect-drop-down-box-example/

Plenty of online examples use this value: http://www.coderanch.com/t/439139/Struts/wrong-select http://www.mkyong.com/struts2/struts-2-sselect-drop-down-box-example/

但是实际的文档(你可以通过将鼠标悬停在符号上来查看 Eclipse 的工具提示)说

BUT the actual documentation (you can view this on the tooltip in Eclipse by hovering over the symbol) says

列表中第一项的键.不能为空!'-1' 和 '' 是正确的, '' 是不好.

Key for first item in list. Must not be empty! '-1' and '' is correct, '' is bad.

-1 对我来说似乎很合乎逻辑,无论如何它不应该是一个有效的选项.是正确的,"对我来说没有任何意义,所以我不太担心.

-1 seems pretty logical to me and it shouldn't be a valid option anyway. " is correct, " doesn't make sense on any level to me so I am not too concerned by it.

推荐答案

key没有问题,但是docs可能有点问题:-1是整数key,'-1' 是字符串,'' 是空字符,"" 是空字符串,但key 不能为空.因此 -1'-1'' '" " 是有效值.来自文档:

Nothing wrong with the key but may be a little bit with docs: -1 is an integer key, '-1' is a string, '' is an empty char, "" is an empty string, but the key should not be empty. Thus -1, '-1', ' ', " " are valid values. From the docs:

'1' 是一个字符,'01' 是一个字符串,1"是一个字符串.这很重要,因为如果value"属性返回的值与list"属性中的键类型不同,它们将不匹配,即使它们的字符串值可能相同.如果它们不匹配,则列表中没有任何内容将被自动选中.

'1' is a char, '01' is a String, "1" is a String. This is important since if the value returned by your "value" attribute is NOT the same type as the key in the "list" attribute, they WILL NOT MATCH, even though their String values may be equivalent. If they don't match, nothing in your list will be auto-selected.

您应该为 listKey 属性提供相应的字段类型,因此 -1 是用于数字类型的整数,而不是 ' '" " 用于字符和字符串类型.

You should provide to the listKey attribute a corresponding field type, so -1 is for integer of numeric types, rather than ' ' and " " are for character and string types.

框架在比较 select 标记的键和值时使用类型转换,为了避免在 OGNL 运行时某处发生类型转换错误,您最好提供正确的类型,并且两个关键属性有同一类型.如果不应该为空的键值与两个属性中指定的值匹配,则将填充标题值选项.

The framework uses a type conversion when comparing keys and values of the select tag and to avoid a typecast errors occurred somewhere at the OGNL runtime you'd better provide the type correctly and two key attributes have the same type. And if the key value, which should be not empty, matches the value specified in the both attributes the header value option will be populated.

这篇关于headerKey=“-1"有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆