Oh, I think I see now. You could write a phase listener to run before
RENDER_RESPONSE that looks for messages associated with your sub-components,
removes them from the messages queue, and adds them associated with the
parent instead, like this... :-)

package com.learnjsf.util.faces;

import java.util.Iterator;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ComponentMessageAggregatorListener implements PhaseListener {

   private static final Log log = LogFactory
           .getLog(ComponentMessageAggregatorListener.class);

   public ComponentMessageAggregatorListener() {
   }

   public PhaseId getPhaseId() {
       return PhaseId.RENDER_RESPONSE;
   }

   public void afterPhase(PhaseEvent event) {
   }

   public void beforePhase(PhaseEvent event) {

       FacesContext facesContext = event.getFacesContext();
       for (Iterator i = facesContext.getClientIdsWithMessages();
i.hasNext();)
{
           String clientId = (String) i.next();
           String parentId = null;
           /*
            * your parsing logic here to set parent ID if clientId is one
you
            * recognize as a subcomponent
            * if (clientId matches some pattern)
            *   set parentId = the parent part
            */
           // Remove the child component's message(s) and attach to the
parent instead
           if (parentId != null)
               for (Iterator msgs = facesContext.getMessages(clientId);
msgs
                       .hasNext();) {
                   FacesMessage fm = (FacesMessage) msgs.next();
                   facesContext.addMessage(parentId, fm);
                   msgs.remove();
               }
       }
   }

}

On 11/15/06, delbd <[EMAIL PROTECTED]> wrote:

I was hoping there could be some suggestion on how to transfert messages
from component id X:a to component id X. I'd like to give user
opportunity to put those error message where ever they want. But maybe i
should better do 'component X internal validation that check values of
it's subcomponents', it seems more logical now.

Thanks for your answers, at least i know i am not missing some obvious
possibility :)

Martin Marinschek a écrit :
> If he can integrate the message-component in the input-component, then
> that's an option, right!
>
> regards,
>
> Martin
>
> On 11/14/06, David Chandler <[EMAIL PROTECTED]> wrote:
>> I may not be understanding your question correctly, but if you're
>> adding the
>> input sub-components programatically, you could add the associated
>> message
>> sub-components programatically at the same time. Call setId() on each
>> input
>> component to give it its own ID that you can then use in for= on the
>> corresponding message component.
>>
>> /dmc
>>
>> --
>> David Chandler
>> Development Coach
>> learnjsf.com
>>
>> On 11/14/06, David Delbecq <[EMAIL PROTECTED]> wrote:
>> > Hi,
>> >
>> > I have a custom component ( let's say assume has id X ) that is
>> made of
>> > several Input component ( let's say X:a, X:b, X:c)
>> >
>> > Is it possible to have the error messages for X also contains the
>> error
>> > for X:a X:b and X:c. I  assume user will want something like
>> > <h:message for="X"/>
>> >
>> > and not have to write
>> >
>> > <h:message for="X"/>
>> > <h:message for="X:a"/>
>> > <h:message for="X:b"/>
>> > <h:message for="X:c"/>
>> >
>> > Is there some mechanics in myfaces that can be of any help to me? Do
i
>> > have to manually transfer message in the component, and if yes, when?
>> >
>>
>>
>>
>>
>
>




--
David Chandler
Development Coach
learnjsf.com

Reply via email to