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

    How to assign value to object array in richfaces

    olasamuel

      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.setEjbql(query);
              this.setRestrictionExpressionStrings(Arrays.asList(restrictions));
              this.setOrder(ORDER); //Override the getOrder in the EntityQuery
              this.setMaxResults(2500);
              getDistinctTopic();

       

      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"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://jboss.com/products/seam/taglib"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:rich="http://richfaces.org/rich"
          template="layout/template.xhtml">

       

      <ui:define name="body">

       

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

       

              <div>

       

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

       

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

       

              </div>

       

          </rich:panel>

       

          <!--<div>
              <s:button id="done"
                     value="Create vote"
                      view="/vote.xhtml"/>
          </div>-->

       

      </ui:define>

       

      </ui:composition>

        • 1. Re: How to assign value to object array in richfaces
          atorble

          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}

           

          Andy