-1

I need a very dynamic View in PrimeFaces. The View must build to runtime and add PrimeFaces components.

In my View I had a panelgrid and added Elements from backing Bean. My Problem is that no setter is called. I added a ValueExpression and the getter is called, but never the setter.

my View

<?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>

my 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;
    }
}

Is there any problem in my setValueExpression that causes setter to not work?

Nissa
  • 4,636
  • 8
  • 29
  • 37
Andreas
  • 31
  • 4

1 Answers1

0

In your method setUiComponents() you are creating the value expression "#{editor.str_text}" with a lower-case 't', however your getters and setters are named with a capital 'T'. You may see a PropertyNotFoundException in the application logs when you click the first commandButton, indicating it was not able to create the value expression.

kingdc
  • 135
  • 8