How to set JSF composite component attribute for ManagedBean property?

So, I created the component FileAdder.xhtml

<composite:interface>
    <composite:attribute name="type" value="#{editoriCompositeController.typeString}"/>
</composite:interface>

<composite:implementation>
    <h:form>
        <p:editor id="editor" widgetVar="editorWidget" value="some text" width="600" />
    </h:form>
</composite:implementation>

And then I have EditoriCompositeController ManagedBean:

@ViewScoped
@ManagedBean
public class EditoriCompositeController {

    String typeString;

    public void setTypeString(String typeStringParameter) {
        this.typeString = typeStringParameter;
    }

    public String getTypeString() {
        return typeString;
    }

}

And then in fileattachmentsview.xhtml I use the component:

    <owncomponents:fileadder type="MEMO" />

But this does not indicate the value of typeString in the bean base as "MEMO". It remains equal to zero. I tested it with a button that displays a value.

How to backup bean get value for typeStringI installed the type-attribute composite component as "memo"? Why is this nulland not "MEMO"?

+4
source share
2

bean/model . <c:set>, .

<cc:interface>
    <cc:attribute name="bean" type="com.example.Bean" />
    <cc:attribute name="type" type="java.lang.String" />
</cc:interface>
<cc:implementation>
    <c:set target="#{cc.attrs.bean}" property="type" value="#{cc.attrs.type}" />
    <p:editor value="#{cc.attrs.bean.text}" />
</cc:implementation>    

:

public class Bean {

    private String text;
    private String type; // I suggest to make it an enum.

    // ...
}

<h:form>
    <your:composite bean="#{bean}" type="MEMO" />
    <p:commandButton action="#{bean.submit}" />
</h:form>

, . - .

. :

+6

, "type" bean :

String typeString = (String) component.getAttributes().get("type");
0

All Articles