我有一个搜索文本,我必须在同一页面中搜索输入文本,就像我们通过ctrl + f搜索任何网页一样,它将显示输入文本的所有出现位置如何在jsf +中执行ICEfaces的。我的xhtml是
<h:inputText id="searchTextField" size="12" maxlength="10" value="#{editSplitAsgnsBean.searchTextField}">
</h:inputText>
<ice:commandButton styleClass="buttonPurple" value="#{msgs['EditSplitAsgns.Button.searchButton']}" id="searchButton"
actionListener="#{editSplitAsgnsController.searchButton}">
<ace:ajax execute="@this" render="@sortDataTable" />
</ice:commandButton>
在我的控制器中我这样做但得到NullPointerException
public void searchButton(ActionEvent e) {
searchTextField = editSplitAsgnsBean.getSearchTextField();
if(isNullOrEmpty(searchTextField)) { return; }
if(!validateInput(searchTextField, true, 10)){
popupHandler.displayMessage(getMessageString(EDIT_SPLIT_ASSIGNMENT_SEARCHSTRING_VALIDATION_MESSAGE));
return;
}
resetSearchData();
findMatchedColumn(SEARCH);
}
public void nextButton(ActionEvent e) {
findMatchedColumn(NEXT);
}
private void findMatchedColumn(String action) {
EditSplitAsgnsData searchRow = null;
String search = editSplitAsgnsBean.getSearchTextField();
if (NEXT.equals(action) && lastFoundIndex != -1) {
index++;
if (matchedColumns.size() > index) {
selectColumn = matchedColumns.get(index);
selectCell(getTable(), lastFoundIndex, selectColumn);
return;
}
}
int newFoundIndex = getTable().findRow(search, selectedColumns, lastFoundIndex + 1, DataTable.SearchType.CONTAINS, true);
matchedColumns.clear();
index = 0;
if (SEARCH.equals(action) && newFoundIndex == -1) {
popupHandler.displayMessage(getMessageString(COMMON_NOSORTSCHEME_DATA_MSG, search));
return;
}
if (NEXT.equals(action) && newFoundIndex == -1) {
popupHandler.displayMessage(getMessageString(EDIT_SPLIT_ASSIGNMENT_SEARCHSTRING_VALIDATION_MESSAGE, search));
searchFlag = false;
selectCell(getTable(), lastFoundIndex, selectColumn);
return;
}
searchFlag = true;
getTable().navigateToRow(newFoundIndex);
getTable().setRowIndex(newFoundIndex);
searchRow = (EditSplitAsgnsData) getTable().getRowData();
searchMatches(searchRow, search);
if (!CollectionsUtil.isNullOrEmpty(matchedColumns)) {
selectColumn = matchedColumns.get(index);
}
lastFoundIndex = newFoundIndex;
selectCell(getTable(), lastFoundIndex, selectColumn);
}
private void resetSearchData() {
lastFoundIndex = -1;
selectColumn = -1;
searchFlag = false;
}
堆栈跟踪
java.lang.NullPointerException
at com.fedex.emea.gss.controller.EditSplitAsgnsController.findMatchedColumn(EditSplitAsgnsController.java:483)
at com.fedex.emea.gss.controller.EditSplitAsgnsController.searchButton(EditSplitAsgnsController.java:464)
at com.fedex.emea.gss.controller.EditSplitAsgnsController$$FastClassByCGLIB$$6f1285ca.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
at com.fedex.emea.gss.controller.EditSplitAsgnsController$$EnhancerByCGLIB$$6e6697f4.searchButton(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:148)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:775)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:786)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1251)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
我是jsf的新手,所以不知道如何解决问题
答案 0 :(得分:0)
您的问题出在execute="@this"
,这意味着您只是在请求中发送命令按钮而不是Textfield。
为了解决这个问题,这里有可能的解决方案
execute="@form"
将在请求中发送所有表单属性execute="searchTextField"
会在请求中发送searchTextFieldId。这是最好的解决方案。照顾"searchFieldId"
的路径。您需要使用完整路径作为另一个建议,我通常使用"listener"
的{{1}}属性并避免使用"ajax"
。理论上你不需要带命令按钮的ajax。 commandButton已经使用了ajax。希望这有帮助