Question : How to get selected row value from datatable in JSF ?

Hi,

How to get selected row value from datatable in jsf ? without  checkbox and radiobutton i have to find the row value.As well as if i found the particular value , those send to database and retrive into the backing bean.

Is this how to do in JSF ? Please give some tutorial or examples...

Answer : How to get selected row value from datatable in JSF ?


i think your are looking for this?


DAO
----

qury="select accountno,name,address,state from tablename";

ArrayList al = new ArrayList();
resultset rs = stmt.executeQuery(qury);

while(rs.next())
{
ManagedBean  bean = new ManagedBean();
bean.setAccountNo(rs.getString(1));
bean.setName(rs.getString(2));
bean.setAddress(rs.getString(3));
bean.setState(rs.getString(4));
al.add(bean);
}


jsf
****

iterate this arraylist in jsf

<h:dataTable value="#{managedBean.list}" var="loc">
                      <h:column>
                          <f:facet name="header" >
                    <h:commandLink action="#{managedBean.someAction}">
                              <h:outputText value="Account No"/>
                        <f:param name="AccountName" value="Account No"/>
                     </h:commandLink>
                          </f:facet>    
                          <h:outputText value="#{loc.AccountNo}"/>
                      </h:column>
                      <h:column>
                          <f:facet name="header" >
                              <h:outputText value="Name"/>
                          </f:facet>    
                          <h:outputText value="#{loc.Name}"/>
                      </h:column>
                      <h:column>
                          <f:facet name="header" >
                              <h:outputText value="Address"/>
                          </f:facet>    
                          <h:outputText value="#{loc.Address}"/>
                      </h:column>
                      <h:column>
                          <f:facet name="header" >
                              <h:outputText value="State"/>
                          </f:facet>    
                          <h:outputText value="#{loc.State}"/>
                      </h:column>
                                       
                  </h:dataTable>  


Backing bean code:
*******************
public String someAction() {

ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();

HttpServletRequest request = (HttpServletRequest) context.getRequest();

String parameterValue = request.getParameter("AccountName");

// Code here

return null

}
Random Solutions  
 
programming4us programming4us