问题描述
我想使用primefaces自动完成组件在我的项目,以避免编写特定的转换器,每个列表对象我想使用的的建议在here和here通过BalusC',我试图复制完全相同的方式,但也没能得到这个工作。请查看以下code段和建议,如果我在这里缺少什么?
在code的第一部分[F:selectOneMenu用于]在没有anyissues工作的精绝
XHTML
< HTML的xmlns =http://www.w3.org/1999/xhtml
的xmlns:H =http://xmlns.jcp.org/jsf/html
的xmlns:UI =http://xmlns.jcp.org/jsf/facelets
的xmlns:P =http://primefaces.org/ui
的xmlns:F =http://xmlns.jcp.org/jsf/core>
<用户界面:作文模板=WEB-INF /布局/ layout.xhtml>
< UI:定义名称=内容>
< H:形式>
&所述; H:的outputText ID =SELECTED_STATUS
值=#{} mybean.objLuStatus.strDescColVal/>
< - H:!selectOneMenu用于工作的罚款 - >
< H:selectOneMenu用于ID =的iterator2VALUE =#{} mybean.objLuStatus
转换器=omnifaces.SelectItemsConverter>
< F:选择信息itemLabel =选择项noSelectionOption =真/>
< F:selectItems的值=#{} mybean.lstStatusVAR =实体
itemLabel =#{} entity.strDescColValitemValue =#{}实体/>
< F:AJAX渲染=SELECTED_STATUS/>
< /小时:selectOneMenu用于>
< - P:自动完成不工作 - >
<电话号码:自动完成ID =iterator3VALUE =#{} mybean.objLuStatus
转换器=omnifaces.ListConverter下拉菜单=真正的VAR =实体
itemLabel =#{} entity.strDescColVal
占位=-----选择之一-----itemValue =#{}实体
completeMethod =#{} mybean.completeList>
< F:AJAX渲染=SELECTED_STATUS/>
< / P:自动完成>
< H:的commandButton值=提交行动=#{} mybean.post/>
< /小时:形式>
< / UI:定义>
< / UI:组合物>
< / HTML>
托管Bean
的Bean;
进口的java.util.ArrayList;
进口的java.util.List;进口javax.annotation.PostConstruct;
进口javax.faces.bean.ManagedBean;
进口javax.faces.bean.ViewScoped;进口com.ntr.foundation.model.LuStatus;@ManagedBean(NAME =mybean)
@ViewScoped
公共类MyManagedBean扩展BaseManagedBean实现Serializable { 清单< LuStatus> lstStatus;
LuStatus objLuStatus; @PostConstruct
公共无效的init(){
lstStatus =新的ArrayList< LuStatus>();
lstStatus.add(新LuStatus(1,草稿,DraftLong));
lstStatus.add(新LuStatus(2,已批准,ApprovedLong));
} 公开名单< LuStatus> getLstStatus(){
返回lstStatus;
} 公共无效setLstStatus(列表< LuStatus> lstStatus){
this.lstStatus = lstStatus;
} 公共无效后(){
的System.out.println(返回值+ objLuStatus);
} 公共LuStatus getObjLuStatus(){
返回objLuStatus;
} 公共无效setObjLuStatus(LuStatus objLuStatus){
this.objLuStatus = objLuStatus;
} 公开名单< LuStatus> completeList(字符串strQuery){
返回lstStatus;
}}
但我得到以下错误...
在此先感谢..
产生的原因:显示java.lang.NullPointerException
在org.omnifaces.converter.ListConverter.getAsObject(ListConverter.java:39)omnifaces-1.7.jar:1.7]
在org.primefaces.component.autocomplete.AutoCompleteRenderer.getConvertedValue(AutoCompleteRenderer.java:600) [primefaces-4.0.jar:4.0]
在javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046)[JSF-API-2.2.4.jar:2.2]
在javax.faces.component.UIInput.validate(UIInput.java:976)[JSF-API-2.2.4.jar:2.2]
对不起,我忽略了ListConverter文件的一行..我错过喂养与原来的列表类似下面。
的ListConverter <○:转换器converterId =omnifaces.ListConverter列表=#{} mybean.lstStatus/>
我得到这个通过添加上述code线的工作。
最后XHTML是将会是什么样的下面。
<电话号码:自动完成ID =iterator3VALUE =#{} mybean.objLuStatusforceSelection =真
下拉=真正的VAR =实体
itemLabel =#{} entity.strDescColVal
占位=-----选择之一-----itemValue =#{}实体
completeMethod =#{} mybean.completeList>
< F:AJAX渲染=SELECTED_STATUS/>
<○:转换器converterId =omnifaces.ListConverter列表=#{} mybean.lstStatus/>
< / P:自动完成>
感谢您omnifaces团队提供这样一个有用的工具...
I am trying to use primefaces autocomplete component in my project, in order to avoid writing specific converter to each list object I am trying to use omnifaces as suggested in here and here by 'BalusC', I tried to replicate exactly same way but could not able get this work. please review below code snippet and advice if I am missing anything here?
First part of the code [f:selectOneMenu] is working absolutely fine without anyissues
XHTML
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:composition template="WEB-INF/layout/layout.xhtml">
<ui:define name="content">
<h:form>
<h:outputText id="selected_status"
value="#{mybean.objLuStatus.strDescColVal}" />
<!-- h:selectOneMenu Working fine -->
<h:selectOneMenu id="iterator2" value="#{mybean.objLuStatus}"
converter="omnifaces.SelectItemsConverter">
<f:selectItem itemLabel="Choose item" noSelectionOption="true" />
<f:selectItems value="#{mybean.lstStatus}" var="entity"
itemLabel="#{entity.strDescColVal}" itemValue="#{entity}" />
<f:ajax render="selected_status" />
</h:selectOneMenu>
<!-- p:autoComplete is NOT Working -->
<p:autoComplete id="iterator3" value="#{mybean.objLuStatus}"
converter="omnifaces.ListConverter" dropdown="true" var="entity"
itemLabel="#{entity.strDescColVal}"
placeholder="----- Select One -----" itemValue="#{entity}"
completeMethod="#{mybean.completeList}">
<f:ajax render="selected_status" />
</p:autoComplete>
<h:commandButton value="Submit" action="#{mybean.post}" />
</h:form>
</ui:define>
</ui:composition>
</html>
Managed Bean
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import com.ntr.foundation.model.LuStatus;
@ManagedBean(name = "mybean")
@ViewScoped
public class MyManagedBean extends BaseManagedBean implements Serializable {
List<LuStatus> lstStatus;
LuStatus objLuStatus;
@PostConstruct
public void init() {
lstStatus = new ArrayList<LuStatus>();
lstStatus.add(new LuStatus("1", "Draft", "DraftLong"));
lstStatus.add(new LuStatus("2", "Approved", "ApprovedLong"));
}
public List<LuStatus> getLstStatus() {
return lstStatus;
}
public void setLstStatus(List<LuStatus> lstStatus) {
this.lstStatus = lstStatus;
}
public void post() {
System.out.println("returned value " + objLuStatus);
}
public LuStatus getObjLuStatus() {
return objLuStatus;
}
public void setObjLuStatus(LuStatus objLuStatus) {
this.objLuStatus = objLuStatus;
}
public List<LuStatus> completeList(String strQuery) {
return lstStatus;
}
}
But I am getting below error...
Thanks in advance..
Caused by: java.lang.NullPointerException
at org.omnifaces.converter.ListConverter.getAsObject(ListConverter.java:39) [omnifaces-1.7.jar:1.7]
at org.primefaces.component.autocomplete.AutoCompleteRenderer.getConvertedValue(AutoCompleteRenderer.java:600) [primefaces-4.0.jar:4.0]
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046) [jsf-api-2.2.4.jar:2.2]
at javax.faces.component.UIInput.validate(UIInput.java:976) [jsf-api-2.2.4.jar:2.2]
Sorry I overlooked one line of ListConverter documentation.. I missed feeding the ListConverter with the original list like mentioned below.
<o:converter converterId="omnifaces.ListConverter" list="#{mybean.lstStatus}" />
I got this worked by adding above line of code.
Final xhtml is going to look like below..
<p:autoComplete id="iterator3" value="#{mybean.objLuStatus}" forceSelection="true"
dropdown="true" var="entity"
itemLabel="#{entity.strDescColVal}"
placeholder="----- Select One -----" itemValue="#{entity}"
completeMethod="#{mybean.completeList}">
<f:ajax render="selected_status" />
<o:converter converterId="omnifaces.ListConverter" list="#{mybean.lstStatus}" />
</p:autoComplete>
Thank you to omnifaces team for providing such a useful utility...
这篇关于使用omnifaces primefaces自动完成POJO支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!