0

there are news titles.and user click on these titles.browser goes to the page which shoes the news of this title.i want to get data from database where id equals to elements id which is clicked.element gets id from database so i don't know id in advance.

<ui:repeat value="#{controller.sql.yenilikler}" var="list">
  <a href="xeberShekil.xhtml" id="#{list.id}}">
    #{list.basliq}
  </a>
<br/>
</ui:repeat>

so i should

1.get the id of an element which is clicked

2.send this id into a variable in java class

3.send query which is get a data from database where id= the id of element

int id;
ResultSet rs= statement.executeQuery("select * from tableName where id="+id);

if an other algorithm propose please share.Tnx a lot

1 Answers1

0

Pass values to managed bean using f:param, f:setPropertyActionListner or pass value directly using commandbutton's action="#{bean.someAction(value)}"

See JSF-2 Action Parameter for code snippets.

Edit to Code

Data table

        <h:dataTable value="#{someManagedBean.categories}" var="cat">
                <h:column>
                        <h:commandButton action="#{someManagedBean.edit(cat.id)}"
                </h:column>

        </h:dataTable>  

Managed Bean

        public void edit(id) {
                doYourDBThing(id);

        } 

You can also use f:param and f:setPropertyActionListner. See the above link.

Community
  • 1
  • 1
Johny T Koshy
  • 3,857
  • 2
  • 23
  • 40