5 Replies Latest reply on Sep 14, 2009 3:40 AM by nille m

    2 Questions regarding rich:message for tables and how to reR

    nille m Newbie

      Hi all,

      I have two questions I couldn't find answers for. Both questions arise from the same scenario:

      There is a xhtml site with multiple tables on it, eg:

      ....
      <h:panelGroup id="messages">
       <rich:messages/>
      </h:panelGroup>
      ....
      <rich:dataTable value="#{reportTable.descriptions}" var="tableRow" border="0" id="table_1" ajaxKeys="#{rowsToUpdate}" rowKeyVar="currentRowIndex">
       <rich:column styleClass="#{tableRow.styleClass}">
       <h:outputLink value="#{tableRow.linkTarget}">
       <h:outputText value="#{tableRow.linkName}"/>
       </h:outputLink>
       </rich:column>
       ....
      </rich:subTable>
      
      <rich:dataTable value="#{reportTable2.descriptions}" var="tableRow" border="0" id="table_2" ajaxKeys="#{rowsToUpdate}" rowKeyVar="currentRowIndex">
       <rich:column styleClass="#{tableRow.styleClass}">
       <h:outputLink value="#{tableRow.linkTarget}">
       <h:outputText value="#{tableRow.linkName}"/>
       </h:outputLink>
       </rich:column>
       ....
      </rich:subTable>
      


      Now the questions:

      1). For each table I would like to have a separate ' <rich:message> ' tag, displaying only the validation errors for fields of this table. The ' for ' attribute does not work, because an ID of an input field inside the table is dynamically generated and looks like ' employeeForm:table_1:subtable_1:0:j_id398 ' for the first table and ' employeeForm:table_2:subtable_1:0:j_id498 ' for the second table and so on. Great would be something like
      <rich:message for="table_1" />
      to render all errors happening inside table ' table_1 '.

      2.) A few weeks ago I learned from a post in this forum how to re-render certain rows inside a table with ' <a4j:support.../> ' and ' ajayKeys '. Now I have the problem that I have to re-render certain rows in different tables. Say, on an ' onChange ' of an input field in ' table_1 ' I have to re-render some rows in this and maybe the last row in ' table_2 '. For now, I'm re-rendering ' table_2' completely, but that is not really an option.

      I would be grateful for any hint. Thanks a lot in advance.

      Kind Regards,
      nille

        • 1. Re: 2 Questions regarding rich:message for tables and how to
          nille m Newbie

          *Bump*

          Does no one has a clue?

          Kind Regards,
          nille

          • 2. Re: 2 Questions regarding rich:message for tables and how to
            liumin hu Master


            1) i think you cant do it for a table. table is not the component who send the message.


            2)Using ajaxkey, just rerender this 2 tables, set the rows you want in the ajaxkey of 2 table.

            hope this can help you.

            • 3. Re: 2 Questions regarding rich:message for tables and how to
              nille m Newbie

              Hi,

              thanks for your reply. I'll check 2) asap.

              Thanks again.

              Kind Regards,
              nille

              • 4. Re: 2 Questions regarding rich:message for tables and how to
                nille m Newbie

                Hi,

                so, thanks for your hint regarding my question no.2. I did not realize, that one can specify the id in a more detailed way than just the name used for the 'id' attribute. With

                <a4j:commandLink...reRender=":testForm:tab1:col2,:testForm:tab2:col2,:testForm:tab1:col3,:testForm:tab2:col3"/>

                it just works. =).

                As for question no. 1 I have no solution yet.

                Kind Regards,
                nille

                • 5. Re: 2 Questions regarding rich:message for tables and how to
                  nille m Newbie

                  I worked around the other problem by using a custom validator, writing the validation message into a field, which ID is passed as a child of the parent input field. Not a good solution, but I have no other idea.

                  import javax.faces.application.FacesMessage;
                  import javax.faces.component.UIComponent;
                  import javax.faces.context.FacesContext;
                  import javax.faces.validator.Validator;
                  
                  public class TestValidator implements Validator {
                   @Override
                   public void validate(FacesContext arg0, UIComponent arg1, Object arg2) {
                   int myVal = (Integer)arg2;
                   //Id of an not rendered input field; used in the 'for' attribute of the 'message' tag
                   Object ret = arg1.getAttributes().get("target");
                  
                   if(myVal < 0) {
                   FacesMessage myMsg = new FacesMessage();
                   myMsg.setSeverity(FacesMessage.SEVERITY_WARN);
                   myMsg.setDetail("Detail comin' here");
                   myMsg.setSummary("Summary goes here");
                   if(ret != null && ret instanceof String) {
                   String target = (String)ret;
                   javax.faces.context.FacesContext.getCurrentInstance().addMessage(target, myMsg);
                   }
                   }
                   }
                  
                  }
                  


                  The usage in the xhtml page:
                  ...
                  <rich:messages for="testForm:myMsgField"/>
                  ...
                  <h:inputText id="myMsgField" value="#{remoteTestClass.testField}">
                   <a4j:support event="onchange" ajaxSingle="true" action="#{remoteTestClass.test2()}"/>
                   <f:validator validatorId="test.TestValidator"/>
                   <f:attribute name="target" value="testForm:myMsgField"/>
                  </h:inputText>
                  ...
                  <h:inputText id="myMsgField" rendered="false"/>
                  

                  Not shown here the configuration in 'faces-config.xml'

                  If anyone has a better idea I would really appreciate it. The above 'solution' is not really a solution.

                  Kind regards,
                  nille