1 Reply Latest reply on Aug 17, 2010 8:27 AM by Andy Torble

    How to assign value to object array in richfaces

    Olalekan Ogunleye Newbie

      Hi All,


      I have a been which looks like this



      private void _Initialize(String query, String[] restrictions) {
              // Set the query and restrictions to use
              this.setOrder(ORDER); //Override the getOrder in the EntityQuery


      public List<Object[]> getDistinctTopic() {
               distinctTopic = this.getEntityManager().createQuery(QUERY_DINSTICT_TOPIC).getResultList();


      return distinctTopic;


      in my view.xhtml I want to display the value of distinctTopic which is a list object array


      I have been struggling to do this but I dont get how to assign the value. All I have tried are not working. Can someone please help me.


      This is my view.xhtml


      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"


      <ui:define name="body">


              <f:facet name="header">Voting Results</f:facet>




                  <h:outputText value="No vote exists"
                             rendered="#{empty distinctTopic}"/>


                  <rich:dataTable id="voteList" var="myTopic"
                         rendered="#{not empty distinctTopic}">
                          <f:facet name="header">Topic</f:facet>
                          <!--<s:link value="#{myTopic.toString()}" view="/voteResult.xhtml" /-->






              <s:button id="done"
                     value="Create vote"





        • 1. Re: How to assign value to object array in richfaces
          Andy Torble Newbie

          A couple of things jump out at me that might be causing you some issues.


          Firstly, your EL expression to retreive the List of Topics isn't qualified by the registered managed bean name (you have registered it in faces-config haven't you?).  You're referring to #{attribute_name} as opposed to the normal #{bean_name.attribute_name}. see http://today.java.net/pub/a/today/2006/03/07/unified-jsp-jsf-expression-language.html


          Secondly, I don't think your #{distinctTopic.toArray(a)} expression will work either as you don't have an instance of an array 'a' to pass to the method - don't think you can even pass values to methods like this anyway.  Your construct of #{myTopic.toString()} is more likely to succeed, but I'd rather not reply on toString() to provide the value required.  Why not have a immutable Topic class with a getter to provide the name and refactor your getDistinctTopic() to generate and return a List<Topic>?  Your can then use your dataTable var ("myTopic") to render the topic's name with #{myTopic.name}