Updating button class on hitting button.
parent
78a118ba13
commit
e56e1a3348
|
@ -9,12 +9,15 @@ import pl.tpolgrabia.trainings.javaee.javaeedemo.entities.User;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.ejb.EJB;
|
import javax.ejb.EJB;
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.faces.view.ViewScoped;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Named
|
@Named
|
||||||
@RequestScoped
|
@ViewScoped
|
||||||
public class HelloController {
|
public class HelloController implements Serializable {
|
||||||
|
private static final long serialVersionUID = 2780964279445984180L;
|
||||||
private static final Logger logger = LoggerFactory.getLogger(HelloController.class);
|
private static final Logger logger = LoggerFactory.getLogger(HelloController.class);
|
||||||
|
|
||||||
@EJB
|
@EJB
|
||||||
|
@ -24,6 +27,7 @@ public class HelloController {
|
||||||
private UserDao userDao;
|
private UserDao userDao;
|
||||||
|
|
||||||
private String message;
|
private String message;
|
||||||
|
private boolean markedAsDanger = false;
|
||||||
|
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
|
@ -37,6 +41,10 @@ public class HelloController {
|
||||||
return todosDao.findAll();
|
return todosDao.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMarkedAsDanger() {
|
||||||
|
return markedAsDanger;
|
||||||
|
}
|
||||||
|
|
||||||
public List<User> getAllUsers() {
|
public List<User> getAllUsers() {
|
||||||
return userDao.findAll();
|
return userDao.findAll();
|
||||||
}
|
}
|
||||||
|
@ -46,7 +54,8 @@ public class HelloController {
|
||||||
return "index";
|
return "index";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleSimpleAction() {
|
public void toggleButtonClass() {
|
||||||
|
this.markedAsDanger = !markedAsDanger;
|
||||||
logger.info("Hello action");
|
logger.info("Hello action");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,9 +90,10 @@
|
||||||
</h:dataTable>
|
</h:dataTable>
|
||||||
<form jsf:id="form">
|
<form jsf:id="form">
|
||||||
<button jsf:action="#{helloController.handleSubmit}" class="button is-light">#{helloController.message}</button>
|
<button jsf:action="#{helloController.handleSubmit}" class="button is-light">#{helloController.message}</button>
|
||||||
<button type="button" jsf:action="#{helloController.handleSimpleAction}" class="button is-light">
|
<button type="button" jsf:action="#{helloController.toggleButtonClass}"
|
||||||
|
class="button #{helloController.markedAsDanger ? 'is-danger' : 'is-light'}">
|
||||||
Action me
|
Action me
|
||||||
<f:ajax/>
|
<f:ajax render="@form"/>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in New Issue