tags:

views:

165

answers:

2

I am trying to access the value of the expression $result.id and use that value and pass it in the bean action commitBtn. how do I go about doing this.

<c:forEach items="${bean.results}" var="result">
  <fieldset>
    <legend>
      <b>Title:</b>
      ${result.id}
      <c:set var="Id" value="${result.id}" />
      <!-- this Id doesn't show as well, why -->
      <h:outputText value="#{Id}" binding="#{bean.Id_lbl}" id="iD_lbl" />

      <h:commandButton value="Commit" binding="#{bean.commitBtn}"
        id="commitBtn" action="#{bean.commitBtn}" />
    </legend>
...
A: 

Use the <f:param> tag to pass the value to the action. Within the action you will have to get the param value from the requestMap

something like:

<h:commandButton blah blah blah>
   <f:param name="resultId" value="${result.id}" />
</h:commandButton>

then in action code:

resultId = FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("resultId");
digitaljoel
A: 

The f:param as some may suggest does not work in a h:commandButton in JSF 1.x. Use f:setPropertyActionListener instead:

<h:commandButton value="Commit" binding="#{bean.commitBtn}" id="commitBtn" action="#{bean.commitBtn}">
    <f:setPropertyActionListener target="#{bean.resultId}" value="#{result.id}" />
</h:commandButton>

Also see this article for more hints.

BalusC