1

I have the following table

<f:view>
                <h:form>
                    <h1><h:outputText value="List"/></h1>
                    <h:dataTable value="#{groupBean.groups}" var="item" >
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Id"/>
                            </f:facet>
                            <h:button value="#{item.id}" />
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Name"/>
                            </f:facet>
                            <h:outputText value="#{item.name}"/>
                        </h:column>
                    </h:dataTable>
                </h:form>
            </f:view>

and I want to use this button

 <h:button value="#{item.id}" />

to know the selected item from the list

I want to get the item.name and add it to edit text in the same page , how can I do that ?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • The `h:button` will just go to a new URL (or reload the page), are you sure that is what you want. Anyway, with other types of input (like `h:commandButton`), the usual way is a nested `f:param` attribute. – SJuan76 May 30 '13 at 09:08
  • ok can you give me example – Mohammed Subhi Sheikh Quroush May 30 '13 at 09:12
  • What is the requirement of your code? Do you know that `` will generate a plain 'JavaScript GET-style' button used for navigational purposes. You seem to expect that some server-side action can be called, which is wrong. Also, there are many ways to achieve the latter functionality. – skuntsel May 30 '13 at 09:59
  • Please don't confuse JSP with JSF or Facelets. I removed the inappropriate JSP tag from the question. See also http://stackoverflow.com/questions/2095397/what-is-the-difference-between-jsf-servlet-and-jsp/2097732#2097732 – BalusC May 30 '13 at 12:58

2 Answers2

1

Just pass the item as request parameter.

<h:button value="#{item.id}">
    <f:param name="id" value="#{item.id}" />
</h:button>

You can set it in bean of target page via <f:viewParam>.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

You can do that in java script. Put an id attribute to the specific tag. and get the item.name

jsf code:

<h:outputText value="#{item.name}" id="ItemName"/>

js code:

  var name = document.getElementById("ItemName");
  var nameValue = name.value;

name will get a reference to the element. nameValue will get the value of the element.

lolo
  • 17,392
  • 9
  • 25
  • 49
  • 3
    You might be unfamiliar with JSF, so I wouldn't post the answer 'as is' in your place. To the very least, JSF prepends ids within a `` with the provided id, or the autogenerated id (this case). So for your code to work you need to search for an element whose id *ends with* the specified value. – skuntsel May 30 '13 at 09:53