wez*_*lee 6 jsf dynamic primefaces
我正在研究一个学校项目,遇到动态ui插入问题.我目前在JSF2.0/Primefaces 3 M1工作.主要的问题是我想要一个带有动态内容的Primefaces对话框,它通过菜单栏进行更改.
该对话框组件包含一个ui:include标记,其中src设置为托管bean属性.菜单项链接到更改此属性的bean方法.
主要问题是变量根本没有变化,我目前正在使用警报来显示这个变量.目前正在使用remoteCommand,但我已经在menuitem组件中尝试了action/actionlistener.任何帮助,将不胜感激.
这是菜单栏和对话框的主页面.
<?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:p="http://primefaces.prime.com.tr/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>KunstInHuis: Main</title>
</h:head>
<h:body style="font-size: 12px;">
<h:form id="mainForm">
<f:metadata>
<f:event type="preRenderView" listener="#{login.verifyAccess}"/>
</f:metadata>
<p:remoteCommand name="lazyANew" actionListener="#{main.goToAboNew}" onsuccess="alert('test')"/>
<p:remoteCommand name="lazyAList" actionListener="#{main.goToAboList}" onsuccess="alert('test')" />
<p:remoteCommand name="lazyASearch" actionListener="#{main.goToAboSearch}" onsuccess="alert('test')" />
<p:menubar autoSubmenuDisplay="true">
<p:submenu label="Abonnementen">
<p:menuitem value="Nieuw" onclick="lazyANew()" onsuccess="alert('#{main.goToPage}')"/>
<p:menuitem value="Lijst" onclick="lazyAList()" onsuccess="alert('#{main.goToPage}')" />
<p:menuitem value="Zoek" onclick="lazyASearch()" onsuccess="alert('#{main.goToPage}')"/>
</p:submenu>
<p:submenu label="Klanten">
<p:menuitem value="Nieuw" url="#" />
<p:menuitem value="Lijst" url="#"/>
</p:submenu>
<p:submenu label="Kunstwerken">
<p:menuitem value="Nieuw" url="#" />
<p:menuitem value="Lijst" url="#"/>
</p:submenu>
</p:menubar>
</h:form>
<p:dialog id="mainDialog" header="Abonnement aanmaken" widgetVar="dlg0" minHeight="300" minWidth="450"
resizable="true" modal="false" >
<ui:include src="#{main.goToPage}" />
</p:dialog>
</h:body>
Run Code Online (Sandbox Code Playgroud)
这是我的支持豆.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.page.beans;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
/**
*
* @author wezlee
*/
@ManagedBean(name = "main")
@ViewScoped
public class mainMenuBean implements Serializable {
private boolean panelRender=false;
private String goToPage = "./includes/forms/abboCreate.xhtml";
/** Creates a new instance of mainMenuBean */
public mainMenuBean() {
}
public void goToAboNew(ActionEvent e){
goToPage="./includes/forms/abboCreate.xhtml";
}
public void goToAboNew(){
goToPage="./includes/forms/abboCreate.xhtml";
}
public void goToAboList(ActionEvent e){
goToPage="./includes/forms/abboList.xhtml";
}
public void goToAboList(){
goToPage="./includes/forms/abboList.xhtml";
}
public void goToAboSearch(ActionEvent e){
goToPage="./includes/forms/abboSearch.xhtml";
}
public void goToAboSearch(){
goToPage="./includes/forms/abboSearch.xhtml";
}
/**
* @return the goToPage
*/
public String getGoToPage() {
return goToPage;
}
public void setGoToPage(String src){
this.goToPage=src;
}
}
Run Code Online (Sandbox Code Playgroud)
实际上,我认为更新支持值的方法看起来效果很好。问题可能在于您试图如何显示它。最初呈现页面时,将评估 goToPage 的值并将其放入返回到用户浏览器的页面内容中。一旦在用户端设置了该值,它就不会与支持 bean 重新同步,直到重新呈现页面的该部分。
我相信 prime faces RemoteCommand 允许您使用 update="client side id" 通过 AJAX 来执行此操作。不过,我不是一个主要面孔的人,所以我做了这个小测试。首先更改您的远程命令:
<p:remoteCommand name="lazyANew" actionListener="#{main.goToAboNew}" update="testOutput" />
<p:remoteCommand name="lazyAList" actionListener="#{main.goToAboList}" update="testOutput" />
<p:remoteCommand name="lazyASearch" actionListener="#{main.goToAboSearch}" update="testOutput" />
Run Code Online (Sandbox Code Playgroud)
然后使用适当的 ID 添加一个简单的文本字段到您的页面内容:
Page target: <h:outputText value="#{main.goToPage}" id="testOutput" />
Run Code Online (Sandbox Code Playgroud)
您的输出文本应该开始同步。只要有效,您只需将更新目标从 testOutput 重新定位到 mainDialog 即可开始工作。