Problem with bindings

UI Components for JSF
Post Reply
elbuild
Posts: 14
Joined: 23 Jun 2010, 11:04

23 Jun 2010, 12:06

hi,
I tried to use the binding attribute to bind a component in the page to an object in a backing bean but, if I do so, when I refresh the page the component just disappears: the content is displayed but no style or position is applied.
It happens with p:dialog and p:panel.
I just used the binding as I always do in JSF: do I need to do something extra to use this feature with primefaces?

here is my code:

in the page:

Code: Select all

  <p:panel binding="#{Bean.panel}" id="panel" >fasgasg</p:panel>
in the backing bean:

Code: Select all

import org.primefaces.component.panel.Panel;


/**
 *
 * @author eve
 */
public class Bean {


    private Panel panel;
    
    public Bean(){
        
    }
     

   
    /**
     * @return the panel
     */
    public Panel getPanel() {
        return panel;
    }

    /**
     * @param panel the panel to set
     */
    public void setPanel(Panel panel) {
        this.panel = panel;
    }

   
}
thanks
Eve
JSF 1.2 - PrimeFaces 1.0.2
--------------------------------
ELbuild - http://www.elbuild.it

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

23 Jun 2010, 14:05

Hello,

I did it with some components (at last with Dashboard) and it always worked. How do you instantiate your Panel? It should be something like (dashboard + panels in request scoped bean):

Code: Select all

	private Dashboard dashboard;

	//~ Methods ----------------------------------------------------------------

	/**
	 * Gets dashboad.
	 *
	 * @return Dashboard the dashboard
	 */
	public Dashboard getDashboard()
	{
		// This will be called once in the first RESTORE VIEW phase
		if (dashboard == null) {
			FacesContext fc = FacesContext.getCurrentInstance();
			Application application = fc.getApplication();
			dashboard =
			    (Dashboard) application.createComponent(fc, "org.primefaces.component.Dashboard",
			                                            "org.primefaces.component.DashboardRenderer");
			dashboard.setId("dashboardChoice");

			DashboardModel model = new DefaultDashboardModel();
			DashboardColumn column = new DefaultDashboardColumn();
			model.addColumn(column);
			dashboard.setModel(model);
		}

		return dashboard;
	}

	/**
	 * Sets dashboard.
	 *
	 * @param dashboard the dashboard to set
	 */
	public void setDashboard(Dashboard dashboard)
	{
		this.dashboard = dashboard;
	}

	/**
	 * Builds dashboad for choice reordering per drag & drop.
	 *
	 * @param parent   parent tree node of the node to be moved
	 * @param treeNode tree node to be moved
	 */
	public void buildDashboard(final TreeNode parent, final TreeNode treeNode)
	{
		List<TreeNode> kids = parent.getChildren();
		if (kids != null && !kids.isEmpty()) {
			FacesContext fc = FacesContext.getCurrentInstance();
			Application application = fc.getApplication();

			String uuid = ChoiceListUtils.getUuid(treeNode);
			DashboardColumn column = dashboard.getModel().getColumn(0);

			for (int i = 0; i < kids.size(); i++) {
				TreeNode kid = kids.get(i);

				// create a new panel
				Panel panel =
				    (Panel) application.createComponent(fc, "org.primefaces.component.Panel",
				                                        "org.primefaces.component.PanelRenderer");
				panel.setId("moveChoice" + i);
				panel.setFooter(((ChoiceTreeNode) kid.getData()).getDisplayName());

				// add panel to the dashboard
				dashboard.getChildren().add(panel);

				// add widget to the column
				column.addWidget(panel.getId());

				if (ChoiceListUtils.getUuid(kid).equals(uuid)) {
					Map<String, Object> attributes = panel.getAttributes();
					attributes.put("style", "border: solid 1px red;");
				}
			}
		}
	}
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

elbuild
Posts: 14
Joined: 23 Jun 2010, 11:04

24 Jun 2010, 10:59

Yes I finally understood where the problem was: it looks like the binding only works with request scoped beans, I don't really know why. I was trying with a session scoped bean.
Thanks, anyway :)

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

25 Jun 2010, 19:00

Yes, session scope and component bindings is not a good practice, for more information;

http://myfaces.apache.org/orchestra/myf ... dings.html

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 58 guests