2

jsf 1.2, jboss 4.2.3 and richfaces 3.3.3

I'm trying to send the index of a as a , but it keeps returning null:

<ui:repeat id="al11" var="albumslistvalue1" value="#{AlbumDetailBean.getAlbumImagesList()}" varStatus="listimages">
  <h:form>
    <h:commandLink value="proxima" id="next" action="#{AlbumDetailBean.escreveparam()}">
      <f:param name="fotoid" value="#{listimages}" />
    </h:commandLink>
  </h:form>
</ui:repeat>

the escreveparam() method only writes the param:

public void escreveparam(){
    String fotoid = ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter("fotoid");
    System.out.println("Teste:" + fotoid);
}

Why is it always null?

  • I tried to use a static value on f:param and it worked: i don't get it, i'm using the #{listimages} on another components id so they are dynamic –  Aug 14 '12 at 13:00

1 Answers1

1

You're using JSF 1.x which thus implies that you're using Facelets 1.x (as in jsf-facelets.jar file). The <ui:repeat> tag has in Facelets 1.x no varStatus attribute. It was been introduced in Facelets 2.0.

You need to look for alternate means. E.g. <c:forEach>

<c:forEach value="#{bean.albums}" var="album" varStatus="loop">
  <h:form>
    <h:commandLink id="next" value="proxima" action="#{bean.next}">
      <f:param name="id" value="#{loop.index}" />
    </h:commandLink>
  </h:form>
</c:forEach>

(please note that your initial usage of varStatus object was completely wrong, it does not give you the raw index back, but a complete object holding all iteration status details, with among others a getIndex() method, you should actually have used #{listimages.index} or something instead --provided that you were using Facelets 2.x)

or just the ID of the iterated Album object itself

<ui:repeat value="#{bean.albums}" var="album">
  <h:form>
    <h:commandLink id="next" value="proxima" action="#{bean.next}">
      <f:param name="id" value="#{album.id}" />
    </h:commandLink>
  </h:form>
</ui:repeat>

either way, just use <managed-property> in faces-config.xml with a value of #{param.id} or the ExternalContext#getRequestParameterMap() to retrieve it:

public void next() {
    String id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id");
    // ...
}

By the way, since your environment seems to support JBoss EL (as indicated by using full method names with parentheses in EL), you could also just pass the whole Album as the action method argument

<ui:repeat value="#{bean.albums}" var="album">
  <h:form>
    <h:commandLink id="next" value="proxima" action="#{bean.next(album)}" />
  </h:form>
</ui:repeat>

with

public void next(Album album) {
    // ...
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks, i'm going to use the id of the iterated Album object, but what i still don't understand is why eclipse and jboss recognize varStatus even using jsf 1.x and facelets 1.x also, is it possible to use facelets 2.x with jsf 1.2 ? –  Aug 14 '12 at 14:13
  • You're welcome. No, Facelets 2 is bundled with JSF 2 and cannot be used independently with JSF 1.x. – BalusC Aug 14 '12 at 14:18