Sending message from input through the MDB.

master
Tomasz Półgrabia 2021-01-05 22:25:41 +01:00
parent e56e1a3348
commit 1ba99edce0
2 changed files with 24 additions and 6 deletions

View File

@ -2,14 +2,14 @@ package pl.tpolgrabia.trainings.javaee.controllers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.tpolgrabia.trainings.javaee.javaeedemo.ejb.SimpleMessageSendingBean;
import pl.tpolgrabia.trainings.javaee.javaeedemo.ejb.TodosDao;
import pl.tpolgrabia.trainings.javaee.javaeedemo.ejb.UserDao;
import pl.tpolgrabia.trainings.javaee.javaeedemo.entities.User;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.util.List;
@ -20,12 +20,15 @@ public class HelloController implements Serializable {
private static final long serialVersionUID = 2780964279445984180L;
private static final Logger logger = LoggerFactory.getLogger(HelloController.class);
@EJB
@Inject
private TodosDao todosDao;
@EJB
@Inject
private UserDao userDao;
@Inject
private SimpleMessageSendingBean simpleMessageSendingBean;
private String message;
private boolean markedAsDanger = false;
@ -50,7 +53,8 @@ public class HelloController implements Serializable {
}
public String handleSubmit() {
logger.info("Hello submit");
logger.info("Submitting message {}", message);
simpleMessageSendingBean.sendHello(message);
return "index";
}
@ -62,5 +66,6 @@ public class HelloController implements Serializable {
@PostConstruct
public void init() {
this.message = "Submit me";
logger.info("Initialized with message {}", message);
}
}

View File

@ -89,7 +89,20 @@
</h:column>
</h:dataTable>
<form jsf:id="form">
<button jsf:action="#{helloController.handleSubmit}" class="button is-light">#{helloController.message}</button>
<div class="field is-horizontal">
<div class="field-label is-normal">
<label for="message" class="label">Message</label>
</div>
<div class="field-body">
<div class="field">
<p class="control">
<h:inputText id="message" name="message" type="text" class="input"
value="#{helloController.message}"/>
</p>
</div>
</div>
</div>
<h:commandButton action="#{helloController.handleSubmit}" class="button is-light" value="Submit me"/>
<button type="button" jsf:action="#{helloController.toggleButtonClass}"
class="button #{helloController.markedAsDanger ? 'is-danger' : 'is-light'}">
Action me