logo
down
shadow

How do I pass an attribute from composite component to backing bean by using backing component?


How do I pass an attribute from composite component to backing bean by using backing component?

By : user2953304
Date : November 20 2020, 01:01 AM
like below fixes the issue Based on your comments this is what you expect.
Note that even if this implementation works, it is conceptually incorrect!
code :
<cc:interface componentType="rangeComponent">
    <cc:attribute name="from" />
    <cc:attribute name="to" />
    <cc:clientBehavior name="rangeSelected" event="dateSelect" targets="from to"/>
</cc:interface>

<cc:implementation>

    <div id="#{cc.clientId}">
        <p:calendar id="from" value="#{cc.attrs.from}"/>
        <p:calendar id="to" value="#{cc.attrs.to}"/>
    </div>

</cc:implementation>
<h:form>
    <e:inputRange from="#{rangeBean.from}" to="#{rangeBean.to}" text="#{rangeBean.text}">
        <p:ajax event="rangeSelected" process="@namingcontainer" update="@form:output" listener="#{rangeBean.onChange}" />
    </e:inputRange>

    <h:panelGrid id="output" columns="1">
        <h:outputText value="#{rangeBean.from}"/>
        <h:outputText value="#{rangeBean.to}"/>
        <h:outputText value="#{rangeBean.text}"/>
    </h:panelGrid>
</h:form>
@FacesComponent("rangeComponent")
public class RangeComponent extends UINamingContainer
{
    @Override
    public void processUpdates(FacesContext context)
    {
        Objects.requireNonNull(context);

        if(!isRendered())
        {
            return;
        }

        super.processUpdates(context);

        try
        {
            Date from = (Date) getValueExpression("from").getValue(context.getELContext());
            Date to = (Date) getValueExpression("to").getValue(context.getELContext());

            ValueExpression ve = getValueExpression("text");
            if(ve != null)
            {
                ve.setValue(context.getELContext(), from + " - " + to);
            }
        }
        catch(RuntimeException e)
        {
            context.renderResponse();
            throw e;
        }
    }
}
@ManagedBean
@ViewScoped
public class RangeBean implements Serializable
{
    private static final long serialVersionUID = 1L;

    private Date from = new Date(1000000000);
    private Date to = new Date(2000000000);
    private String text = "range not set";

    public void onChange(SelectEvent event)
    {
        Messages.addGlobalInfo("[{0}] changed: [{1}]", event.getComponent().getId(), event.getObject());
    }

    // getters/setters
}


Share : facebook icon twitter icon
JSF composite component with backing bean

JSF composite component with backing bean


By : diamo
Date : March 29 2020, 07:55 AM
hope this fix your issue I now see my mistake. The problem was that the composite component has to be called with a Date object, i.e. . As the code stands the date needs to be instantiated, but it wasn't. The more robust way of doing this is to do a new Date() in encodeBegin() in the event that getValue() is null. This then works the same a h:inputText/f:convertDateTime which does not require that the value is instantiated.
Composite component backing bean location

Composite component backing bean location


By : user3619136
Date : March 29 2020, 07:55 AM
I hope this helps . You need the componentType attribute of to explicitly specify the backing component.
code :
<cc:interface componentType="component1">
package components.page1;

@FacesComponent("component1")
public class Component1 extends UINamingContainer {
    // ...
}
JSF composite component backing bean EL expression as default of required attribute failing, methods not known

JSF composite component backing bean EL expression as default of required attribute failing, methods not known


By : JeffO
Date : March 29 2020, 07:55 AM
wish help you to fix your issue According to the documentation for the tag cc:attribute, the value for default must evaluate to a java.lang.String.
That's why the #{blockManager} expression is not working as you are expecting, you only can set defaults for String attributes.
code :
public static String typeOf(Object o) {
    return o == null ? null : o.getClass().toString();
}
<ui:composition>
    <cc:interface>
        <cc:attribute name="param" type="java.lang.Integer" required="true"
            default="1" />
    </cc:interface>
    <cc:implementation>
        <h:outputText value="#{fnc:typeOf(cc.attrs.param)}" />
    </cc:implementation>
</ui:composition>
<my:comp />
<my:comp param="1" />
How to return value from backing bean as composite component attribute

How to return value from backing bean as composite component attribute


By : BTestQ
Date : March 29 2020, 07:55 AM
around this issue You need a component to submit the 'output' value to the backing bean. Use inputHidden to accomplish this:
code :
<composite:interface componentType="myComp">
  <composite:attribute name="input" type="java.lang.Integer" />
  <composite:attribute name="output" type="java.lang.Integer" />
  <composite:attribute name="action" method-signature="java.lang.String action()"/>
</composite:interface>
<composite:implementation>
  <h:inputText id="input" value="#{cc.attrs.input}" />
  <h:inputHidden id="output" value="#{cc.attrs.output}" />
</composite:implementation>
How to find an component ID including the composite component ID from backing bean

How to find an component ID including the composite component ID from backing bean


By : user3908803
Date : March 29 2020, 07:55 AM
hope this fix your issue "j_idt123" is a generated id for components which do not specify their own. Just give the parent-container of "tableForm" an id.
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org