相关疑难解决方法(0)

了解PrimeFaces进程/更新和JSF f:ajax执行/呈现属性

究竟是什么process,并update在PrimeFaces p:commandXxx组件和executerenderf:ajax标签?

哪个在验证时有效?什么是update属性做,而不是更新的值从后端组件?不要process属性绑定值模型?究竟是什么@this,@parent,@all@form在这两个属性?

下面的例子工作正常,但我对基本概念有点困惑.

<p:commandButton process="@parent"
                 update="@form"
                 action="#{bean.submit}" 
                 value="Submit" />
Run Code Online (Sandbox Code Playgroud)

jsf process updates primefaces

181
推荐指数
4
解决办法
22万
查看次数

如何在ap:对话框中显示p:dataTable中当前行的详细信息,并在保存后更新

我有一个JSF 2应用程序,它有两个页面,一个用于列出学生,另一个用于显示给定学生的详细信息.列表页面包含指向学生表每行中详细信息页面的链接,该页面在浏览器中打开一个新选项卡,以便在单击时显示这些详细信息.

现在,需求已更改为在新选项卡中显示详细信息,但在列表页面中的模式对话框中.

我的想法是简单地将详细信息页面内容嵌入到模态对话框中,这样列表页面就不会太大而且难以维护.在这里开始我的怀疑.经过一番研究后,我将列表每行中的链接更改为以下按钮:

<p:commandButton value="Details" type="button"
                 onclick="PF('dialog-details').show()">
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)

该对话框声明如下:

<p:dialog widgetVar="dialog-details" header="Details" modal="true" width="95%">
    <ui:include src="student_details.xhtml">
        <ui:param name="id" value="#{student.id}"/>
    </ui:include>
</p:dialog>
Run Code Online (Sandbox Code Playgroud)

最后,详细信息页面更改为如下所示:

<ui:composition
    xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui" xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets">

    <f:metadata>
        <f:viewParam name="id" value="#{studentBean.id}" />
    </f:metadata>

    <h1 class="title ui-widget-header ui-corner-all">Details of #{studentBean.bean.name} / #{studentBean.bean.number}</h1>
</ui:composition>                       
Run Code Online (Sandbox Code Playgroud)

当我单击按钮时,对话框确实显示,内容是详细信息页面.我在对话框中看到以下内容:

Details of  / 
Run Code Online (Sandbox Code Playgroud)

根本没有错误,但应该显示的数据不是.设置了断点StudentBean.setId()(此方法加载以beanStudent传递的id对应的实例命名的属性),但它永远不会被命中.

经过一段时间的思考,我才明白为什么它不起作用.传递给详细信息页面的参数是student.id,但是在显示所有学生时student使用的名称,因此无效在其中.var<p:datatable/>student<p:dialog/><p:datatable/>

所以,我需要的是一种使用给定行中相应学生的id来显示对话框的方法.理想情况下,我想在这里进行ajax调用,因此细节只有在被绑定时才会加载.

有任何想法吗?

datatable jsf dialog master-detail primefaces

8
推荐指数
1
解决办法
1万
查看次数

为什么p:resetInput要求在提交表单后首先将托管bean的属性设置为null?

在视图范围内的托管bean中,我<p:resetInput>用来清除相应的manged bean中属性所持有的值,比如

<p:commandButton value="Reset" update="panel" process="@this">
    <p:resetInput target="panel" />
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)

这很好用.


我有一个提交按钮<p:commandButton>,按下该按钮会导致提交的值插入到数据库中,如果验证成功.

<p:remoteCommand name="updateTable" update="dataTable"/>

<p:panel id="panel" header="New">
    <p:outputLabel for="property1" value="property1"/>

    <p:inputText id="property1" value="#{bean.property1}" required="true">
        <f:validateLength minimum="2" maximum="100"/>
    </p:inputText>

    <p:message for="property1" showSummary="false"/>

    <p:commandButton id="btnSubmit"
                     update="panel messages"
                     oncomplete="if(!args.validationFailed) {updateTable();}"
                     actionListener="#{bean.insert}"
                     value="Save"/>

    <p:commandButton value="Reset" update="panel" process="@this">
        <p:resetInput target="panel" />
    </p:commandButton>
</p:panel>
Run Code Online (Sandbox Code Playgroud)

命令按钮调用insert()托管bean中的方法,该方法定义如下.

public void insert() {
    if (service.insert(property1)) {
        //...Popup a success message.
        reset(); //Invoke the following private method.
    } else {
        //...Show the cause of …
Run Code Online (Sandbox Code Playgroud)

jsf primefaces jsf-2

3
推荐指数
1
解决办法
5612
查看次数

标签 统计

jsf ×3

primefaces ×3

datatable ×1

dialog ×1

jsf-2 ×1

master-detail ×1

process ×1

updates ×1