Update composite component with remoteCommand

UI Components for JSF
Post Reply
leolux
Posts: 12
Joined: 06 Nov 2011, 13:23
Location: Germany

21 Jun 2014, 20:28

I have a problem to find the correct value for the "update" attribute of the remoteCommand. Using the code

Code: Select all

<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.org/ui"
	xmlns:pm="http://primefaces.org/mobile"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:qs="http://java.sun.com/jsf/composite/components">

<ui:composition template="templates/userTemplate.xhtml">
	<ui:define name="content">
		<div style="height: 90%">
			<h:form>
				<p:remoteCommand name="newsignal" update="square" process="@this" async="true"
					actionListener="#{signalView.newsignal}" />
				<h:outputText id="count"
					value="#{signalView.count}" />
			</h:form>	
				
                         <qs:square id="square"></qs:square>			
		</div>
	</ui:define>
</ui:composition>
</html>
I get the following error:
Cannot find component with expression "square" referenced from "page:j_idt14:j_idt15".
How to reference the component "square" in the update attribute of remoteCommand?
Primefaces 5
Glassfish 4.0.1
Hibernate Bean Validator 4.2.0 Final
Eclipse Kepler

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

22 Jun 2014, 14:17

Not primefaces mobile related, not even primefaces related... most likely you need to use ":square"

leolux
Posts: 12
Joined: 06 Nov 2011, 13:23
Location: Germany

23 Jun 2014, 21:18

":square" does not work either. It seems to be a general problem with my code...
However herer is the full code containing the view, one bean and the composite component to be updated by p:remoteCommand:

index.xhtml

Code: Select all

<!DOCTYPE html>
<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.org/ui"
	xmlns:pm="http://primefaces.org/mobile"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:qs="http://java.sun.com/jsf/composite/components">

<pm:page id="page">
	<pm:content>
		<h:form>
			<p:remoteCommand name="newsignal" update=":square" process="@this"
				async="true" actionListener="#{signalView.newsignal}" />
			<h:button onclick="newsignal(); return;" value="New Signal..."></h:button>
		</h:form>

		<qs:square id="square"></qs:square>
	</pm:content>
</pm:page>
</html>
SignalView.java

Code: Select all

@ManagedBean
@ViewScoped
public class SignalView implements Serializable {

	public void newsignal() {
		System.out.println("Add new signal");
	}

}
resources/components/square.xhtml

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:cc="http://java.sun.com/jsf/composite">

<cc:interface>
</cc:interface>


<cc:implementation>
	<div id="#{cc.clientId}">
		<h:outputText value="This might be a square" />
	</div>
</cc:implementation>
</html>
Should this code work this way?
Primefaces 5
Glassfish 4.0.1
Hibernate Bean Validator 4.2.0 Final
Eclipse Kepler


leolux
Posts: 12
Joined: 06 Nov 2011, 13:23
Location: Germany

29 Jun 2014, 12:56

The code posted above is reduced to minimum set of lines in order to reproduce the problem. So if you put all code together you have an working example including the problem that SF still cannot find the component named ":squre".

I will try to figure out if the problem is related to the mobile renderer. Maybe there is some magic going on having multiple content containers, although I use only one of them.

Does this example code work for anyone?
Primefaces 5
Glassfish 4.0.1
Hibernate Bean Validator 4.2.0 Final
Eclipse Kepler

leolux
Posts: 12
Joined: 06 Nov 2011, 13:23
Location: Germany

09 Jul 2014, 12:45

The problem must have something to do with the mobile renderer. If I run a simple view without the mobile renderer everything works fine:

Code: Select all

<!DOCTYPE html>
<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.org/ui"
	xmlns:pm="http://primefaces.org/mobile"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:qs="http://java.sun.com/jsf/composite/components">

<h:head>
</h:head>

<h:body>
	<p:growl id="growl" autoUpdate="true" globalOnly="true"
		showDetail="true" sticky="false" widgetVar="growl" />

	<h:form>
		<p:remoteCommand name="newsignal" update=":square" process="@this"
			async="true" actionListener="#{signalView.newsignal}" />
		<h:button onclick="newsignal(); return;" value="New Signal..."></h:button>
	</h:form>

	<qs:square id="square"></qs:square>

	<p:messages id="messages" redisplay="false"></p:messages>
</h:body>
</html>
But if the same view gets rendered by the mobile renderer, then the remoteCommand cannot find the composite component ":square":

Code: Select all

<!DOCTYPE html>
<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.org/ui"
	xmlns:pm="http://primefaces.org/mobile"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:qs="http://java.sun.com/jsf/composite/components">

<f:view renderKitId="PRIMEFACES_MOBILE" />

<h:head>
</h:head>

<h:body>
	<pm:page id="page">
		<pm:content>
			<p:growl id="growl" autoUpdate="true" globalOnly="true"
				showDetail="true" sticky="false" widgetVar="growl" />

			<h:form>
				<p:remoteCommand name="newsignal" update=":square" process="@this"
					async="true" actionListener="#{signalView.newsignal}" />
				<h:button onclick="newsignal(); return;" value="New Signal..."></h:button>
			</h:form>

			<qs:square id="square"></qs:square>

			<p:messages id="messages" redisplay="false"></p:messages>
		</pm:content>
	</pm:page>
</h:body>
</html>
It seems to be that the content container id within a mobile page cannot be set to a static value. So how could I specify the update command to update a composite component within the same content container as the remoteCommand resides in?
Primefaces 5
Glassfish 4.0.1
Hibernate Bean Validator 4.2.0 Final
Eclipse Kepler

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

11 Jul 2014, 10:53

have you checked what the REAL id is of the component in the jsf component tree and/or the generated xhtml? Might just be that the id of the page is prepended to it

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 29 guests