【问题标题】:How to make RESTFUL navigation in JSF 2 ?如何在 JSF 2 中进行 RESTFUL 导航?
【发布时间】:2013-07-04 18:20:04
【问题描述】:

我有一张表格,其中列出了一些演员。这个页面是 actor.xhtml。这是相关的部分:

<p:dataTable id="allActors" var="actor" value="#{actorTableBackingBean.allActors}">
                <p:column headerText="Actor Name" sortBy="#{actor.firstName}">
                    <h:outputText value="#{actor.firstName}"/>
                </p:column>

                <p:column headerText="Actor Detail">
                    <h:link value="Go to actor detail" outcome="actorDetail?actorId=#{actor.actorId}" />
                </p:column>

            </p:dataTable>

所以当我点击表格中的 Go To Actor Detail 链接时,我成功导航到:actorDetail.xhtml?actorId=1

这里是actorDetail.xhtml:

<ui:composition template="../maintemp.xhtml">
    <f:metadata>
        <f:viewParam name="actorId" value="#{actorDetailBackingBean.actorId}" />
    </f:metadata>

    <ui:define name="mainarea">

        <div class="well" style="padding: 15px" >
            <h3>Actor Detail</h3>
        </div>
        #{actorDetailBackingBean.actorWith().firstName}
    </ui:define>
</ui:composition>

这是我的 ActorDetailBackingBean.java :

@Named
@RequestScoped
public class ActorDetailBackingBean extends BasePage {

    @Inject
    ActorDao actorDao;

    @Inject
    Actor actor;

    private int actorId;

    public int getActorId() {
        return actorId;
    }

    public void setActorId(int actorId) {
        this.actorId = actorId;
    }

    public Actor actorWith(){
        actor = actorDao.getWithId(actorId);
        return actor;
    }
}

但这会返回零数据。所以细节没有加载。 actorDao.getWithId 使用参数 0 调用。

我错过了什么?

还有一个额外的问题:

如何使用 POST 请求执行此操作?

【问题讨论】:

    标签: jsf


    【解决方案1】:

    我会回答我自己的问题。

    将字符串传递给 bean,而不是 int。现在它起作用了!

    【讨论】:

    • @LaabidiRaissi 你能详细点吗?
    • 从您的问题标题来看,我认为您希望 actorId 出现在 URL 中。然后,您询问如何以 POST 方式制作它。我说的对吗?
    • @LaabidiRaissi 不,第二种方式我不希望它出现在 URL 中。我想要(我猜)一个 h:commandLink 但我无法让它工作..
    • 这是我尝试过的,但它不起作用:
    • 当然可以,因为您的 View/Request 范围的 bean 将被重新创建。
    猜你喜欢
    • 2011-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-20
    • 1970-01-01
    • 2011-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多