faces
faces copied to clipboard
Allow redirect via Annotation on action
Currently the return value of the action triggers a navigation
public String action() {
return "myNewView.xhtml"
}
to force a redirect, we have to add a string param:
public String action() {
return "myNewView.xhtml?faces-redirect=true"
}
Wouldnt it be nice if we allow:
@Redirect
public String action() {
return "myNewView.xhtml"
}
and
@Redirect("myNewView.xhtml")
public void action() {
}
Will this also be applicable to void methods e.g.
@Redirect public void action() { doSomeOtherAction(); }
I rather see it only apply to void methods and then taking an argument
We could even allow both, see my updated example.
I think this is great if it also allows external URLs.
Old
public void action() throws IOException {
// ...
FacesContext.getCurrentInstance().getExternalContext().redirect("https://google.com");
}
New (just match ^https?://
)
@Redirect("https://google.com")
public void action() { // Look ma, no throws!
// ...
}
And EL expressions.
Old
public String action() {
// ...
boolean flag = compute();
return flag ? "foo" : "bar";
}
New
private boolean flag;
@Redirect("#{bean.flag ? 'foo' : 'bar'}")
public void action() {
// ...
flag = compute();
}
public boolean isFlag() {
return flag;
}
will prototype this in MF as next task
What should we do with forward?
Either make a @Forward
or @Navigate
with redirect or forward param
I'd rather not implement/advocate a "forward" for now. It only encourages poor practices.
Created a el-spec feature request, which would make this feature really easy to implement: https://github.com/eclipse-ee4j/el-ri/issues/154
I currently think about something like that:
@Target(value = ElementType.FIELD)
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Redirect
{
/**
* The relative or absolute path, which will be passed to the NavigationHandler.
* EL-Expressions are also supported.
*
* This parameter is required when the return-type of the method is void.
*
* @return
*/
String value() default "";
boolean includeViewParams() default false;
}
which could be easily accessed in ActionListenerImpl
EL feature is implemented now, i will do a prototype in MF next week
@BalusC @arjantijms i have propably some time to work on it. Would you like to see it? im sure its only a small change, similar to my CDI bridges
@tandraschko sounds good! Sure would like to see it.