如何从自动完成项目 select 打开新页面 - primefaces
how open a new page from autocomplete item select - primefaces
我正在构建一个显示网页列表的自动完成功能,当用户 select 其中一个网页时,它应该会打开该网页。
我该怎么做?
navbar.xhtml
<p:autoComplete id="autoMenu"
value="#{menuController.componenteP}"
completeMethod="#{menuController.getAutoComplete}"
converter="genericConverter"
var="componente"
itemLabel="#{componente.dsComponente}"
itemValue="#{componente}"
queryDelay="50"
forceSelection="false"
placeholder="Menu"
required="false"
>
<p:ajax event="itemSelect" listener="#{menuController.onItemSelect}" update="msgs"/>
<f:attribute name="classe" value="Componente" />
<p:column>
<b><h:outputText value="#{componente.codigo}"/></b>
</p:column>
<p:column>
<p:outputLabel rendered="#{componente != null}" value="#{componente.dsComponente}" />
</p:column>
</p:autoComplete>
我找到了一个方法:
MenuController.java
public void onItemSelect(SelectEvent<Componente> event) {
FacesContext ctx = FacesContext.getCurrentInstance();
ExternalContext extContext = ctx.getExternalContext();
String url = extContext.encodeActionURL(ctx.getApplication().getViewHandler().getActionURL(ctx, event.getObject().getDsUrl()));
try {
extContext.redirect(url);
}
catch (IOException ioe) {
throw new FacesException(ioe);
}
}
我正在构建一个显示网页列表的自动完成功能,当用户 select 其中一个网页时,它应该会打开该网页。 我该怎么做?
navbar.xhtml
<p:autoComplete id="autoMenu"
value="#{menuController.componenteP}"
completeMethod="#{menuController.getAutoComplete}"
converter="genericConverter"
var="componente"
itemLabel="#{componente.dsComponente}"
itemValue="#{componente}"
queryDelay="50"
forceSelection="false"
placeholder="Menu"
required="false"
>
<p:ajax event="itemSelect" listener="#{menuController.onItemSelect}" update="msgs"/>
<f:attribute name="classe" value="Componente" />
<p:column>
<b><h:outputText value="#{componente.codigo}"/></b>
</p:column>
<p:column>
<p:outputLabel rendered="#{componente != null}" value="#{componente.dsComponente}" />
</p:column>
</p:autoComplete>
我找到了一个方法:
MenuController.java
public void onItemSelect(SelectEvent<Componente> event) {
FacesContext ctx = FacesContext.getCurrentInstance();
ExternalContext extContext = ctx.getExternalContext();
String url = extContext.encodeActionURL(ctx.getApplication().getViewHandler().getActionURL(ctx, event.getObject().getDsUrl()));
try {
extContext.redirect(url);
}
catch (IOException ioe) {
throw new FacesException(ioe);
}
}