本文整理匯總了Java中javax.faces.context.FacesContext.getMessages方法的典型用法代碼示例。如果您正苦於以下問題:Java FacesContext.getMessages方法的具體用法?Java FacesContext.getMessages怎麽用?Java FacesContext.getMessages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.faces.context.FacesContext
的用法示例。
在下文中一共展示了FacesContext.getMessages方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: saveMessages
import javax.faces.context.FacesContext; //導入方法依賴的package包/類
/**
* Remove the messages that are not associated with any particular component
* from the faces context and store them to the user's session.
*
* @return the number of removed messages.
*/
private int saveMessages(FacesContext facesContext) {
// remove messages from the context
List<FacesMessage> messages = new ArrayList<FacesMessage>();
for(Iterator<FacesMessage> i = facesContext.getMessages(null); i.hasNext(); ) {
messages.add(i.next());
i.remove();
}
// store them in the session
if(messages.size() == 0) {
return 0;
}
Map<String, Object> sessionMap = facesContext.getExternalContext().getSessionMap();
// if there already are messages
@SuppressWarnings("unchecked")
List<FacesMessage> existingMessages = (List<FacesMessage>) sessionMap.get(sessionToken);
if(existingMessages != null) {
existingMessages.addAll(messages);
}
else {
sessionMap.put(sessionToken, messages); // if these are the first messages
}
return messages.size();
}
示例2: restoreMessages
import javax.faces.context.FacesContext; //導入方法依賴的package包/類
/**
* Substitute the faces messages that are not associated with a particular
* component by the saved messages from the MESSAGEHOLDERBEAN.
*
* @return the number of removed messages.
*/
private void restoreMessages(FacesContext facesContext) {
MessageHolderBean bean = ui.findMessageHolderBean();
Set<MessageWithClientId> messages = bean.getMessages();
// remove global messages in facesContext
Set<FacesMessage> facesContextMessages = new HashSet<FacesMessage>();
for (Iterator<FacesMessage> i = facesContext.getMessages(null); i
.hasNext();) {
FacesMessage msg = i.next();
facesContextMessages.add(msg);
i.remove();
}
// add saved messages if not yet existing
if (messages != null && messages.size() > 0) {
for (MessageWithClientId message : messages) {
if (!facesContextMessages.contains(message.getMessage()))
facesContext.addMessage(message.getClientId(),
message.getMessage());
}
bean.resetMessages();
}
}
示例3: replaceMessageInListIfExisting
import javax.faces.context.FacesContext; //導入方法依賴的package包/類
public static boolean replaceMessageInListIfExisting(String oldKey,
Object[] oldParams, String newKey, Object[] newParams) {
FacesContext fc = FacesContext.getCurrentInstance();
String oldText = JSFUtils.getText(oldKey, oldParams);
String newText = JSFUtils.getText(newKey, newParams);
for (Iterator<FacesMessage> i = fc.getMessages(); i.hasNext();) {
FacesMessage fm = i.next();
if (fm.getDetail().equals(oldText)) {
fm.setDetail(newText);
fm.setSummary(newText);
return true;
}
}
return false;
}
示例4: _renderGlobalMessages
import javax.faces.context.FacesContext; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
protected void _renderGlobalMessages(
FacesContext context,
RenderingContext rc,
UIComponent component,
FacesBean bean
) throws IOException
{
ResponseWriter writer = context.getResponseWriter();
// Get all messages without and id
Iterator<FacesMessage> msgIter = context.getMessages(null);
while (msgIter.hasNext())
{
FacesMessage msg = msgIter.next();
writer.startElement("li", null);
String text = MessageUtils.getGlobalMessage(rc, msg.getSummary(), msg.getDetail());
renderPossiblyFormattedText(context, text);
writer.endElement("li");
}
}
示例5: getFacesMessage
import javax.faces.context.FacesContext; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static FacesMessage getFacesMessage(
FacesContext context,
String clientId)
{
if (clientId != null)
{
Iterator<FacesMessage> messages = context.getMessages(clientId);
if (messages.hasNext())
{
return messages.next();
}
}
return null;
}
示例6: getMessagesForClientId
import javax.faces.context.FacesContext; //導入方法依賴的package包/類
/**
* Gets the messages with the given client identifier from the faces context
* .
*
* @param clientId
* The client identifier to filter for.
* @param facesContext
* The faces context.
* @return The messsage with the given id.
*/
private List<MessageWithClientId> getMessagesForClientId(String clientId,
FacesContext facesContext) {
List<MessageWithClientId> md = new ArrayList<MessageWithClientId>();
for (Iterator<FacesMessage> it = facesContext.getMessages(clientId); it
.hasNext();) {
FacesMessage msg = it.next();
md.add(new MessageWithClientId(clientId, msg));
it.remove();
}
return md;
}
示例7: hasErrors
import javax.faces.context.FacesContext; //導入方法依賴的package包/類
public static boolean hasErrors(FacesContext fc) {
for (Iterator<FacesMessage> i = fc.getMessages(); i.hasNext();) {
FacesMessage m = i.next();
if (FacesMessage.SEVERITY_ERROR == m.getSeverity()) {
return true;
}
}
return false;
}
示例8: hasWarnings
import javax.faces.context.FacesContext; //導入方法依賴的package包/類
public static boolean hasWarnings(FacesContext fc) {
for (Iterator<FacesMessage> i = fc.getMessages(); i.hasNext();) {
FacesMessage m = i.next();
if (FacesMessage.SEVERITY_WARN == m.getSeverity()) {
return true;
}
}
return false;
}
示例9: containsMessageInList
import javax.faces.context.FacesContext; //導入方法依賴的package包/類
private boolean containsMessageInList(FacesContext fc, String msg) {
for (Iterator<FacesMessage> i = fc.getMessages(); i.hasNext();) {
if (i.next().getDetail().contains(msg)) {
return true;
}
}
return false;
}
示例10: multipleMessagesQueued
import javax.faces.context.FacesContext; //導入方法依賴的package包/類
/**
* Returns true if there is more than one FacesMessage queued.
* @param context
* @param globalOnly Count only global messages
* @return true if multiple messages queued.
*/
@SuppressWarnings("unchecked")
public static boolean multipleMessagesQueued(
FacesContext context,
boolean globalOnly)
{
Iterator<FacesMessage> msgIter = null;
if (globalOnly)
// All messages without id's
msgIter = context.getMessages(null);
else
// All messages, inc those without id's
msgIter = context.getMessages();
if (msgIter.hasNext())
{
// At least one message
msgIter.next();
if (msgIter.hasNext())
{
// At least two messages
return true;
}
}
return false;
}
示例11: _renderComponentMessages
import javax.faces.context.FacesContext; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
protected void _renderComponentMessages(
FacesContext context,
RenderingContext rc,
UIComponent component,
FacesBean bean
) throws IOException
{
ResponseWriter writer = context.getResponseWriter();
Iterator<String> idIter = context.getClientIdsWithMessages();
while (idIter.hasNext())
{
String id = idIter.next();
// Skip global messages
if (id == null)
continue;
Iterator<FacesMessage> msgIter = context.getMessages(id);
while (msgIter.hasNext())
{
FacesMessage msg = msgIter.next();
writer.startElement("li", null);
_renderMessageAnchor(context, rc, msg, id);
String text = MessageUtils.getClientMessage(rc, msg.getSummary(), msg.getDetail());
// If the first two characters are "- ", assume it's due to af_messages.LIST_FORMAT_private;
// alternatively, we could change the value of this key in CoreBundle.xrts, located in:
// trinidad-impl\src\main\xrts\org\apache\myfaces\trinidadinternal\renderkit\core\resource
// If the label is null, then we don't want to render the "- ".
boolean isNullLabel = false;
if (msg instanceof LabeledFacesMessage)
{
LabeledFacesMessage labeledMsg = (LabeledFacesMessage)msg;
String labelString = labeledMsg.getLabelAsString(context);
if (labelString == null || labelString.length() == 0)
isNullLabel = true;
}
else
{
isNullLabel = true;
}
if (isNullLabel && text.charAt(0) == '-' && text.charAt(1) == ' ')
text = text.substring(2);
renderPossiblyFormattedText(context, text);
writer.endElement("li");
}
}
}
示例12: existMessageInList
import javax.faces.context.FacesContext; //導入方法依賴的package包/類
/**
* Checks if a message is already added to FacesContext messages list.
*
* @param fc
* FacesContext instance
*
* @param msg
* the message
* @return Returns true if the msg exists, otherwise false.
*/
public static boolean existMessageInList(FacesContext fc, String msg) {
for (Iterator<FacesMessage> i = fc.getMessages(); i.hasNext();) {
if (i.next().getDetail().equals(msg)) {
return true;
}
}
return false;
}