use of javax.faces.application.FacesMessage in project rubia-forums by flashboss.
the class JSFUtil method handleException.
/**
* @author sshah
*
* @param e
* the exception to handle
*
* @return the navigation state of the application
*/
public static String handleException(Exception e) {
String genericNavState = ERROR;
String msg = e.toString();
FacesMessage message = new // severity
FacesMessage(// severity
FacesMessage.SEVERITY_ERROR, // summary
msg, // detail
msg);
getCurrentInstance().addMessage(ERROR, message);
return genericNavState;
}
use of javax.faces.application.FacesMessage in project tutorials by eugenp.
the class MemberController method register.
public void register() throws Exception {
try {
memberRegistration.register(newMember);
FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_INFO, "Registered!", "Registration successful");
facesContext.addMessage(null, m);
initNewMember();
} catch (Exception e) {
String errorMessage = getRootErrorMessage(e);
FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, "Registration unsuccessful");
facesContext.addMessage(null, m);
}
}
use of javax.faces.application.FacesMessage in project core by weld.
the class CommentBoard method post.
public Boolean post() {
if (comment == null || blog == null) {
return null;
}
BlogEntry entry = repository.getEntry(blog.getEntryId());
if (entry == null) {
return null;
}
comment.checkAuthor();
repository.addComment(comment, entry);
FacesContext ctx = FacesContext.getCurrentInstance();
ctx.addMessage(null, new FacesMessage("Thanks for leaving a comment!"));
// FIXME doesn't seem to be working; must investigate
ctx.getExternalContext().getFlash().setKeepMessages(true);
return true;
}
use of javax.faces.application.FacesMessage in project fit3d by fkaiserbio.
the class LoginView method submit.
public void submit() throws IOException {
System.out.println(username + ":" + password);
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext externalContext = context.getExternalContext();
HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
try {
request.login(username, password);
logger.info("authenticated {}", request.getUserPrincipal());
externalContext.redirect(requestedUri);
} catch (ServletException e) {
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Bad login", null));
logger.warn("failed login attempt {}:{}", username, password);
}
}
use of javax.faces.application.FacesMessage in project fit3d by fkaiserbio.
the class SubmitJobView method analyzeTargetList.
private void analyzeTargetList() throws IOException {
// check if target list contains exclusively PDB-IDs
List<String> pdbIdentifiers = Files.lines(targetListPath).filter(Pattern.compile("^" + PDBIdentifier.PATTERN.pattern() + "$").asPredicate()).distinct().collect(Collectors.toList());
List<String> chainIdentifiers = Files.lines(targetListPath).filter(Pattern.compile("^" + PDBIdentifier.PATTERN.pattern() + "\\s[0-9A-Za-z]+$").asPredicate()).distinct().collect(Collectors.toList());
if (!pdbIdentifiers.isEmpty() && !chainIdentifiers.isEmpty()) {
if (!blocked) {
blocked = true;
RequestContext.getCurrentInstance().update("mainForm:submitButton");
}
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Your target list is a mix of PDB-IDs and chain-IDs.");
FacesContext.getCurrentInstance().addMessage(null, message);
} else {
if (!pdbIdentifiers.isEmpty()) {
targetListSize = pdbIdentifiers.size();
chainTargetList = false;
pdbTargetList = true;
if (blocked) {
blocked = false;
RequestContext.getCurrentInstance().update("mainForm:submitButton");
}
targetListPath = jobPath.resolve("targets.txt");
Files.write(jobPath.resolve("targets.txt"), pdbIdentifiers.stream().collect(Collectors.joining("\n")).getBytes());
logger.info("copied PDB-ID target list to {}", targetListPath);
} else if (!chainIdentifiers.isEmpty()) {
targetListSize = chainIdentifiers.size();
pdbTargetList = false;
chainTargetList = true;
if (blocked) {
blocked = false;
RequestContext.getCurrentInstance().update("mainForm:submitButton");
}
targetListPath = jobPath.resolve("targets.txt");
Files.write(targetListPath, chainIdentifiers.stream().collect(Collectors.joining("\n")).getBytes());
logger.info("copied chain-ID target list to {}", targetListPath);
} else {
if (!blocked) {
blocked = true;
RequestContext.getCurrentInstance().update("mainForm:submitButton");
}
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Your target list does not contain valid PDB-IDs.");
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
}
Aggregations