PrimeFaces视图与动态添加组件

时间:2017-07-28 11:53:34

标签: jsf primefaces uicomponents

我需要PrimeFaces中非常动态的视图。 View必须构建到运行时并添加PrimeFaces组件。

在我的视图中,我有一个panelgrid并添加了来自支持Bean的Elements。我的问题是没有调用setter。我添加了一个ValueExpression并调用了getter,但从未调用过setter。

我的观点

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title></title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
        <link href="#{request.contextPath}/resources/css/primefaces-9/theme.css" rel="stylesheet" type="text/css"/>
        <link href="#{request.contextPath}/resources/css/p_css.css" rel="stylesheet" type="text/css"/>
    </h:head>
    <h:body style="font-family: Arial; font-size: 8pt;">
        <h:form id="buttonForm">

            <p:calendar id="test" value="#{editor.dt_vrAufnahmeDatum}" mindate="#{editor.str_currentDate}" navigator="true" locale="de" pattern="dd.MM.yyyy" />
            <p:selectOneMenu id="selTest" />
            <p:commandButton id="reloadPanelGrid" action="#{editor.setUiComponents()}" value="new" />                
        </h:form>

        <h:form id="dynaForm">

            <p:panelGrid id="tiles" columns="1" >
                <h:outputText value="hallo" />
                <p:commandButton value="Submit" actionListener="#{editor.storeDataVr()}" process="dynaForm"/>
            </p:panelGrid>

        </h:form>
    </h:body>
</html>

我的Backing Bean

package com._9.controller.global;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.el.ValueExpression;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UISelectItem;
import javax.faces.component.html.HtmlPanelGroup;
import javax.faces.context.FacesContext;
import org.primefaces.component.panelgrid.PanelGrid;
import org.primefaces.context.RequestContext;
import org.primefaces.event.SelectEvent;

@ManagedBean(name = "editor")
@ViewScoped
public class Editor implements Serializable
{

    private static final long serialVersionUID = -33430593454354523L;

    private String str_Text = "";


    @PostConstruct
    public void init()
    {

    }


    public String getStr_Text()
    {
        return this.str_Text;
    }

    public void setStr_Text(String str_Text)
    {
        this.str_Text = str_Text;
    }

    public void setUiComponents()
    {
        org.primefaces.component.inputtext.InputText inpt_obj = new org.primefaces.component.inputtext.InputText();
        inpt_obj.setValueExpression("value", createValueExpression("#{editor.str_text}", String.class));

        HtmlPanelGroup tile = new HtmlPanelGroup();
        tile.setId("testPanelGroup");

        tile.getChildren().add(0, inpt_obj);


        PanelGrid tiles;

        tiles = (PanelGrid) FindComponent.doFind(FacesContext.getCurrentInstance(), "dynaForm:tiles");

        tiles.getChildren().add(2, tile);


        RequestContext.getCurrentInstance().update("dynaForm:tiles");
    }

    public ValueExpression createValueExpression(String valueExpression, Class<?> valueType)
    {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        return facesContext.getApplication().getExpressionFactory().createValueExpression(facesContext.getELContext(), valueExpression, valueType);
    }

    public void StoreDataVr()
    {
        int i = 0;
    }
}

我的setValueExpression中是否存在导致setter不起作用的问题?

1 个答案:

答案 0 :(得分:0)

在方法setUiComponents()中,您正在创建值表达式&#34;#{editor.str_text}&#34;但是你的吸气者和背叛者用一个大写的“T&#39;”来命名。单击第一个commandButton时,您可能会在应用程序日志中看到PropertyNotFoundException,表明它无法创建值表达式。