« Return to Thread: Problem with ui:repeat and own tag

RE: Problem with ui:repeat and own tag

by TRIFILETTI, Mel-2 :: Rate this Message:

Reply to Author | View in Thread

I am not 100% sure, but I think you have gone down the wrong path. In
your component all you need is a getter and setter like this

public Integer getUserId() {
    if (this.userId != null)
                return this.userId ;
        ValueBinding vb = getValueBinding("userId");

        return vb != null ? Integer.valueOf((String)
vb.getValue(getFacesContext())) : null;
}

public void setUserId(Integer userId) {
        this.userId= userId;
}

-----Original Message-----
From: Dominik Dorn [mailto:dominik.dorn@...]
Sent: Sunday, 21 June 2009 2:29 AM
To: users@...
Subject: Problem with ui:repeat and own tag

Hello!

I've created an own tag by creating a TagHandler and a Renderer.

The tag looks like <dc:userString userId="#{newsEntry.userId}" /> (being
userId an integer).
When using it with normal bean properties, it works as expected.

However if I try to use it within a <ui:repeat var="message"
value="#{messages}">
being messages a list of Message-Objects it doesn't work anymore,
meaning that the el

#{message.sender} does get resolved inside <ui:outputText
value="#{message.sender}" /> or even without a tag but not within  my
tag <dc:userString userId="#{message.sender}" />

[code]
/**
 * HTML-Representation of the UserString  */ public final class
UserStringTagHandler extends TagHandler {

        private final TagAttribute userId;

        public UserStringTagHandler(ComponentConfig config) {
                super(config);
                this.userId = this.getRequiredAttribute("userId");
        }


        @Override
        public void apply(FaceletContext faceletContext, UIComponent
parentUIComponent) throws IOException, FacesException, FaceletException,
ELException {

// some business logic here; creating the "uss" object
                                if (userId.isLiteral()) { //If this
TagAttribute is literal (not #{..} or ${..})
                                        us =
uss.getUserString(Integer.parseInt(userId.getValue(faceletContext)));
                                } else {
                                        int userIdInt = -1;


                                        if (parentUIComponent instanceof
UIRepeat) {


       
userIdInt = Integer.parseInt( userId.getValue(faceletContext) );
userIdInt); // this works with a normal bean property, but not with
ui:repeat!
                                        us =
uss.getUserString(userIdInt);

                                }

                                output.setValue(us);

                        }
                        catch (NumberFormatException
numberFormatException) {
                                throw new TagAttributeException(userId,
"Invalid userId given or string not castable to a valid number",
numberFormatException);
                        }
                } else {
                        output.setValue(userId.getValue());
                        output.setValue("UserStringTagHandler: XXXX
numbertest of <b>" +
userId.getValue() + "</b> XXXX "); // place Object UserString in here
                }
                parentUIComponent.getChildren().add(output);
        }
}
[/code]

Please someone give me a hint... I've spent > 20h on this issue already.

Thanks,
Dominik

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


DISCLAIMER: This email, including any attachments, is intended only for use by the addressee(s)
and may contain confidential and/or personal information and may also be the subject of legal privilege.
If you are not the intended recipient, you must not disclose or use the information contained in it.
In this case, please let me know by return email, delete the message permanently from your system and destroy any copies.

Before you take any action based upon advice and/or information contained in this email you should
carefully consider the advice and information and consider obtaining relevant independent advice.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...

 « Return to Thread: Problem with ui:repeat and own tag