0

This is how I'm rendering my composite component inside a loop, it works, but when I switch to edit mode and sumbmit new values I can't retrieve them from the InputText.

@FacesComponent("customComponent")
public class CustomComponent extends UIInput implements NamingContainer, Serializable {

    private static final long serialVersionUID = 1L;

    @Override
    public String getFamily() {
        return UINamingContainer.COMPONENT_FAMILY;
    }

    private UIComponent component;
    private HtmlInputText inputTextValue;

    @Override
    public void encodeBegin(FacesContext context) throws IOException {

        AttributeObject attrObject = (AttributeObject) getAttributes().get("value");
        Boolean enableInput = (Boolean) getAttributes().get("enableInput");

        if (attrObject.getAttributeValue() != null) {
            if (attrObject.getAttributeDescriptor().getDataType() == DataTypeConstants.TEXT && enableInput) {
                InputText inputText = new InputText();
                inputText.setRequired(true);
                inputText.setValueExpression("binding",
                        createValueExpression("#{searchController.myComponent}", UIComponent.class));
                inputText.setId("editableTextId");
                inputText.encodeAll(context);
                inputText.setParent(this);
                component = inputText;
            } else if (attrObject.getAttributeDescriptor().getDataType() == DataTypeConstants.TEXT
                    && enableInput == false) {
                OutputLabel outputLabel = new OutputLabel();
                outputLabel.setValue(attrObject.getAttributeValue());
                outputLabel.encodeAll(context);
                outputLabel.setId("nonEditatbleId");
                component = outputLabel;
            }
        }

    }

    private ValueExpression createValueExpression(String valueExpression, Class<?> valueType) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        return facesContext.getApplication().getExpressionFactory()
                .createValueExpression(facesContext.getELContext(), valueExpression, valueType);
    }

this is where Iam trying to submit, the results you see (testnumber, test name) are coming from the attributeObject, but if I write different values and submit I get the previous results again.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
theo231022
  • 329
  • 2
  • 12
  • 2
    Use XHTML to create components, not Java. In 99% of cases, problem will solve all by itself like magic. Here's some food for read: http://stackoverflow.com/q/14911158 – BalusC Nov 26 '15 at 10:25
  • thank you balusC thats exactly what I did before.. the problem is I have performance problems because Iam iterating over a lot of fields (up to 1500) I was using rendered attribute for each component but I read somewhere that rendered is indeed not showing html on page BUT all of this components are getting build inside the uicomponent tree. And I believe this is the case here. When I switched to java code I was able to manipulate which components should get and should not get stacked under this tree. Reading is faster and Iam trying to do the same with writing. thank you for your response – theo231022 Nov 26 '15 at 10:52
  • Exactly I tried also with c:test and It didnt worked. I have a link to put it here you have answered! – theo231022 Nov 26 '15 at 10:55
  • http://stackoverflow.com/questions/3442380/jstl-cif-doesnt-work-inside-a-jsf-hdatatable – theo231022 Nov 26 '15 at 10:55
  • Yes I know iam currently reading it thank you – theo231022 Nov 26 '15 at 10:56

1 Answers1

0

Ok I think I found what caused all that mad performance problems. I did some logic inside a getter and because that getter was getting called multiple times that caused performance issues.

theo231022
  • 329
  • 2
  • 12
  • This answer is about something you stated in the comments of the question, right? – Kukeltje Dec 07 '15 at 08:44
  • I'm so sorry I should have answered diffrent (you are totaly right) This question was made because I had performance issues. I managed to fix them with a totaly different way by using the "rendered attribute" as balus said. I just found out that the problem was deep inside my logic and not in the jsf components. – theo231022 Dec 07 '15 at 08:48