jsf

DataTable中点击link/button修改某行数据...可以通过以下几种方法来实现:

1> 利用<f:param>来传递参数,如id等...
页面代码如下:
程序代码 程序代码

<t:dataTable var="emp" .... >
    <h:commandLink id="editLink" action="#{employeeAction.prepareEdit}">
    <h:outputText value="#{msg.edit}"/>
    <f:param name="id" value="#{emp.id}"/>
</h:commandLink>

后台取得参数代码:
程序代码 程序代码

FacesContext context = FacesContext.getCurrentInstance();
Map map = context.getExternalContext().getRequestParameterMap();
String employeeID = (String) map.get("id");
 
2> 通过actionListeners来获得点击的是哪一行,从而获得dataTable,将之转化为YourBeanClass...即可得到那个实例,即那行数据...这样做的好处是:不需要再去数据库拿那条数据...
由此可见,JSF把页面上的控件也是放在session中进行管理的...,具体实现如下:
页面代码如下:
程序代码 程序代码

<h:dataTable value="#{ResultsBean.hitSet.hits}" var="hit">
  <h:column>
    <h:commandLink>
      <f:actionListener type="net.java.OrderActionListener" />
      <h:outputText value="Order" />
    </h:commandLink>
    ...
  </h:column>
</h:dataTable>

后台代码:
程序代码 程序代码

public class orderActionListener implements ActionListener {

    public void processAction(ActionEvent anEvent) throws AbortProcessingException {

    YourBeanClass tmpBean = null;

    UIComponent tmpComponent = anEvent.getComponent();

    while (null != tmpComponent && !(tmpComponent instanceof UIData)) {
        tmpComponent = tmpComponent.getParent();
    }

    if (tmpComponent != null && (tmpComponent instanceof UIData)) {
        Object tmpRowData = ((UIData) tmpComponent).getRowData();
        if (tmpRowData instanceof YourBeanClass) {
            tmpBean = (YourBeanClass) tmpRowData;

            //TODO Implementation of your method

        }
    }

    //TODO Exception Handling if UIData not found or tmpRowBean of wrong type

  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值