我已经编写了一个自定义渲染器类来修复 Primefaces 问题#5869,现在尝试在我正在开发的网站上使用它。我已经通过包括来做到这一点
<renderer>
<component-family>org.primefaces.component</component-family>
<renderer-type>org.primefaces.component.inputtext.InputTextRenderer</renderer-type>
<renderer-class>at.ac.uibk.library.utils.fixedInputTextRenderer</renderer-class>
</renderer>
在我的 faces-config.xml 中。 但是用js仍然可以插入超过指定的字符限制。
我在fixedInputTextRenderer中添加了这些行,它应该进行必要的检查
if (submittedValue != null) {
int maxlength = inputText.getMaxlength();
if (maxlength > 0 && submittedValue.length() > maxlength) {
submittedValue = submittedValue.substring(0, maxlength);
}
inputText.setSubmittedValue(submittedValue);
}
最佳答案
指定<renderer-type>
错误的是:
<renderer-type>org.primefaces.component.inputtext.InputTextRenderer</renderer-type>
根据VDL documentation的 <p:inputText>
它默认注册在 org.primefaces.component.InputTextRenderer
.
Component information
Info Value Component Type org.primefaces.component.InputText
Handler Class None Renderer Type org.primefaces.component.InputTextRenderer
Description None
因此进行相应调整:
<renderer-type>org.primefaces.component.InputTextRenderer</renderer-type>
请注意,组件类型和渲染器类型实际上并不代表 FQN,而只是键/标识符。它们看起来像 FQN 确实是强制唯一性的一个不幸的副作用,这确实会让初学者感到困惑。
另请参阅:
关于jsf - PrimeFaces 组件的自定义渲染器未注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65718999/