开发者

Java server faces link doesn't work inside loop

I have this simple code in facelets "numbers.xhtml":

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:c="http://java.sun.com/jsp/jstl/core">
  <body>
    <h1>Numbers page</h1>
  <table>
    <c:forEach var="number" items="#{numbers}">
    <tr>
        <td>
          <h:form>
          <h:commandLink action="#{numbers开发者_JAVA百科.showNumber}" value="#{number.number}" />
          </h:form>
        </td>
    </tr>
    </c:forEach>
  </table>
</body>
</html>

In "showNumber" method I just return string "number" which is mapped in faces-config.xml to "number.xhtml" but it always opens "numbers.xhtml" page.

I even tried with "ui:repeat" tag but same results. If I put "h:commandLink" outside loop it works.

You have simple test case here. It is maven project and you need just to execute "./run_jetty.sh" to run simple jetty server.


Just saw the src you attached, I think you need a getter method: getShowNumber() in your Numbers class. You might want to rename public static String showNumber to public static String getShowNumber.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜