我已经从Eclipse切换到IntelliJ,还有一些我找不到的东西,也没有google:
如何获取自动完成以替换函数的名称?在Eclipse中,它将是ctrl+ enter功能.
例如,
userController.setAmount();
Run Code Online (Sandbox Code Playgroud)
假设我不想打电话给setAmount()a setDefaultPassword(),我把我的插入符号放在set那个ctrl+ space后自动完成,setDefaultPassword()显示但是如果我按回车键,它将不会替换Amount(),我最终会
userController.setDefaultPassword();Amount();
Run Code Online (Sandbox Code Playgroud)
显然我想要的是替换setAmount()by setDefaultPassword().
我想要一种处理异常的通用方法,特别是从后端收到的 401。当我不提取 catchError 内容时,它工作正常。但是,如果我只是将其提取到特定函数,则该函数中不会注入任何内容:
return this.http.request<T>(new HttpRequest('POST', this.appConfig.baseApiPath + url, file, {
reportProgress: true,
headers: headers,
params: urlParams
})).pipe(
catchError((err) => {
if (err.status === 401) {
this.router.navigateByUrl('/login?expired=true');
}
return Observable.throw(err || 'Server error')
})
);
Run Code Online (Sandbox Code Playgroud)
这有效!但是我想在一个函数中处理这个重定向代码,以便通过其他方法重用它。
在这里,我将其导出到一个函数中:
return this.http.request<T>(new HttpRequest('POST', this.appConfig.baseApiPath + url, file, {
reportProgress: true,
headers: headers,
params: urlParams
})).pipe(
catchError(this.handleHttpError),
);
handleHttpError(error: HttpErrorResponse) {
if (error.status === 401) {
this.router.navigateByUrl('/login?expired=true'); --> router is null!
}
return Observable.throw(error || 'Server error')
}
Run Code Online (Sandbox Code Playgroud)
如果我使用这种工作方式,那就是路由器(以及其他构造函数注入的服务)为空的地方……你能建议为什么吗?
我对JSF很新,并没有真正"习惯"不同的思维,所以我在努力(我假设)是基本的.
假设我有一个类User,它是一个会话bean.
假设我有10000个对象的控制器,比如Factory,它需要能够将它们中的一些设置为"锁定",在我们的例子中,它意味着"锁定"字段不再变为空,而是引用"LockedItem"宾语.
这是我无法工作的地方:LockedItem,当你实现它时,应该引用当前登录的用户.我该怎么做?
我尝试使用@managedproperty进行注入,但是在LockedItem.constructor中它是null(这是正常的我假设)然后我尝试了@PostConstruct方法,但是这个方法永远不会被调用(为什么?即使我把它变成了一个托管bean ...是只有在".xhtml"创建对象时调用的postconstruct方法?)或者我应该使用"java se"技巧,比如使用户静态?
代码澄清为什么没有调用@PostConstruct("Seat"之一):
.xhtml
<h:outputLabel id="user" value="Hello #{user.name}" />
<h:outputLabel id="car" value="you have #{car.brand}" />
Run Code Online (Sandbox Code Playgroud)
用户
package test;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class User implements Serializable {
private String name ;
public User()
{
name = "toto";
System.out.println("User constructor");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
汽车
package test;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
@ManagedBean
public class Car implements Serializable …Run Code Online (Sandbox Code Playgroud) jsf design-patterns code-injection postconstruct managed-bean