composite attributes returns null in jsf custom components
Asked Answered
M

2

0

I am implementing my custom component like below. Placed this file web-> resource folder

<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:composite="http://java.sun.com/jsf/composite"
      >
    <h:body>
        <composite:interface>
            <composite:attribute name="width" default="300"/>
            <composite:attribute name="height" default="400"/>
        </composite:interface>
        <composite:implementation>
            <h:inputText style="height: #{composite.attrs.height}px"></h:inputText>
            <span> #{composite.attrs.height}</span>
        </composite:implementation>
    </h:body>
</html>

but attrs.height return nothing.

Custom component is used like below

<my:mycustom  height="40"></my:mycustom>

What i have done mistakes here. Anyone please help me to do this.

Milan answered 9/6, 2017 at 9:58 Comment(0)
M
0

I have found the issue, used the namespaces as composite to get the attribute(#{composite.attrs.height}) But this is not correct it seems and used cc instead of composite and its returns correctly.

{cc.attrs.height}

Milan answered 11/6, 2017 at 13:38 Comment(0)
E
0

Little bit late I know but, I wanted to answer your question, because there's no valid answers here yet..

Even, you've found the null value reason, take this as answer an advice please..

What you've found: {cc.attrs.height} is right, you must reach the attributes via "cc" it does not change regarding the namespace, take it as a quick access keyword like "session", "request", etc.

Let me move on to my suggestion..

Your component definition has html and body tags. Which are generally not for component definitions. Because a component is a part of a page, it can be defined and used as below..

NOTE: You've put your file at the right place but I suggest making a folder "components" let's say in the resources folder. Then, it'll be available at any page via below namespace definition:

xmlns:components="http://java.sun.com/jsf/composite/components"

myFirstComponent.xhtml

<ui:component xmlns=""
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:composite="http://java.sun.com/jsf/composite" 
              xmlns:p="http://primefaces.org/ui"
              xmlns:f="http://java.sun.com/jsf/core">

    <composite:interface>
        <!-- Your attributes goes here -->
        <composite:attribute name="sampleAttributeName" default="@form"/>
    </composite:interface>

    <composite:implementation>
        <!-- Your implementation goes here -->
    </composite:implementation>
</ui:component>
Entwine answered 12/6, 2018 at 22:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.