h:commandLink不能在dataTable里面工作 [英] h:commandLink not working inside dataTable

查看:213
本文介绍了h:commandLink不能在dataTable里面工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



< h:form>< h:commandLink value =创建新员工帐户action =adminCreateStaffMember/>< / h:form>



使用这个,当我创建在创建新员工帐户我被重定向到我有表单创建新帐户的页面。



但是,当我在 dataTable 中使用相同的内容时,采取 NO ACTION 。我仍然在同一页面上:(

 < h:dataTable var =cvalue =#{newStaffMemberServiceBean.newStaffMemberDataBeanList $
styleClass =order-table
headerClass =order-table-header
rowClasses =order-table-odd-row,order-table-even-row
border =1id =staffListDataTablewidth =100%>

< h:column>
< f:facet name =header> ;
工作人员名称
< / f:facet>
< h:form>< h:commandLink value =创建新员工帐户action =adminCreateStaffMember/> < / h:form>
< / h:column>
< / h:dataTable>

其实我想打印的是相关工作人员的细节,我将使用 f:setPropertyActionListener ,但是如上所述不行,我不要继续。



请给我建议我去哪里 错误



更新1



我的 newS taffMemberServiceBean RequestScoped

  @ManagedBean (name =newStaffMemberServiceBean)
@RequestScoped
public class NewStaffMemberServiceBean {
// some code
}



更新2



HTML生成如下



dataTable

 < div align =right> 
< form id =j_idt35name =j_idt35method =postaction =/ adminManageStaffMemberenctype =application / x-www-form-urlencoded>
< input type =hiddenname =j_idt35value =j_idt35/>
< a href =#onclick =mojarra.jsfcljs(document.getElementById('j_idt35'),{'j_idt35:j_idt36':'j_idt35:j_idt36'},''); return false> ;创建新员工帐户< / a>< input type =hiddenname =javax.faces.ViewStateid =javax.faces.ViewStatevalue =2664682277023387375:-3250423983171933030autocomplete =off/> ;
< / form>

里面 dataTable

 < form id =staffListDataTable:0:j_idt43name =staffListDataTable:0:j_idt43method =post action =/ adminManageStaffMemberenctype =application / x-www-form-urlencoded> 
< input type =hiddenname =staffListDataTable:0:j_idt43value =staffListDataTable:0:j_idt43/>
< a href =#onclick =mojarra.jsfcljs(document.getElementById('staffListDataTable:0:j_idt43'),{'staffListDataTable:0:j_idt43:j_idt45':'staffListDataTable:0:j_idt43: j_idt45'},''); return false>创建新员工帐户< / a>< input type =hiddenname =javax.faces.ViewStateid =javax.faces.ViewStatevalue = 2664682277023387375:-3250423983171933030autocomplete =off/>
< / form>


解决方案

我会为您的原始代码建议一些修改。首先,不要为每个 commandLink 使用 h:form ,而是使用一个表单作为 dataTable 。第二,动作只有在找到触发aciton的组件时才会被执行。如果您为 datatable 使用了一个请求作用域列表,那么当视图恢复时,该列表将不会在那里,或者可能与用于创建视图的原始列表不一致。您可能必须将托管bean从请求范围更改为视图或更高版本。



第三,作为建议,您可以使用h:outputLink或h:link而不是commandLink,并提供f:param来简化此操作,在这种情况下,您不要需要表单。


In my JSF file I have below at the start.

<h:form><h:commandLink value="Create New Staff Account" action="adminCreateStaffMember"/></h:form>.

By use of this, when I create on Create New Staff Account I get re-directed to the page where I have form to create new account.

BUT, When I use the same inside dataTable, NO ACTION is taken. I am still on same page :(

<h:dataTable var="c" value="#{newStaffMemberServiceBean.newStaffMemberDataBeanList}"
  styleClass="order-table"
  headerClass="order-table-header"
  rowClasses="order-table-odd-row,order-table-even-row"
  border="1" id="staffListDataTable" width="100%">

  <h:column>
    <f:facet name="header">
       Staff Member Name
    </f:facet>
    <h:form><h:commandLink value="Create New Staff Account" action="adminCreateStaffMember"/></h:form>
  </h:column>
</h:dataTable>

Actually what I wanted to print is details of respective staff member where I would be using f:setPropertyActionListener. But as above is not working, I won't go ahead.

Please suggest me where I am going wrong.

Update 1

My newStaffMemberServiceBean is in RequestScoped

@ManagedBean(name = "newStaffMemberServiceBean")
@RequestScoped
public class NewStaffMemberServiceBean {
    // some code
}

Update 2

HTML Generated are as below

Outside of dataTable

<div align="right">
<form id="j_idt35" name="j_idt35" method="post" action="/adminManageStaffMember" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt35" value="j_idt35" />
<a href="#" onclick="mojarra.jsfcljs(document.getElementById('j_idt35'),{'j_idt35:j_idt36':'j_idt35:j_idt36'},'');return false">Create New Staff Account</a><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="2664682277023387375:-3250423983171933030" autocomplete="off" />
</form>

Inside dataTable

<form id="staffListDataTable:0:j_idt43" name="staffListDataTable:0:j_idt43" method="post" action="/adminManageStaffMember" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="staffListDataTable:0:j_idt43" value="staffListDataTable:0:j_idt43" />
<a href="#" onclick="mojarra.jsfcljs(document.getElementById('staffListDataTable:0:j_idt43'),{'staffListDataTable:0:j_idt43:j_idt45':'staffListDataTable:0:j_idt43:j_idt45'},'');return false">Create New Staff Account</a><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="2664682277023387375:-3250423983171933030" autocomplete="off" />
</form>

解决方案

I would suggest a few modifications for your original code. First, don't use h:form for each of your commandLink, instead use one form for your dataTable. Second, the action will get executed only when it finds the component that triggered the aciton. If you use a request scoped list for your datatable then that list wont be there when the view is restored or may not match the original one which was used to create the view. You may have to change the managed bean from request scope to view scope or higher.

Third, as a suggestion, you can use h:outputLink or h:link instead of the commandLink and provide the f:param to simplify this, in which case you dont need the form also.

这篇关于h:commandLink不能在dataTable里面工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆