简体   繁体   English

在不使用selectOneMenu的情况下从XHTML访问JSF SelectItem.Label和Value

[英]Accessing JSF SelectItem.Label and Value from XHTML without selectOneMenu

I'm struggling with a little internationalization issue in one of my apps. 我在其中一个应用程序中遇到了一些国际化问题。 The story goes like this: 故事是这样的:

I have a datatable which displays records, and a selectOneMenu in order to select a column of the dataTable to be filtered for. 我有一个显示记录的数据表和一个selectOneMenu,以便选择要过滤的dataTable的列。 The selectOne is fed with SelectItems which are filled according to the actual locale in the backing bean on DataRefresh time. selectOne提供有SelectItem,这些SelectItem在DataRefresh时根据备用bean中的实际语言环境填充。

Now, when the user changes the locale the contents of the selectOne stay in the old locale until the page is rerendered. 现在,当用户更改语言环境时,selectOne的内容将保留在旧的语言环境中,直到重新呈现页面为止。 This is quite logical and expected. 这是很合逻辑的,也是可以预期的。

Of course I want that to change. 我当然希望改变。

So I tried writing an own selectOne which uses selectItems which contain references to languageFile entries in order to be able to change them without rerendering. 因此,我尝试编写自己的selectOne,该selectOne使用selectItems包含对languageFile条目的引用,以便能够更改它们而无需重新呈现。

Here's what I tried 这是我尝试过的

<select id="j_id5:filterSelector" name="j_id5:filterSelector" size="1"> 
    <c:forEach var="item" items="#{gridBean.filterFields}">
        <option value="#{item.Value}">#{msg[item.Label]}</option>
    </c:forEach>
</select>

Sadly JSF tells me the item does not have a Label or Value property, which I hardly believe. 可悲的是,JSF告诉我该项目没有Label或Value属性,我几乎不相信。 ;) ;)

Does anyone's got an idea how to access thise properties this way? 有谁知道如何以这种方式访问​​此属性?

It seems to me you should write: 在我看来,您应该写:

#{item.value}

instead of #{item.Value} , as standard JavaBeans convention is to have getXyz() getter for xyz property. 而不是#{item.Value} ,因为标准JavaBeans约定是让xyz属性具有getXyz() getter。

Also, why don't you provide a valueChangeListener to the UI component for locale selection, and then, inside it, populate the select item labels for that locale. 另外,为什么不向UI组件提供valueChangeListener以便进行语言环境选择,然后在其内部填充该语言环境的选择项标签。 That way you can use standard f:selectItems tag. 这样,您可以使用标准的f:selectItems标记。

I solved the issue with storing the filterfields twice. 我通过两次存储filterfield解决了这个问题。 Once for each language - runtime decission which is rendered. 对于每种语言一次-呈现运行时决定。 Not a nice one, but it works. 这不是一个很好的方法,但是可以。 Could'nt get the changeListener going... 无法使changeListener运行...

You could also make it so your command links re-render the page so that it automatically does what you need it to. 您也可以这样做,以便您的命令链接重新呈现页面,以便它自动执行您需要的操作。 Don't know if this meets your requirements or not. 不知道这是否满足您的要求。 :) :)

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

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