目前,我正在尝试以下JSF-Lib:
https://www.ocpsoft.org/rewrite/examples/
我有以下问题:
我有一个页面: /page.jsf
在我的页面中,只有多个参数。 例如。我有: -参数1 -parameter2
String parameter1 = FacesContext.getCurrentInstance().getExternalContext()
.getRequestParameterMap().get("parameter1");
String parameter2 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
.get("parameter2");
目前,我了解可以将其添加到我的UrlConfigProvider类中:
.addRule(Join.path(“ / page / {parameter1}”)。to(“ / portal / mypage.jsf”) .withInboundCorrection())
这适用于一个参数。
但是如何对多个参数执行此操作,因此URL为: / page / {parameter1} / {parameter2} ....
有什么想法吗?
答案 0 :(得分:0)
重写API并未针对此问题带来本地解决方案。
.addRule()
.when(/* your condition */)
.perform(new HttpOperation() {
@Override
public void performHttp(HttpServletRewrite httpServletRewrite, EvaluationContext evaluationContext) {
// this is the default wrapper
HttpRewriteWrappedRequest request = ((HttpRewriteWrappedRequest) httpServletRewrite.getRequest());
// get the uri (example: '/index/p1/p2')
String uri = httpServletRewrite.getRequest().getRequestURI();
// split by slash
String[] split = uri.split("/");
// this is example specific
// split value 0 is empty and split value 1 is the page (e.g. 'index')
// for every folder increment the index
// for '/pages/index' the start index should 3
for (int i = 2; i < split.length; i++) {
String s = split[i];
// the request parameter is by default an immutable map
// but this returns a modifiable
request.getModifiableParameters().put("prefix" + (i - 1), new String[]{s});
}
}
});
唯一重要的部分是HttpOperation
。默认情况下,ServletRequest
包装在HttpRewriteWrappedRequest
中。
初始化后,默认的HttpServletRequest
不允许更改参数。方法getParameterMap()
返回一个不变的映射。
getParameterMap()
中的 HttpRewriteWrappedRequest
也返回一个不变的映射。但是getModifiableMap()
显然会返回可修改的地图。
其余的应该不言自明。