有几种方法可以保留原始GET URL中的ID。我并不是想全面。
将参数添加到commandlink
<h:commandlink action="#{beanWithId.save}" value="Save"> <f:param name="ID" value="#{param.ID}" /></h:commandlink>每次单击链接,都将通过参数设置ID。
使用隐藏字段
<h:form> <h:inputHidden value="#{beanWithId.id}" /> <p>ID: <h:outputText value="#{beanWithId.id}" /></p> <p>Info: <h:inputText value="#{beanWithId.info}" /></p> <p><h:commandButton action="#{beanWithId.save}" value="Save" /></p></h:form>每当发布表单时,都会从表单中设置ID。
保留网址
由于表单URL不包含原始查询,因此帖子将从浏览器栏中的URL中删除ID。在执行操作之后,可以通过使用服务器端重定向来纠正此问题。
public String save() { System.out.println("Saving changes to persistence store: id=" + id); redirect(); return null; // no navigation } private void redirect() { FacesContext context = FacesContext.getCurrentInstance(); ExternalContext ext = context.getExternalContext(); UIViewRoot view = context.getViewRoot(); String actionUrl = context.getApplication().getViewHandler().getActionURL( context, view.getViewId()); try { // TODO enpre id value actionUrl = ext.enpreActionURL(actionUrl + "?ID=" + id); ext.redirect(actionUrl); } catch (IOException e) { throw new FacesException(e); } }


