jsf - Two h:commandButton in the same h:form: one works, the other doesn't -
i have .xhtml
piece of code:
<h:inputtext value="#{boardmbean.logintoadd}"/> <h:commandbutton action="#{boardmbean.adduser}" immediate="true" process="@this" value="adicionar"/> (...) <h:commandbutton action="#{boardmbean.edit}" value="salvar" class="btn btn-large"/>
the second h:commandbutton
works fine, i.e., submits form correctly. in other hand, first, instead of calling adduser()
method boardmbean
, refresh page , nothing happens.
i'm using jsf 2.2 , application running on jetty. managed bean is:
import java.io.serializable; import javax.faces.bean.managedbean; import javax.faces.bean.requestscoped; import javax.faces.bean.viewscoped; @managedbean(name="boardmbean") @requestscoped public class boardmbean extends generalcontroller<board> implements serializable { /** login of new user of board. */ private string logintoadd; /** selected role add user. */ private roleboard role; /** * constructor. * */ public boardmbean() { obj = new board(); } /** * prepare board update. * * @return sends same edit page. * */ public string loadboard() {(doesn't matter).} /** * called edit/create board use case. * * @return sends list of tables. * */ public string edit() {(works fine.)} /** * add user board. * * @return same page. * */ public string adduser() { if (logintoadd != null && !logintoadd.equals("")) { userdao udao = new userdao(); // retrieve user login user u = udao.getuserbylogin(logintoadd); // if exists // todo check if exists in board if (u != null) { // build relation boarduser boarduser = new boarduser(u, obj); // role boarduser.setrole(role); userboarddao ubdao = new userboarddao(); ubdao.create(boarduser); obj.getusers().add(boarduser); boarddao bdao = new boarddao(); // commit change bdao.update(obj); } else { //todo user not found } } return null; } public roleboard getrole() { return role; } public void setrole(roleboard role) { this.role = role; } public string getlogintoadd() { return logintoadd; } public void setlogintoadd(string logintoadd) { this.logintoadd = logintoadd; } }
since i'm using jetty, there exist well-known problem @managedbean
annotation, makes me use faces-config.xml
(just now) indicate managed beans. how looks like:
<?xml version="1.0" encoding="utf-8"?> <faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd" version="2.2"> <managed-bean> <managed-bean-name>usermbean</managed-bean-name> <managed-bean-class>com.vinivitor.trackit.control.usermbean</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> <managed-bean> <managed-bean-name>boardmbean</managed-bean-name> <managed-bean-class>com.vinivitor.trackit.control.boardmbean</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> </faces-config>
does know how make first h:commandbutton
work expected?
thanks in advance.