p:focus for="#{null}"

UI Components for JSF
Post Reply
scar
Posts: 15
Joined: 28 Apr 2011, 16:06

20 Feb 2012, 12:07

hi,

i've got a problem with p:focus tag. i want to use it in a composite component and expose the "for" attribute as an attribute of the composite component.

Code: Select all

	<cc:interface>
		<cc:attribute name="focus"			required="false"	/>
	</cc:interface>
	<cc:implementation>
		<p:focus context="#{cc.id}" for="#{cc.attrs.focus}" />
		<p:panelGrid>
			....
		</p:panelGrid>
	</cc:implementation>
this code will work as long as you specify the focus attribute. if i do not set it manually or if i use a expression which resolves to null thre will be an IllegalArgumentException: ""

Code: Select all

java.lang.IllegalArgumentException: ""
	javax.faces.component.UIComponentBase.findComponent(UIComponentBase.java:570)
	org.primefaces.component.focus.FocusRenderer.encodeExplicitFocus(FocusRenderer.java:66)
	org.primefaces.component.focus.FocusRenderer.encodeEnd(FocusRenderer.java:56)
	javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
	com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
	com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
	javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
	javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
	com.sun.faces.renderkit.html_basic.CompositeRenderer.encodeChildren(CompositeRenderer.java:78)
	javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
	javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
	javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
	javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
	com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
	com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:309)
	com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:309)
	com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
	javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
	javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
	com.sun.faces.renderkit.html_basic.CompositeRenderer.encodeChildren(CompositeRenderer.java:78)
	javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
	javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
	javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
am i doing something evil or is it a bug?

thanks and best regards
JBoss AS 7.1.3.Final / Mojarra 2.1.11-jbossorg-3 20120815-1456 / PrimeFaces 3.5

User avatar
T.dot
Expert Member
Posts: 620
Joined: 01 Feb 2012, 15:39
Location: Vienna/Austria

20 Feb 2012, 13:16

Looks like the "for" parameter is set to an empty string. The FocusRenderer just checks if its null so you get this IllegalArgumentException when findind a component with id "".

Try changing your focus to this:
<p:focus context="#{cc.id}" for="#{empty cc.attrs.focus ? null : cc.attrs.focus}" />

scar
Posts: 15
Joined: 28 Apr 2011, 16:06

24 Feb 2012, 16:38

T.dot wrote:Looks like the "for" parameter is set to an empty string. The FocusRenderer just checks if its null so you get this IllegalArgumentException when findind a component with id "".

Try changing your focus to this:
<p:focus context="#{cc.id}" for="#{empty cc.attrs.focus ? null : cc.attrs.focus}" />
hi!

yes, that's the problem. i also tried for="#{null}" and it resolves to an empty string! is this a bug in the expression language??
has anyone an idea how to solve this problem?
i don't want to use two different p:focus components with rendered-attributes...

best regards
JBoss AS 7.1.3.Final / Mojarra 2.1.11-jbossorg-3 20120815-1456 / PrimeFaces 3.5

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

24 Feb 2012, 16:41

there was a possible solution given above. Did you explicitly try that one?

scar
Posts: 15
Joined: 28 Apr 2011, 16:06

27 Feb 2012, 16:30

kukeltje wrote:there was a possible solution given above. Did you explicitly try that one?
yes, i tried this one too.
in the meanwhile i found out, that i can use <c:if test="#{not empty xx"> and <f:attribute name="for" value="xxx" /> for my problem :(
there are many of these attributes, where expressions aren't possible
<p:column selectionMode="#{cc.attrs.selectionMode}" > is another one...

best regards
JBoss AS 7.1.3.Final / Mojarra 2.1.11-jbossorg-3 20120815-1456 / PrimeFaces 3.5

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 39 guests