Algunos métodos podemos definir un parametro opcional por ejemplo Object... item
public String prepare(String action, Object... item) {
String url = "";
try {
loginController.put("pagerol", page.toString());
loginController.put("rol", action);
switch (action) {
case "new":
rol = new Rol();
rolSelected = new Rol();
writable = false;
break;
case "view":
if (item.length != 0) {
rolSelected = (Rol) item[0];
rol = rolSelected;
loginController.put("idrol", rol.getIdrol());
}
url = "/pages/rol/view.xhtml";
break;
case "golist":
url = "/pages/rol/list.xhtml";
break;
case "gonew":
rol = new Rol();
rolSelected = new Rol();
url = "/pages/rol/new.xhtml";
break;
}
} catch (Exception e) {
JsfUtil.errorMessage("prepare() " + e.getLocalizedMessage());
}
return url;
}// </editor-fold>
Desde una pagina Java Server Faces podemos invocarlo
<a:paginator
clear="#{rolController.clear()}"
first="#{rolController.first()}"
back="#{rolController.back()}"
next="#{rolController.next()}"
last="#{rolController.last()}"
page="#{rolController.page}"
pages="#{rolController.pages}"
skip="ajax:rolController.skip(rolController.page)"
new="#{rolController.prepare('gonew',rolController.rol)}"
printAll="#{rolController.printAll()}"
/>
Resultados
Glassfish 5.0, funciona sin problemas
Payara 5.0, Glassfish 4.0
public String prepare(String action, Object... item) {
String url = "";
try {
loginController.put("pagerol", page.toString());
loginController.put("rol", action);
switch (action) {
case "new":
rol = new Rol();
rolSelected = new Rol();
writable = false;
break;
case "view":
if (item.length != 0) {
rolSelected = (Rol) item[0];
rol = rolSelected;
loginController.put("idrol", rol.getIdrol());
}
url = "/pages/rol/view.xhtml";
break;
case "golist":
url = "/pages/rol/list.xhtml";
break;
case "gonew":
rol = new Rol();
rolSelected = new Rol();
url = "/pages/rol/new.xhtml";
break;
}
} catch (Exception e) {
JsfUtil.errorMessage("prepare() " + e.getLocalizedMessage());
}
return url;
}// </editor-fold>
Desde una pagina Java Server Faces podemos invocarlo
<a:paginator
clear="#{rolController.clear()}"
first="#{rolController.first()}"
back="#{rolController.back()}"
next="#{rolController.next()}"
last="#{rolController.last()}"
page="#{rolController.page}"
pages="#{rolController.pages}"
skip="ajax:rolController.skip(rolController.page)"
new="#{rolController.prepare('gonew',rolController.rol)}"
printAll="#{rolController.printAll()}"
/>
Resultados
Glassfish 5.0, funciona sin problemas
Payara 5.0, Glassfish 4.0
Para que funcione en Payara 5.0, o Glassfish 4.0, hay que indicar el parámetro correspondiente sin usar el optional.
public String prepare(String action, Rol item) {
String url = "";
try {
loginController.put("pagerol", page.toString());
loginController.put("rol", action);
switch (action) {
case "new":
rol = new Rol();
rolSelected = new Rol();
writable = false;
break;
case "view":
rolSelected = item;
rol = rolSelected;
loginController.put("idrol", rol.getIdrol());
url = "/pages/rol/view.xhtml";
break;
case "golist":
url = "/pages/rol/list.xhtml";
break;
case "gonew":
rol = new Rol();
rolSelected = new Rol();
url = "/pages/rol/new.xhtml";
break;
}
} catch (Exception e) {
JsfUtil.errorMessage("prepare() " + e.getLocalizedMessage());
}
return url;
}// </editor-fold>
Comments