Rendered in column

Hi
I want to display the following column only when dependant.strOpti == 'OPTI'. When I use the following
code I get illegal state exception:
<h:column id="colGroup" rendered = "#{dependant.strOpti == 'OPTI'}"/>
                <f:facet name="header">
                        <h:outputText id="otxtGroup" value="Comment" rendered = "#{dependant.strOpti == 'OPTI'}"/>
                </f:facet>
                 <h:outputText value="ALL DEPENDENTS COVERED" rendered = "#{dependant.strOpti == 'OPTI'}"/>
                 <h:outputText value="" rendered = "#{dependant.strOpti == ''}"/>
        </h:column>However when I use the following code, no exceptions but the Column will be display when dependant.strOpti
is not OPTI.
<h:column id="colGroup">
                <f:facet name="header">
                        <h:outputText id="otxtGroup" value="Comment" />
                </f:facet>
                 <h:outputText value="ALL DEPENDENTS COVERED" rendered = "#{dependant.strOpti == 'OPTI'}"/>
                 <h:outputText value="" rendered = "#{dependant.strOpti == ''}"/>
        </h:column>Is there some way to fix this?
Thanks
Murthy

BalusC wrote:
murthy64 wrote:
I am very new to JSF. I read the roseindia.net tutorials.
I don't understand your point "the rendered attribute a column cannot be determined at the row object level, but only at the backing bean level."
Could you please elaborate?I did not say that you cannot use the rendered attribute of a column. I have only said that you cannot determine it at the row level, but only at the table level. So replace rendered="#{rowObject.booleanValue}" by rendered="#{managedBean.booleanValue}.Still not clear. Let me rephrase. The table has several columns. How do I prevent one of the columns from appearing? I used the obvious rendered in the
column tag which did not work. I don't want the column to be suppressed at the row level. The column header should not appear when
a rendered test fails.
Here is the table code:
<h:panelGrid width="100%" columns="1" rendered="#{not subscriberListBean.requestDTO.bNoDependents}">
<h:dataTable id="dTblDependants" width="100%" border="0" cellspacing="0"
     cellpadding="4" styleClass="tblContent" style="text-align: left;" columnClasses="mainContent"
     rowClasses="tblContent,tblContentAlternate" headerClass="tblHeaders"
     value="#{subscriberListBean.requestDTO.arrDepAuthDTO}"
     var="dependant" rendered="#{not subscriberListBean.requestDTO.bNoDependents}">
     <h:column id="colFirstName">
          <f:facet name="header">
               <h:outputText id="otxtFirstName" value="#{bundle.otxtFirstName}" />
          </f:facet>
<f:verbatim><strong></f:verbatim>
          <h:commandLink id="clinkDependantClaim_Click" action="#{subscriberListBean.lnk_SubscriberNameClick}"
               onmouseup="hideDepList(); return true;"
               rendered="#{dependant.strStatus == 'ACTIVE'}">
          <h:outputText id="otxtDepFirstName" value="#{dependant.strDepFirstName}" />
          </h:commandLink>
          <h:outputText value="#{dependant.strDepFirstName}"
                    rendered="#{dependant.strStatus == 'INACTIVE'}" />
          <f:verbatim><strong></f:verbatim>
     </h:column>
     <h:column id="colDOB">
          <f:facet name="header">
               <h:outputText id="otxtDOB" value="#{bundle.otxtDOB}" />
          </f:facet>
          <h:outputText value="#{dependant.strDepDOB}" />
     </h:column>
     <h:column id="colStatus">
          <f:facet name="header">
               <h:outputText id="otxtStatus" value="#{bundle.otxtStatus}" />
          </f:facet>
          <h:outputText value="#{dependant.strStatus}"/>
     </h:column>
      <h:column id="colOpti" >
                <f:facet name="header">
                        <h:outputText id="otxtGroup" value="Comment" />
                </f:facet>
                 <h:outputText value="ALL DEPENDENTS COVERED" rendered = "#{dependant.strOpti == 'OPTI'}"/>
                 <h:outputText value="" rendered = "#{dependant.strOpti != 'OPTI'}"/>
        </h:column>
</h:dataTable>
</h:panelGrid>I'd appreciate if you can clarify to me with an example.
Thanks
Murthy

Similar Messages

  • ADF FACES: af:table not rendering all columns

    I'm using ADF EA 17 with myFaces 1.0.9 on JBoss 4.0.1/JVM 1.4.2_07-b05. The af:table is embedded within an af:panelgroup (being body of af:panelbox).
    The af:table is not rendering all columns (only last 2 out of 8 cols total). The model behind the af:table is a java.util.List. Debugging shows that the list is filled up with beans correctly and that each of the properties of such a bean corresponding to a table column are also set correctly.
    Strange thing is that sometimes all columns are rendered ok. Especially if i make heavy changes on the jsp (e.g. removing all but 2 cols from the af:table) and dropping it into the .../jboss/server/../tmp/deploy/tmpXYZ-exp.war directory. Restarting JBoss results in the old behaviour. Also closing browser and re-opening it yields to the missing columns again.
    I've set breakpoints on the bean properties representing on table column and i can see, that the getter methods aren't called (all but those 2 that get rendered finally)
    Table has multiselection enabled with 1 command button.
    This happens with both IE 6 and Firefox 1.0.4; no oracle, myFaces exceptions visible on console or any log file.
    Has anybody made same experiences so far or an idea what the problem really is ?
    best regards,
    Christoph.

    I've tried it also with a plain af:table without any surrounding af:panelgroup or/and af:panelbox. Same result.
    The bean holding the table-model (the java.util.List) is in session-scope. the table-model is update by an actionListener fetching values from an EJB. Could the session-scope be a problem ?
    Potential candidates from my point of view, that might cause trouble here:
    --) Caching (i've seen that sort of "CachedRenderers" are used
    --) partial page rendering
    --) multi-threading issue.
    --) or any silly mistake of mine :-)
    best regards,
    Christoph

  • Rendered=false column is not returning value in simpleSearch Query Region.

    Hi Guru's,
    I have a simpleSearchPanel with two search columns Order Number (Rendered=true, i.e Visible to User in the form) and Order Id(Rendered=False, i.e Non visible to User in the form) which are getting values from LOV. The LOV selection Order Number and Order Id are getting values and Order Number column is rendered true(visible) query able to return the values, but Order Id is not getting values because Rendered=False/Not visible Field.
    Unfortunately i can't make OrderId filed as "formValue" because of simpleSearchPanel (autoCustoomizationCritirea) query region.
    I appreciate your help.
    Regards
    Pathi

    its not the problem with simpleSearchPanel, it is the messageComponentLayout within simpleSearchPanel which is restricting the formValue.
    just change the region style to defaultDoubleColumn and create the formValue into it.
    This should solve your problem..
    --Prasanna                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Partial Page Rendering - Refresh Column Value

    Hi OAF Gurus,
    I created a create page and followed the tutorial on Partital page Rendering creating a PVO view object and I am able to render the "EmployeeNumber" / "Location" column true OR false based on the value of another feild (Area Monitored).
    The "TypeMonitored" (message choice) has 2 values (Area/Employee). If user selects the "Area" then the "EmployeeNumber" column should be hidden and if the user selects "Employee" then the "Location" column should be hidden. it works fine.
    My problem is if the user has selected "Employee" in the "TypeMonitored" poplist and entered the "EmployeeNumber" and then immediately again if the user selects "Area" from the "TypeMonitored" poplist and enters the "Location" (since the location is now visible to the user) and clicks on the Save then the record is getting saved with both the values. I need to have the column value of "Employee" to be blank in this case.
    Basically need to set/clear the value of EmployeeNumber before saving to the database.
    Any help would be greatlly appreciated. Please let me know if you need further details.
    Thanks,
    Mir
    Here is my AMImpl Code
    ===============
    package lac.oracle.apps.lac.lacempexposure.server;
    import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;
    import oracle.apps.fnd.framework.server.OAViewObjectImpl;
    import oracle.jbo.Row;
    import oracle.apps.fnd.framework.OAViewObject;
    import oracle.jbo.Transaction;
    import oracle.jbo.domain.Number;
    import oracle.apps.fnd.framework.OARow;
    import oracle.apps.fnd.common.MessageToken;
    import oracle.apps.fnd.framework.OAException;
    // --- File generated by Oracle ADF Business Components Design Time.
    // --- Custom code may be added to this class.
    // --- Warning: Do not modify method signatures of generated methods.
    public class LacEmpExposureAMImpl extends OAApplicationModuleImpl {
    /**This is the default constructor (do not remove)
    public LacEmpExposureAMImpl() {
    * Initializes the transient application properties VO.
    public void init()
    System.out.println("Into LACEmpExposureAMImpl.java IN init");
    //System.out.println(LacTypeMonitored);
    OAViewObject appPropsVO = (OAViewObject)findViewObject("LacExpCreatePVO1");
    if (appPropsVO != null)
    // Do not reinitialize the VO unless needed. Note that this method call
    // does not try to query the database for VOs with no SELECT statement
    //and only transient attributes.
    if (appPropsVO.getFetchedRowCount() == 0)
    // Setting the match fetch size to 0 for an in-memory VO
    // prevents it from trying to query rows. Calling
    // executeQuery() ensures that rows aren't lost after
    // a commit in the transaction (BC4J known issue workaround).
    appPropsVO.setMaxFetchSize(0);
    appPropsVO.executeQuery();
    // You must create and insert a row in the VO before you can start
    // setting properties.
    appPropsVO.insertRow(appPropsVO.createRow());
    // Set the primary key value for this single-rwo VO.
    OARow row = (OARow)appPropsVO.first();
    row.setAttribute("RowKey", new Number(1));
    } // Initialize the application properties VO (and the UI) based on the
    // default Type Monitored value set on the underlying object.
    handleTypeMonitoredChangeEvent();
    } // end init()
    * Handles changes of the TypeMonitored poplist to set the
    * application properties VO value for PRR
    public void handleTypeMonitoredChangeEvent()
    // Get the special, single-row application properties and make the
    // first(only) row current.
    OAViewObject vo = (OAViewObject)findViewObject("LacExpCreatePVO1");
    OARow row = (OARow)vo.first();
    // Get the value of the view object attribute with the TypeMonitored code
    OAViewObject LacEmpExposureCreateVO = (OAViewObject)findViewObject("LacEmpExposureVO1");
    OARow LacEmpExposureCreateRow = (OARow)LacEmpExposureCreateVO.getCurrentRow();
    String LacTypeMonitored = (String)LacEmpExposureCreateRow.getAttribute("TypeMonitored");
    System.out.println("Into LACEmpExposureAMImpl.java IN handleTypeMonitoredChangeEvent");
    System.out.println(LacTypeMonitored);
    //row.getAttribute("LocationMonitoredRender");
    //System.out.println(row.getAttribute("LocationMonitoredRender"));
    if (("Personal".equals(LacTypeMonitored)))
    row.setAttribute("LocationMonitoredRender", Boolean.FALSE);
    row.setAttribute("EmployeeNumberRender", Boolean.TRUE);
    row.setAttribute("FullNameRender", Boolean.TRUE);
    else if (("Area".equals(LacTypeMonitored)))
    row.setAttribute("LocationMonitoredRender", Boolean.TRUE);
    row.setAttribute("EmployeeNumberRender", Boolean.FALSE);
    row.setAttribute("FullNameRender", Boolean.FALSE);
    } // handleTypeMonitoredChangeEvent()
    /**Sample main for debugging Business Components code using the tester.
    public static void main(String[] args) {
    launchTester("lac.oracle.apps.lac.lacempexposure.server", /* package name */
    "LacEmpExposureAMLocal" /* Configuration Name */);
    /**Container's getter for LacEmpExposureVO1
    public OAViewObjectImpl getLacEmpExposureVO1() {
    return (OAViewObjectImpl)findViewObject("LacEmpExposureVO1");
    /**Container's getter for EmployeeNamesLovVO1
    public OAViewObjectImpl getEmployeeNamesLovVO1() {
    return (OAViewObjectImpl)findViewObject("EmployeeNamesLovVO1");
    /**Container's getter for MonitoringTypeVO1
    public OAViewObjectImpl getMonitoringTypeVO1() {
    return (OAViewObjectImpl)findViewObject("MonitoringTypeVO1");
    /**Container's getter for LacParameterMonitoredVO1
    public OAViewObjectImpl getLacParameterMonitoredVO1() {
    return (OAViewObjectImpl)findViewObject("LacParameterMonitoredVO1");
    *Creates a new Exposure Record
    public void CreateLacEmpExposure()
    OAViewObject vo = (OAViewObject)getLacEmpExposureVO1();
    //Per the coding standards, this is the proper way to
    //initialize a VO that is used for both inserts and queries.
    //See View Objects in detail in then Developers Guide for
    //additional Information.
    System.out.println("Into LACEmpExposureAMImpl.java IN CreateLacEmpExposure");
    if(!vo.isPreparedForExecution())
    vo.executeQuery();
    Row row = vo.createRow();
    vo.insertRow(row);
    //Required per OA Framework Model Coding Standard M69
    row.setNewRowState(Row.STATUS_INITIALIZED);
    } // end CreateLacEmpExposure
    *Executes a rollback including the database and the middle tier
    public void rollbackLacEmpExposure()
    Transaction txn = getTransaction();
    // This small optimization ensures that we dont persorm a rollback
    // if we don't have to.
    if (txn.isDirty())
    txn.rollback();
    } // end rollbackLacEmpExposure()
    /**Container's getter for LacEmpExposureLOVDataVO1
    public OAViewObjectImpl getLacEmpExposureLOVDataVO1() {
    return (OAViewObjectImpl)findViewObject("LacEmpExposureLOVDataVO1");
    * Commits the transaction
    public void Apply()
    getTransaction().commit();
    } // end apply()
    /**Container's getter for LacExpCreatePVO1
    public OAViewObjectImpl getLacExpCreatePVO1() {
    return (OAViewObjectImpl)findViewObject("LacExpCreatePVO1");
    * Initializes the detail employee query for Update Page.
    public void initDetailsUpdate(String EmployeeNumber,
    String FullName,
    String RecordSeq)
    System.out.println("Into LACEmpExposureAMImpl.java IN initDetailsUpdate");
    System.out.println("LACEmpExposureAMImpl ==> EmployeeNumber in initQueryUpdate is: " + EmployeeNumber);
    System.out.println("LACEmpExposureAMImpl ==> FullName in initQueryUpdate is: " + FullName);
    System.out.println("LACEmpExposureAMImpl ==> RecordSeq in initQueryUpdate is: " + RecordSeq);
    // OAViewObjectImpl vo = getLacEmpExposureVO1();
    LacEmpExposureEditVOImpl vo = (LacEmpExposureEditVOImpl)getLacEmpExposureEditVO1();
    // OAViewObject vo = (OAViewObject)getLacEmpExposureVO1();
    if (vo == null)
    MessageToken[] errTokens = { new MessageToken("OBJECT_NAME", "LacEmpExposureVO1") };
    throw new OAException("AK", "FWK_TBX_OBJECT_NOT_FOUND", errTokens);
    vo.InitQueryUpdate(EmployeeNumber, FullName, RecordSeq);
    Row row=vo.first();
    vo.setCurrentRow(row);
    // Since we're querying a single row with a primary key value, we
    // can use the findByKey method which first checks the BC4J cache,
    // and if it doesn't find a matching row, it will formulate a query using
    // the given key and retrieve it from the database.
    String[] keys = { employeeNumber };
    Row[] rows = vo.findByKey(new Key(keys), 1);
    // You must set the current row, or the Details page won't display any
    // data. When you explicitly query data, you don't have to do this.
    if (rows != null)
    vo.setCurrentRow(rows[0]);
    } // end initDetails()
    /**Container's getter for LacEmpExposureEditVO1
    public LacEmpExposureEditVOImpl getLacEmpExposureEditVO1() {
    return (LacEmpExposureEditVOImpl)findViewObject("LacEmpExposureEditVO1");
    } // end class LacEmpExposureAMImpl

    Hi,
    In your LacTypeMonitored // I assume this will be triggered when you change the poplist value form Employee to Area
    Add a logic to null the Employee value
    if (("Area".equals(LacTypeMonitored)))
    row.setAttribute("LocationMonitoredRender", Boolean.TRUE);
    row.setAttribute("EmployeeNumberRender", Boolean.FALSE);
    row.setAttribute("FullNameRender", Boolean.FALSE);
    //Set the employee attribute to null
    (OARow)LacEmpExposureCreateVO.getCurrentRow().setAttribute("<employeeAttribute >",null);
    Let me know it works.
    Thanks,
    With regards,
    Kali.
    OSSI.

  • Execute PL/SQL statement on rendered report column only (APEX 4.02)

    Hello,
    i have a classic report which selects approx. 100.000 rows. For one of the columns in the sql i am executing
    a rather complex PL/SQL function which generates additional html. This function slows down the query
    by a tremendous amount (over one hour for the select, without this function it's 30 seconds) so i don't
    want to execute it for each selected row but for the rendered ones only (15 per page).
    Is it possible to do so in a report?

    Steven Mark wrote:
    So if APEX does not give us the option to execute PL/SQL scripts on actually rendered columns onlyI have long thought that this is a major limitation of APEX. We know from Marc's post Re: Reports/Tabular Form and number of executions of a Lov Query that built-in column display operations are only performed for the rows rendered on the current page. However, there are many requirements (even relatively simple ones like row-level conditional display) that are impossible to meet using the built-in Display As/LOV, HTML Expression, Tabular Form Element, and Column Link display options. The alternatives are inefficient (context switching to user-defined functions) or poor practice (losing the separation of concerns by generating HTML/links in report queries).
    The ability to call user-defined functions at the same rendering point as built-in column display operations, and to apply row-level conditions to built-in display options are long overdue enhancements.

  • Rendering a column before the nodeStamp column in an af:treeTable

    I have a requirement to show a column before the nodeStamp column in a treeTable.
    Is there a way to achieve this?
    Code looks like the following -
    <af:column id="t3c1" width="50px" headerText="#{dbdiscoveryuiBundle.SELECT}" align="center">
    <af:selectBooleanCheckbox .... />
    </af:column>
    <f:facet name="nodeStamp">
    <af:column id="t3c2" rowHeader="unstyled" headerText="#{dbdiscoveryuiBundle.TARGET_NAME}" width="80%" align="start">
      <af:outputText ...." />
    </af:column>
    </f:facet>
    Expected order -> Checkbox first followed by OutputText
    NOTE - Making rowHeader=true is not an option because of accessibility violations
    Thanks,
    Vishwesh

    Hi user,
    Do you need the header for the select one choice? you could so something like:
    <af:column id="c1">
                            <af:panelGroupLayout id="pgl1" layout="horizontal">
                                <af:selectOneChoice value="#{bindings.DepartmentsView1.inputValue}"
                                                    label="#{bindings.DepartmentsView1.label}"
                                                    required="#{bindings.DepartmentsView1.hints.mandatory}"
                                                    shortDesc="#{bindings.DepartmentsView1.hints.tooltip}" id="soc1">
                                    <f:selectItems value="#{bindings.DepartmentsView1.items}" id="si1"/>
                                    <f:validator binding="#{bindings.DepartmentsView1.validator}"/>
                                </af:selectOneChoice>
                                <af:outputText value="#{node}" id="ot1"/>
                            </af:panelGroupLayout>
                        </af:column>
    But that will be all in the same column so I guess you tried that already.

  • How to build a custom movie clip that will be used as a cell renderer for column in a grid ?

    i want to build a datagrid that shows a picture and underneath it a name.
    the problem is i dont want to see all of the pictures, but all the pictures that have certain requirements, so i cant just make one movie clip that includes all the pictures and names.
    so my question is how do i build a movie clip that contains photo and text?.

    You do not create movieclips on the timeline using code, though you can create them and add them as children of something that has been manually placed in the timeline.
    To create a MovieClip using code you use: 
        var mc:MovieClip = new MovieClip();
    If you need to add an image, then however you intend to acquire the image, after it has been acquired, you add it to the MovieClip using:  
        mc.addChild(img); 
    where img is the instance of whatever form of object the image takes (Bitmap, Loader)
    If you need to add a TextField to the MovieClip then you use: 
        var tf:TextField = new TextField();
        mc.addChild(tf);
    and you can set up properties for the textfield such as the font and color and position as well after it has been instantiated (the first line).

  • Table Rendering - Row level vs Column level

    Normally renderers are specified for a given class of data or column of data.
    So, how would you handle rendering requirements that are row or table dependent? For example, how do I:
    a) color alternate lines in a table
    b) change the border of the selected cell
    Traditional Approach
    Most answers in the forum would be something like "use a custom render". Sounds great, but what does it really mean? If all your data is displayed as a String then it really isn't too difficult to create a single renderer with the required logic and add it to the table as the default renderer.
    However, what if you table contains, String's, Dates, Integer's, Double's and Boolean's and you want your cell to retain the default formatting of each data type in addition to the above requirement? Now you have two options:
    a) render by class (multiple renderers). Each renderer would need to implement the default "formatting" of the data (dates: dd-MMM-yyy, numbers: right justified, etc) in addition to the "row/table" rendering requirements. So the answer really becomes "use five custom renderers". Now the "row/table" rendering code is found in 5 classes. Of course you could always move the "row/table" rendering code up to a common base class.
    b) render by table (single renderer). A single custom renderer would be created and would need to implement the default "formatting" for all data types in the table, in addition to the "row/table" rendering. The benefit is that all the rendering code is in one class. An example solution is include for this approach.
    Alternative Approach
    I recently came across an approach where the "formatting" of the data is still done by the default renderers and the "row/table" rendering is done at the table level by overriding the prepareRenderer() method. This approach is much simpler, but the rendering is done in two different places. Is this a problem?
    So, my question is which approach do you prefer:
    a) Traditional Approach - multiple renderers
    b) Triditional Approach - single renderer
    c) Alternative Approach
    Me, I like the alternative approach, but I'm more of a problem solver than I am a designer, so I don't know how the solution fits in a large scale application.
    Hopefully your response will consider:
    a) OO design principles
    b) class reusability
    c) class maintenance
    d) anything else you can think of
    import java.awt.*;
    import java.text.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    public class TableRowRendering extends JFrame
        JTable table;
        Border selected = new LineBorder(Color.GREEN);
        public TableRowRendering()
            //  Model used by both tables
            Object[] columnNames = {"Type", "Date", "Company", "Shares", "Price"};
            Object[][] data =
                {"Buy", new Date(), "IBM", new Integer(1000), new Double(80.50)},
                {"Sell",new Date(), "MicroSoft", new Integer(2000), new Double(6.25)},
                {"Sell",new Date(), "Apple", new Integer(3000), new Double(7.35)},
                {"Buy", new Date(), "Nortel", new Integer(4000), new Double(20.00)}
            DefaultTableModel model = new DefaultTableModel(data, columnNames)
                public Class getColumnClass(int column)
                    return getValueAt(0, column).getClass();
            //  Traditional Approach
            table = new JTable( model );
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            getContentPane().add(new JScrollPane( table ), BorderLayout.WEST);
            TableCellRenderer custom = new CustomRenderer();
            table.setDefaultRenderer(Object.class, custom);
            table.setDefaultRenderer(String.class, custom);
            table.setDefaultRenderer(Date.class, custom);
            table.setDefaultRenderer(Number.class, custom);
            table.setDefaultRenderer(Double.class, custom);
            //  Alternative Approach
            table = new JTable( model )
                public Component prepareRenderer(
                    TableCellRenderer renderer, int row, int column)
                    Component c = super.prepareRenderer(renderer, row, column);
                    if (!isRowSelected(row))
                        String type = (String)getModel().getValueAt(row, 0);
                        c.setBackground(row % 2 == 0 ? null : Color.LIGHT_GRAY );
                    if (isRowSelected(row) && isColumnSelected(column))
                        ((JComponent)c).setBorder(selected);
                    return c;
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            getContentPane().add(new JScrollPane( table ), BorderLayout.EAST);
        //  Custom renderer used by Traditional approach
        class CustomRenderer extends DefaultTableCellRenderer
            DateFormat dateFormatter = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
            NumberFormat numberFormatter = NumberFormat.getInstance();
            public Component getTableCellRendererComponent(
                JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column)
                super.getTableCellRendererComponent(
                    table, value, isSelected, hasFocus, row, column);
                //  Code for data formatting
                setHorizontalAlignment(SwingConstants.LEFT);
                if ( value instanceof Date)
                    setText(dateFormatter.format((Date)value));
                if (value instanceof Number)
                    setHorizontalAlignment(SwingConstants.RIGHT);
                    if (value instanceof Double)
                        setText(numberFormatter.format(((Number) value).floatValue()));
                //  Code for highlighting
                if (!isSelected)
                    String type = (String)table.getModel().getValueAt(row, 0);
                    setBackground(row % 2 == 0 ? null : Color.LIGHT_GRAY );
                if (table.isRowSelected(row) && table.isColumnSelected(column))
                    setBorder(selected);
                return this;
        public static void main(String[] args)
            TableRowRendering frame = new TableRowRendering();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setLocationRelativeTo( null );
            frame.setVisible(true);
    }Before you make your final decision. What changes would be required for each solution in the following "what if " scenarios:
    a) what if, you added a Boolean column to the table
    b) what if, you added a second Double column to the table which should be formatted as a currency (ie. 1,234.5 --> $1,234.50).
    Here is an example of a currency renderer:
    class CurrencyRenderer extends DefaultTableCellRenderer
         private NumberFormat formatter;
         public CurrencyRenderer()
              super();
              formatter = NumberFormat.getCurrencyInstance();
              setHorizontalAlignment( SwingConstants.RIGHT );
         public void setValue(Object value)
              if ((value != null) && (value instanceof Number))
                   value = formatter.format(value);
              super.setValue(value);
    }

    Well, here's a partila solution using technique from a link you cited in another thread.
    import tests.basic.tables.ColorProvider;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.text.NumberFormat;
    public class DecoratedTablePrepareRenderer extends JFrame {
        JTable table;
        private DefaultTableModel model;
        public DecoratedTablePrepareRenderer() {
            Object[] columnNames = {"Type", "Company", "Price", "Shares", "Closed"};
            Object[][] data =
                        {"Buy", "IBM", new Double(80.50), new Double(1000), Boolean.TRUE},
                        {"Sell", "MicroSoft", new Double(6.25), new Double(2000), Boolean.FALSE},
                        {"Sell", "Apple", new Double(7.35), new Double(3000), Boolean.TRUE},
                        {"Buy", "Nortel", new Double(20.00), new Double(4000), Boolean.FALSE}
            model = new DefaultTableModel(data, columnNames);
            table = new JTable(model) {
                //  Returning the Class of each column will allow different
                //  renderers to be used based on Class
                public Class getColumnClass(int column) {
                    return getValueAt(0, column).getClass();
                public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
                    Component c = super.prepareRenderer(renderer, row, column);
                    if (isRowSelected(row))
                        c.setFont(c.getFont().deriveFont(Font.BOLD));
                    return c;
            ColorProvider prov = new TransactionColorProvider();
            ColorTableCellRenderer renderer = new ColorTableCellRenderer(table.getDefaultRenderer(Object.class),prov);
            ColorTableCellRenderer boolrenderer = new ColorTableCellRenderer(table.getDefaultRenderer(Boolean.class),prov);
            ColorTableCellRenderer doublerenderer = new ColorTableCellRenderer(table.getDefaultRenderer(Double.class),prov);
                    int priceIndex = model.findColumn("Price");
              table.getColumnModel().getColumn(priceIndex).setCellRenderer( new EtchedBorderTableCellRenderer(new ColorTableCellRenderer(new CurrencyRenderer(),prov) ));
            table.setDefaultRenderer(Object.class,new EtchedBorderTableCellRenderer(renderer));
            table.setDefaultRenderer(Double.class,new EtchedBorderTableCellRenderer(doublerenderer));
            table.setDefaultRenderer(Boolean.class, new EtchedBorderTableCellRenderer(boolrenderer));
            JScrollPane scrollPane = new JScrollPane(table);
            getContentPane().add(scrollPane);
        class CurrencyRenderer extends DefaultTableCellRenderer {
            private NumberFormat formatter;
            public CurrencyRenderer() {
                super();
                formatter = NumberFormat.getCurrencyInstance();
                setHorizontalAlignment(SwingConstants.RIGHT);
            public void setValue(Object value) {
                if ((value != null) && (value instanceof Number)) {
                    value = formatter.format(value);
                super.setValue(value);
        public static void main(String[] args) {
            DecoratedTablePrepareRenderer frame = new DecoratedTablePrepareRenderer();
            frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        class ColorTableCellRenderer implements TableCellRenderer{
            protected TableCellRenderer delegate;
            protected ColorProvider provider;
            public ColorTableCellRenderer(TableCellRenderer delegate, ColorProvider provider) {
                this.delegate = delegate;
                this.provider = provider;
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                Component c = delegate.getTableCellRendererComponent(table, value,isSelected,hasFocus,row, column);
                  c.setBackground(provider.getBackgroundColor(row, column));
                return c;
          class EtchedBorderTableCellRenderer implements TableCellRenderer{
            protected TableCellRenderer delegate;
            public EtchedBorderTableCellRenderer(TableCellRenderer delegate) {
                this.delegate = delegate;
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                JComponent c = (JComponent)delegate.getTableCellRendererComponent(table, value,isSelected,hasFocus,row, column);
                  JPanel panel = new JPanel(new GridLayout(0,1));
                  panel.add(c);
                  panel.setBorder(BorderFactory.createEtchedBorder());
                return panel;
        class TransactionColorProvider implements ColorProvider {
            private int keyIndex = 0;
            private Color sellColor = Color.yellow;
            private Color buyColor = Color.green;
            public TransactionColorProvider() {
                keyIndex = model.findColumn("Type");
            public Color getBackgroundColor(int row, int column) {
                 if( model.getValueAt(row,keyIndex).equals("Sell")){
                     return sellColor;
                else {
                     return buyColor;
            public Color getForegroundColor(int row, int column) {
                return Color.black;
    }Boolean values are problematical since JCheckBox does seem to like borders, using a panel as I did in the Etched renderer seems to work. This solution need a little more work, this is submitted as a prototype
    Cheers
    DB

  • Selection problem in rendered JtextArea.

    I create a jtable by rendering one column using jTextarea. While selecting the row, color of selection not geting to the rendered Jtextarea. How can i solve this problem.
    please help me

    Do you include code in your getTableCellRendererComponent method to change
    the color depending on if the row is selected or not? You'll need something like
         if ( isSelected ) {
              setForeground( table.getSelectionForeground() );
              setBackground( table.getSelectionBackground() );
         } else {
              setForeground( table.getForeground() );
              setBackground( table.getBackground() );
         }: jay

  • Urgent need help in Rendering

    Requirment :- i have table with two column and three rows, "i need to put comboBox in first two cells of second column".
    if i set the column-2 for rendering entair column has comboBox i need to put comboBox into First & Second cell of second column third cell of second column shouldn't have comboBox.
    how can i do this,i donno how to set renderer to single cell.
    anything related to this will be a great help for me
    Thank's in Advance

    Check out this posting for one possible solution:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=637581

  • Table Cell Renderer

    Hi,
    I have a JTable with 2 columns. One of the column is editable. But depending on a checkbox selection outside the table, I need to make the column noneditable, i.e. if the checkbox is selected the column is editable else the column is non-editable.
    To enable this I have rendered the column as below:
          // rendered the column
          col2.setCellRenderer(new EnableCellRenderer(flag)); //flag is either true or false
            class EnableCellRenderer  extends DefaultTableCellRenderer {
              boolean isEnable;
              public EnableCellRenderer(boolean enable) {
                isEnable = enable;
              public Component getTableCellRendererComponent(JTable table, Object value,
                                                             boolean isSelected,
                                                             boolean hasFocus, int row, int column) {
                setEnabled(isEnable);
                return super.getTableCellRendererComponent(table, value, isSelected,
                                                           hasFocus, row, column);
            }This is working fine but whats happening is when the column is disabled(I am not able to edit which is fine), it is not getting greyed out,
    I mean the backgroung color is still white. Is there any way how I can disable the column as well as grey out the column.
    Thanks

    I would override the isCellEditable(...) method of JTable. Something like:
    if (column == ??? && !isEnabled)
        return false;
    else
        return true;

  • Image inside facet not rendering

    <t:column>
          <f:facet name="header">                               
                  <h:graphicImage value="images/pic.gif" />   // NOT RENDERING
          </f:facet>                                                            
          <h:graphicImage value="images/pic.gif" />             // IS RENDERING
    </t:column>
    // WHY IS THE IMAGE INSIDE THE  "<facet>"  TAG NOT RENDERING ?

    Uh, yup, that sure solved it.  Thanks Tom.

  • Item renderer for specific rows

    I need to have a checkbox item renderer for a spark datagrid column. I am using the following to get an item renderer into column:
    var checkBoxRenderer:ClassFactory = new ClassFactory(GridCheckBoxItemRenderer);
    column.itemRenderer = checkBoxRenderer;
    My question is if I need to show a checkbox for specific rows can I do that without going into GridCheckBoxItemRenderer's source code?
    Thanks

    Hi Zolotoj ,
    Please go through following links :
    http://stackoverflow.com/questions/1952940/show-itemrenderer-in-specific-datagrid-rows-oth ers-empty
    http://www.flexer.info/2009/01/09/different-rows-in-datagrid-programmatically-added-itemre nderers-classfactory-and-ifactory/
    It will provide you some idea to how to proceed further for this problem.
    Thanks and Regards,
    Vibhuti Gosavi | [email protected] | www.infocepts.com

  • TableSorter + custom cell renderer: how to get DISPLAYED value?

    Hi!
    I have a JTable with a custom cell renderer. This renderer translates numerical codes, which are stored in the table model, into textual names. E.g. the table model stores country codes, the renderer displays the name of the country.
    Now, having a reference on the JTable, how can I get the DISPLAYED value, i.e. the country name? Is there some method like ....getRenderer().getText()?
    Thanx,
    Thilo

    Well, a renderer can be anything. It may be rendering an image not text so you can't assume a method like getText(). However, since you know the component being used to render the cell you should be able to do something like:
    TableCellRenderer renderer = table.getCellRenderer(row, column);
    Component component = table.prepareRenderer(renderer, row, column);
    Now you can cast the component and use get text.
    Another option would be to store a custom class on the table cell. This class would contain both the code and value. The toString() method would return the value. Whenever you want the code you would use the table.getValueAt(...) method and then use the classes getCode() method. Using this approach you would not need a custom renderer. This thread shows how you can use this approach using a JComboBox, but the concept is the same for JTable as well:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=417832

  • Adding Dynamic column to datagrid at the begining of datagrid

    Hello friends,
    There is one datagrid which is static. and i m adding one dynamic column. it is get added to the end of the static datagrid
    but I want to add dynamic column at the begning of the datagrid can anybody help me on this.
    Thanking you,
    Regards,
    gajanan

    Thanks to everybody.
    finally i got the things to work using following code.
    private  function SwapGridColumns (DG:DataGrid, Col1:Number, Col2:Number):void
                    var i:Number; // Counter
                    var DP:ArrayCollection =ArrayCollection( DG.dataProvider);     //DataProvider
                    var Widths:Array = new Array ();     // the widths of the columns
                    var Columns:Array = new Array ();    // the column names
                    var Visibility:Array = new Array (); // visibility of columns
                    var HRenderer:Array = new Array ();   // Header Renderer of columns
                    var IRenderer:Array = new Array();
                    var datastore:Array = new Array ();
                    var Editable:Array = new Array();
                    var DFields:Array=new Array();
                    var Sortable:Array = new Array();
                    for (i = 0; i<DG.columns.length; i++)
                        if (i == Col1)
                            Columns.push(DG.columns[Col2].headerText);
                            Widths.push(DG.columns[Col2].width);
                            Visibility.push(DG.columns[Col2].visible);
                            HRenderer.push(DG.columns[Col2].headerRenderer);
                            IRenderer.push(DG.columns[Col2].itemRenderer);
                            Editable.push(DG.columns[Col2].editable);
                            Sortable.push(DG.columns[Col2].sortable);
                            DFields.push(DG.columns[Col2].dataField);
                        else if (i == Col2)
                            Columns.push(DG.columns[Col1].headerText);
                            Widths.push(DG.columns[Col1].width);
                            Visibility.push(DG.columns[Col1].visible);
                            HRenderer.push(DG.columns[Col1].headerRenderer);
                            IRenderer.push(DG.columns[Col1].itemRenderer);
                            Editable.push(DG.columns[Col1].editable);
                            Sortable.push(DG.columns[Col1].sortable);
                            DFields.push(DG.columns[Col1].dataField);
                        else
                            Columns.push(DG.columns[i].headerText);
                            Widths.push(DG.columns[i].width);
                            HRenderer.push(DG.columns[i].headerRenderer);
                            IRenderer.push(DG.columns[i].itemRenderer);
                            Editable.push(DG.columns[i].editable);
                            Sortable.push(DG.columns[i].sortable);
                            DFields.push(DG.columns[i].dataField);
                    // Reset the widths
                    var col:Array
                    for (i = 0; i < Columns.length; i++)
                        var DGC:DataGridColumn = new DataGridColumn(Columns[i]);
                        DGC.width = Widths[i];
                        DGC.visible = Visibility[i];
                        DGC.headerRenderer = HRenderer[i];
                        DGC.itemRenderer = IRenderer[i];
                        DGC.dataField=DFields[i];
                        DGC.sortable=Sortable[i];
                        DGC.editable=Editable[i];
                        datastore.push(DGC);
                    DG.columns=datastore;
                    // Load DP
                    DG.dataProvider = DP;
    Regards,
    gajanan

Maybe you are looking for