我有一个搜索authors
的页面。它应该显示有关找到的作者的信息,或者在找不到作者时显示消息。
我正在尝试使用<rich:notifyMessage>
,但问题是当我使用它时,找不到找到的作者的结果,并且信息也出现在页面的右上角我希望它出现在面板下方,搜索结果会出现在面板上。
看看我是怎么做的,有没有更好的方法呢?
XHTML
<h:form>
<br />
<br />
Insert Author
<br />
<br />
<br />
<rich:panel id="panel" style="width:310px">
<f:facet name="header">Search for the author you want to insert</f:facet>
<h:panelGrid columns="3">
Name: <h:inputText value="#{insertAuthorController.nameToSearch}" />
<a4j:commandButton value="Search" action="#{insertAuthorController.searchAuthor()}">
</a4j:commandButton>
</h:panelGrid>
</rich:panel>
<br />
<rich:notifyMessage/>
<rich:dataTable value="#{insertAuthorController.authorListOfMap}" var="result">
<c:forEach items="#{insertAuthorController.variableNames}" var="vname">
<rich:column>
<f:facet name="header">#{vname}</f:facet>
#{result[vname]}
</rich:column>
</c:forEach>
</rich:dataTable>
<br />
<h:commandButton value="Go to insert page" action="#{insertAuthorController.searchAuthor()}" />
</h:form>
豆
public void searchAuthor() {
this.variableNames.clear();
List<String> uris = new ArrayList<String>();
uris = this.authMapper.searchAuthorUriByName(this.nameToSearch);
if( (uris != null) && (!uris.isEmpty()) ) {
for( String uri : uris ) {
Map<String, String> map = new HashMap<String, String>();
String name = this.authMapper.searchNameByAuthorUri(uri);
String email = this.authMapper.searchEmailByAuthorUri(uri);
map.put("URI", uri);
map.put("Nome", name);
map.put("Email", email);
authorListOfMap.add(map);
}
this.addVariableNames();
} else {
FacesContext ctx = FacesContext.getCurrentInstance();
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,"Detail","Author not found!"); //FacesMessage has other info levels
ctx.addMessage(null,msg);
}
}
谢谢!
答案 0 :(得分:0)
notifyMessage
应该表现得那样(即在屏幕的一角弹出),如果你只想要一条简单的短信使用<rich:message>
。
或者在这个简单的例子中,您可以检查结果是否返回了一些内容:
<h:outputText value="No results"
rendered="#{fn:length(insertAuthorController.authorListOfMap) == 0}">
您的表格未显示,因为如果您想查看更改,则需要重新呈现:
<rich:dataTable id="authorsTable" …>
<a4j:commandButton … render="authorsTable" />