Jsf 2 使用视图处理程序的内部化显示空白页
我正在尝试内部化示例,我编写了如上所示的视图处理程序。我有两种语言:英语和法语。但是在编写这个处理程序之后。控制台上没有错误,但显示空白白页。如何查看视图 您应该扩展而不是编写自己的Jsf 2 使用视图处理程序的内部化显示空白页,jsf-2,primefaces,Jsf 2,Primefaces,我正在尝试内部化示例,我编写了如上所示的视图处理程序。我有两种语言:英语和法语。但是在编写这个处理程序之后。控制台上没有错误,但显示空白白页。如何查看视图 您应该扩展而不是编写自己的ViewHandler public class LocaleViewHandler extends ViewHandler{ private final ViewHandler base; public LocaleViewHandler(ViewHandler base){ s
ViewHandler
public class LocaleViewHandler extends ViewHandler{
private final ViewHandler base;
public LocaleViewHandler(ViewHandler base){
super();
this.base = base;
}
@Override
public Locale calculateLocale(FacesContext context) {
Locale locale;
HttpSession session = (HttpSession) context.getExternalContext()
.getSession(false);
if (session != null) {
//Return the locale saved by the managed bean earlier
locale = (Locale) session.getAttribute("locale");
if (locale == null) {
locale= new Locale("en");
}
return locale;
}
return base.calculateLocale(context);
}
@Override
public String calculateRenderKitId(FacesContext arg0) {
// TODO Auto-generated method stub
return base.calculateRenderKitId(arg0);
}
@Override
public UIViewRoot createView(FacesContext arg0, String arg1) {
// TODO Auto-generated method stub
return base.createView(arg0, arg1);
}
@Override
public String getActionURL(FacesContext arg0, String arg1) {
// TODO Auto-generated method stub
return base.getActionURL(arg0, arg1);
}
@Override
public String getResourceURL(FacesContext arg0, String arg1) {
// TODO Auto-generated method stub
return base.getResourceURL(arg0, arg1);
}
@Override
public void renderView(FacesContext arg0, UIViewRoot arg1)
throws IOException, FacesException {
// TODO Auto-generated method stub
base.renderView(arg0, arg1);
}
@Override
public UIViewRoot restoreView(FacesContext arg0, String arg1) {
// TODO Auto-generated method stub
return base.restoreView(arg0, arg1);
}
@Override
public void writeState(FacesContext arg0) throws IOException {
// TODO Auto-generated method stub
base.writeState(arg0);
}
public ViewHandler getBase() {
return base;
}
}
与具体问题无关,这不是完全正确的方法。你应该用
public class LocaleViewHandler extends ViewHandlerWrapper {
private ViewHandler wrapped;
public LocaleViewHandler(ViewHandler wrapped) {
this.wrapped = wrapped;
}
@Override
public ViewHandler getWrapped() {
return wrapped;
}
@Override
public Locale calculateLocale(FacesContext context) {
// Do your thing here.
}
}
相反。另请参见。您应该扩展而不是编写自己的ViewHandler
public class LocaleViewHandler extends ViewHandler{
private final ViewHandler base;
public LocaleViewHandler(ViewHandler base){
super();
this.base = base;
}
@Override
public Locale calculateLocale(FacesContext context) {
Locale locale;
HttpSession session = (HttpSession) context.getExternalContext()
.getSession(false);
if (session != null) {
//Return the locale saved by the managed bean earlier
locale = (Locale) session.getAttribute("locale");
if (locale == null) {
locale= new Locale("en");
}
return locale;
}
return base.calculateLocale(context);
}
@Override
public String calculateRenderKitId(FacesContext arg0) {
// TODO Auto-generated method stub
return base.calculateRenderKitId(arg0);
}
@Override
public UIViewRoot createView(FacesContext arg0, String arg1) {
// TODO Auto-generated method stub
return base.createView(arg0, arg1);
}
@Override
public String getActionURL(FacesContext arg0, String arg1) {
// TODO Auto-generated method stub
return base.getActionURL(arg0, arg1);
}
@Override
public String getResourceURL(FacesContext arg0, String arg1) {
// TODO Auto-generated method stub
return base.getResourceURL(arg0, arg1);
}
@Override
public void renderView(FacesContext arg0, UIViewRoot arg1)
throws IOException, FacesException {
// TODO Auto-generated method stub
base.renderView(arg0, arg1);
}
@Override
public UIViewRoot restoreView(FacesContext arg0, String arg1) {
// TODO Auto-generated method stub
return base.restoreView(arg0, arg1);
}
@Override
public void writeState(FacesContext arg0) throws IOException {
// TODO Auto-generated method stub
base.writeState(arg0);
}
public ViewHandler getBase() {
return base;
}
}
与具体问题无关,这不是完全正确的方法。你应该用
public class LocaleViewHandler extends ViewHandlerWrapper {
private ViewHandler wrapped;
public LocaleViewHandler(ViewHandler wrapped) {
this.wrapped = wrapped;
}
@Override
public ViewHandler getWrapped() {
return wrapped;
}
@Override
public Locale calculateLocale(FacesContext context) {
// Do your thing here.
}
}
相反。另见