use of jakarta.faces.context.FacesContext in project guide-jpa-intro by OpenLiberty.
the class EventBean method addErrorMessage.
/**
* Adds "Choose a valid time" message after selectOptions in user interface.
*/
private void addErrorMessage(ComponentSystemEvent event, String errorMessage) {
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage(errorMessage);
HtmlPanelGroup divEventTime = (HtmlPanelGroup) event.getComponent().findComponent("eventform:eventTime");
context.addMessage(divEventTime.getClientId(context), message);
}
use of jakarta.faces.context.FacesContext in project rubia-forums by flashboss.
the class JSFUtil method getBundleMessage.
/**
* @param bundleName the name of the bundle
* @param messageKey the key of the bundle to find
*
* @return the value for the requested id
*/
public static String getBundleMessage(String bundleName, String messageKey) {
String bundleMessage = null;
// Getting ResourceBundle with current Locale
FacesContext ctx = getCurrentInstance();
UIViewRoot uiRoot = ctx.getViewRoot();
Locale locale = uiRoot.getLocale();
ClassLoader ldr = currentThread().getContextClassLoader();
ResourceBundle bundle = getBundle(bundleName, locale, ldr);
bundleMessage = bundle.getString(messageKey);
return bundleMessage;
}
use of jakarta.faces.context.FacesContext in project rubia-forums by flashboss.
the class PollValidator method validate.
public void validate(FacesContext context, UIComponent component, String value) throws ValidatorException {
// A check whether it is post submition action. If not validators are
// not executed.
FacesContext fc = FacesContext.getCurrentInstance();
Map<String, String> reqParams = fc.getExternalContext().getRequestParameterMap();
if (!reqParams.keySet().contains("post:Submit")) {
return;
}
// Collecting all poll data from the form.
UIComponent formComp = component.getParent();
UIComponent questionComp = formComp.findComponent("question");
UIComponent pollDurationComp = formComp.findComponent("pollDuration");
List<UIComponent> options = new ArrayList<UIComponent>();
for (int i = 1; ; i++) {
UIComponent temp = formComp.findComponent("option_" + i);
if (temp != null) {
options.add(temp);
} else {
break;
}
}
// validate.
if (!((questionComp.getAttributes().get("value") != null && questionComp.getAttributes().get("value").toString().trim().length() != 0) || (options.size() > 0))) {
return;
}
// Checks
if (options.size() > 10) {
throwValidationException(TOO_MANY_OPTIONS_MSG);
}
if (options.size() < 2) {
throwValidationException(TOO_FEW_OPTIONS_MSG);
}
if (questionComp.getAttributes().get("value") == null || questionComp.getAttributes().get("value").toString().trim().length() == 0) {
throwValidationException(EMPTY_POLL_QUESTION_MSG);
}
for (UIComponent option : options) {
if (option.getAttributes().get("value") == null || option.getAttributes().get("value").toString().trim().length() == 0) {
throwValidationException(EMPTY_POLL_OPTION_MSG);
}
}
int duration = 0;
if (pollDurationComp.getAttributes().get("value") != null && pollDurationComp.getAttributes().get("value").toString().trim().length() != 0) {
try {
duration = parseInt(pollDurationComp.getAttributes().get("value").toString());
} catch (NumberFormatException e) {
throwValidationException(POLL_DURATION_MSG);
}
if (duration < 0) {
throwValidationException(POLL_DURATION_MSG);
}
}
}
use of jakarta.faces.context.FacesContext in project core by weld.
the class WeldTestPhaseListener method testELResolver.
private void testELResolver(String name) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ELResolver resolver = facesContext.getApplication().getELResolver();
ELContext elContext = facesContext.getELContext();
Object object = resolver.getValue(elContext, null, name);
if (object == null)
throw new NullPointerException("ELResolver returned null");
}
use of jakarta.faces.context.FacesContext in project core by weld.
the class ConversationPropagationFilter method wrapResponse.
private ServletResponse wrapResponse(HttpServletResponse response, final String requestPath) {
return new HttpServletResponseWrapper(response) {
@Override
public void sendRedirect(String path) throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
if (context != null) {
// this is a JSF request
ConversationContext conversationContext = instance(contextId).select(HttpConversationContext.class).get();
if (conversationContext.isActive()) {
Conversation conversation = conversationContext.getCurrentConversation();
if (!conversation.isTransient()) {
path = new FacesUrlTransformer(path, context).toRedirectViewId().toActionUrl().appendConversationIdIfNecessary(conversationContext.getParameterName(), conversation.getId()).encode();
}
}
}
super.sendRedirect(path);
}
};
}
Aggregations