开发者

RICH:dataTable - add new row

开发者 https://www.devze.com 2023-03-06 12:43 出处:网络
how can I add new row to extendedDataTable at the end of the list? Is there some solution? JSF table example:

how can I add new row to extendedDataTable at the end of the list? Is there some solution?

JSF table example:

RICH:dataTable - add new row

Can you help me?

UPDATE:

I'm able to add new item using for example a rich:popupPanel, but not by creating a new row in datatable. What I wanted to say, I'm able to save but not as elegant as using BalusCs JSF guide.

Part of XHTML:

<rich:extendedDataTable 
 id="tableDetail"
 value="#{myBdeCheck.dataListBde}"
 var="bdeItem">

<rich:column width="80px">
  <f:facet name="header">
     <h:outputText value="Směna" />
  </f:facet>
  <h开发者_Go百科:outputText value="#{bdeItem.dayShift}"/>
</rich:column>

<rich:column width="70px">
  <f:facet name="header">
     <h:outputText value="Karta" />
  </f:facet>
  <h:outputText value="#{bdeItem.bdeno}"/>
</rich:column>

Part of BEAN: package common;

@ViewScoped
@ManagedBean(name="myBdeCheck")
public class MyBdeCheck extends Tools
{
  /**/
  private static final long serialVersionUID = -6586004426692130933L;

  private Session session; 
  private List<BDE> dataListBde; //= new ArrayList<BDE>();
  private int currentIndexDetail;   // index for BDEDetail datatable

  private BDECheckView editedWork;  // one item of BdeCheckView
  private BDE BDEItem;              // one item of BdeData

  // Constructor 
  public MyBdeCheck()
  {
    editedWork = new BDECheckView();
    BDEItem = new BDE();
  }

  /** GET DATA FROM BDEData *******************
   * @param personalNum, dayShift [whole day: YYYY-MM-DD%]
   */
  private void criteriaCheck()
  {
    try 
    {
      Criteria criteria = session.createCriteria(BDE.class);
      {some restrictions}
      dataListBde = criteria.list();
    }  
    catch (Exception e) {...}
   }

  public void saveBde()
  {    
    try
    {
      DaoCrud.update(dataListBde, 'R');  // ulozeni do dtb
    }
    catch  {...}  
  }

  public void saveNew() {...}

// and GETTERS AND SETTERS 
}


Your dataTable is modeling a Collection:

private List<BDE> dataListBde;

To add a new row you would just need to add a new BDE() to the Collection.

this.dataListBde.add(new BDE());

Then you can just reRender your dataTable to see the new row.

Finally, in your xhtml you can conditionally render an inputText or outputText:

<rich:column width="70px">
    <f:facet name="header">
        <h:outputText value="Karta" />
    </f:facet>
    <h:outputText value="#{bdeItem.bdeno}" rendered="#{bdeItem.bdeno != null}"/>
    <h:inputText value="#{bdeItem.bdeno}" rendered="#{bdeItem.bdeno == null}"/>
</rich:column>


The general jsf approach would be to add an empty element at the end of the underlying list in the backing bean and then in your dataTable render an h:outputText if the row element contains data and an h:inputText or some other input component if the row element is empty.

See BalusC's blog entry on "Using datatables" for an example.

It shouldn't be a big problem to adapt it to Richfaces.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号