0

I have a page where I click on a button and a panelgrid is added dynamically to the view. I use a UI:Reapeat tag, connected to a backing bean in viewScope to achive it. This works, without any flaws. The problem appears when I want to remove one of the added grids.

I have read alot of Balus C's answeres about similar issues, including using JSTL c:foreach, but with no luck of fixing my own. It is probably easy for one of you guys but for me, it seems impossible. Here is my XHTML:

<h:form id="mainForm">
    <div id="xmlHead" class="xmlTopLabel">
        <p:outputLabel>Object Name</p:outputLabel>
    </div>
    <div class="xmlTopLabel">
        <p:outputLabel>Attribute Name</p:outputLabel>
    </div>
    <div class="clear">

    </div>

    <div id="xmlHead" class="xmlTop">
        <p:inputText></p:inputText>
    </div>
    <div class="xmlTop">
        <p:inputText></p:inputText>
    </div>
    <div class="clear">

    </div>
    <h:panelGroup id="tagsList" class="xmlTagsBox">
    <p:commandButton action="#{controller.add()}" value="add"    update="tagsList" process="@this,tagsList"></p:commandButton>
    <p:commandButton action="#{controller.execute()}" value="execute"></p:commandButton>
    <ui:repeat var="tag" value="#{controller.xmlTagsList}" varStatus="currIndex" >
    <h:panelGrid id="grid" columns="11" style="margin-bottom:5px" cellpadding="5">
    <h:outputText value="Tag Name " />
    <p:inputText value="#{tag.tagName}"></p:inputText>
    <h:outputText value="Value " />
    <p:inputText value="#{tag.value}"></p:inputText>
    <h:outputText value="Type " />
    <p:selectOneMenu value="#{tag.dataType}">
    <f:selectItem itemLabel="String" itemValue="String" />
    <f:selectItem itemLabel="Integer" itemValue="Integer" />
    <f:selectItem itemLabel="Double" itemValue="Double" />
    <f:selectItem itemLabel="Boolean" itemValue="Boolean" />
    </p:selectOneMenu>
    <h:outputText value="is  list " />
    <p:selectBooleanCheckbox id="isList" value="#{tag.list}"></p:selectBooleanCheckbox>
    <h:outputText value="is ChildNode " />
    <p:selectBooleanCheckbox id="isChildNode" value="#{tag.child}"></p:selectBooleanCheckbox>
    <p:commandButton action="#{controller.remove(currIndex.index)}" value="remove" update ="tagsList">
    </p:commandButton>
    </h:panelGrid>
    </ui:repeat>
    </h:panelGroup>

And here is my backing bean:

@ManagedBean
@ViewScoped
public class Controller implements Serializable{

/** The instance represents the */
private static final long serialVersionUID = -6907079630004212317L;

private List<Tags> xmlTagsList;

private XmlObject xmlObj;


public void init(){
    if(xmlTagsList == null){
        xmlObj = new XmlObject();
        xmlTagsList = new ArrayList<Tags>();
        for(int i = 0; i < 4; i++){
            xmlTagsList.add(xmlObj.new Tags());

        }

    }else{

    }
}

public void add(){
    xmlTagsList.add(xmlObj.new Tags());
    System.out.println("new obj added "+xmlTagsList.size());

}

public void remove(int index){
    xmlTagsList.remove(index);
    System.out.println(index);
    System.out.println(xmlTagsList.size());

}

public void execute(){
    for(Tags tag : xmlTagsList){
        System.out.println(tag.getTagName());
    }

}



/**
 * @return the xmlTagsList
 */
public List<Tags> getXmlTagsList(){
    return xmlTagsList;
}

/**
 * @return the xmlObj
 */
public XmlObject getXmlObj(){
    return xmlObj;
}

/**
 * @param xmlTagsList the xmlTagsList to set
 */
public void setXmlTagsList(List<Tags> xmlTagsList){
    this.xmlTagsList = xmlTagsList;
}

/**
 * @param xmlObj the xmlObj to set
 */
public void setXmlObj(XmlObject xmlObj){
    this.xmlObj = xmlObj;
}

}

Any help would be much appriciated. I know that the remove method works, because if i hit the add button after I hit the remove button, the panelGroup is updated and the grids I removed is being removed. That's why I know it has to do with the view, and that I am probably doing something stupid.

I am using mojorra 2.2 PrimeFaces 4.0, tomcat 8.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
SwissArmyKnife
  • 200
  • 1
  • 12
  • This is technically a dupe of http://stackoverflow.com/questions/31353057/fajax-render-does-not-update-components-anymore/ – BalusC Aug 30 '15 at 11:54
  • ok, i might look stupid now, but i fail to see the similarites between the questions. I tried to seperate the call with spaces, but got this exception: javax.servlet.ServletException: Cannot find component with expression "tagsList" referenced from "mainForm:j_idt25:0:j_idt38". – SwissArmyKnife Aug 30 '15 at 13:05
  • Oh, you're not using Mojarra 2.2.5+ ? Well, then this is a dupe: http://stackoverflow.com/questions/8634156/cannot-find-component-with-expression-foo-referenced-from-bar-fajax-con But I only wonder why you didn't got that exception sooner. – BalusC Aug 30 '15 at 13:06
  • I foolishly left that out :/ sorry about that. So, If i understand you correctly. I need to upgrade my mojorra, and use h:commandButton with Ajax render instead? – SwissArmyKnife Aug 30 '15 at 14:01
  • Nope, since Mojarra 2.2.5 you don't get an informative exception anymore when you use the wrong relative ID in f:ajax render. The link in my previous comment explains how to figure out the right ID. – BalusC Aug 30 '15 at 14:09
  • Ok, so naming all compnents, refer them in The buttons update and separate them with space is The way to go? – SwissArmyKnife Aug 30 '15 at 14:30

0 Answers0