0

I need to solve this issue. I am using jsf primefaces with c:foreach here is my code. but this code is not running.

<p:tab id="catagoryTab" title="#{hardvalue['tutor.reg.tab2']}">
                <p:panel header="#{hardvalue['tutor.reg.tab2']}" id="rowCreator">
                <h:outputLabel value="#{hardvalue['tutor.reg.selectStmt']}"></h:outputLabel>
                        <h:panelGrid columns="3" style="width:100%;">
                            <p:outputLabel value="#{hardvalue['tutor.reg.category.table.collection']}"/>
                            <p:outputLabel value="#{hardvalue['tutor.reg.category.table.level']}"/>
                            <p:outputLabel value="#{hardvalue['tutor.reg.category.table.subject']}"/>
                        </h:panelGrid>


                            <c:forEach begin="0" end="#{Registerbean.size -1}" varStatus="loop" var="row"> 
                            <h:panelGrid  columns="3"
                            style="width:100%; border: 1px solid #d4f1ff; border-radius: 3px 3px 3px 3px; background:#F7FDFF  50% 50% repeat-x ;">
                            <p:selectOneMenu 
                                value="#{Registerbean.selectedtutorialType[loop.index]}"
                                style="font-size:15px !important; width:100px;">
                                <p:ajax process="@this" update="levellist1_#{loop.index}, levellist2_#{loop.index}, subjectlist_#{loop.index}" event="change" 
                                    listener="#{Registerbean.updateRecords(loop.index)}" />
                                <f:selectItem itemLabel="#{hardvalue['tutor.tutorial']}"
                                    itemValue="tutorial" />
                                <f:selectItem itemLabel="#{hardvalue['tutor.conversaion']}"
                                    itemValue="conversation" />
                                <f:selectItem itemLabel="#{hardvalue['tutor.music']}"
                                    itemValue="music" />
                                <f:selectItem itemLabel="#{hardvalue['tutor.other']}"
                                    itemValue="other" />
                            </p:selectOneMenu>
                            <h:panelGrid columns="3" >
                            <p:selectOneMenu  style="width:230px" id="levellist1_#{loop.index}" value="#{Registerbean.selectedtutorialLevelFrom[loop.index]}"
                                 >

                                <f:selectItems value="#{Registerbean.levellist}" />
                            </p:selectOneMenu>
                            <p:outputLabel value=" #{hardvalue['tutor.reg.to']} " />
                            <p:selectOneMenu  style="width:230px" id="levellist2_#{loop.index}" value="#{Registerbean.selectedtutorialLevelTo[loop.index]}"
                                >

                                <f:selectItems value="#{Registerbean.levellist}" />
                            </p:selectOneMenu>

                            </h:panelGrid>          

                                <p:selectOneMenu  id="subjectlist_#{loop.index}" value="#{Registerbean.selectedtutorialSubject[loop.index]}"
                                style="width:230px;" 
                                label="#{hardvalue['tutorsearch.select']}" filter="true" filterMatchMode="startsWith"
                                panelStyle="width:383px">

                                <f:selectItems value="#{Registerbean.subjectslist}" />
                            </p:selectOneMenu>  
                        </h:panelGrid>


                    </c:forEach>

                <p:commandButton id="moreButton" value="#{hardvalue['tutor.reg.addmore']}" update="rowCreator" process="@this" actionListener="#{Registerbean.addNewRow}" />    

               </p:panel>


            </p:tab>

The above code is a tab in wizard. So I need to move on the next page after this one. But I am not able to get the values as it do not let me assign to the array variables using indexes. Here is my backingbean

bean name: @ManagedBean(name="Registerbean")

private Tutor tutor= new Tutor();


private String[] selectedtutorialType= new String[size];


private String[] selectedtutorialLevelFrom= new String[size];

private String[] selectedtutorialLevelTo= new String[size];

private String[] selectedtutorialSubject= new String[size];
    public void addNewRow(){
        System.out.println("In add row");
        size++;

        selectedtutorialSubject=selectedtutorialLevelTo= selectedtutorialLevelFrom=selectedtutorialType=new String[size];


    }

Here is my flowlistner through which I am just checking about the values of this tab. flowListener="#{Registerbean.onFlowProcess}"

public String onFlowProcess(FlowEvent event) {


   System.out.println("tab id is:"+event.getOldStep());
    if(event.getOldStep().equalsIgnoreCase("catagoryTab")){

        for(int i=0;i<selectedtutorialType.length;i++){
            System.out.println("selectedtutorialType : "+selectedtutorialType[i]);
            System.out.println("selectedtutorialLevelFrom : "+selectedtutorialLevelFrom[i]);
            System.out.println("selectedtutorialLevelTo : "+selectedtutorialLevelTo[i]);
            System.out.println("selectedtutorialSubject : "+selectedtutorialSubject[i]);
        }
    }
        return event.getNewStep();

}

What I want is : I want to draw components. on add row A component line will be added here. first one of the component's value changes, it reflacts the values of other two in that row only. but I is not doing the same. As the next button of p:wizard is not allowing me to move upword. for updates it uses this function of backing bean.

public void updateRecords(int index) {
    System.out.println("In update records: "+index);

    levellist = new ArrayList<String>();
    if (selectedtutorialType[index].equals("tutorial")) {

        subjectslist = Arrays.asList(tutorialSubject);

        levellist = Arrays.asList(tutorialLevel);
        System.out.println("tutorial selection done..");
        return;
    } else if (selectedtutorialType[index].equals("conversation")) {

        subjectslist = Arrays.asList(conversationSubject);

        levellist = Arrays.asList(conversationLevel);
        System.out.println("Conversation selection done..");
        return;
    } else if (selectedtutorialType[index].equals("music")) {

        subjectslist = Arrays.asList(musicSubject);

        levellist = Arrays.asList(musicLevel);
        System.out.println("Music selection done..");
        return;
    } else {
        subjectslist = Arrays.asList(otherSubject);

        levellist = Arrays.asList(otherLevel);
        System.out.println("Other selection done..");
        return;
    }

}

What to do. Plz help. Any other detail for this, if I am missing, let me know.

Thanks

  • having ids like id="levellist1_#{loop.index}" , id="levellist2_#{loop.index}" , id="subjectlist_#{loop.index}" is not going to work. Read second paragraph of @BalusC answer here http://stackoverflow.com/questions/20279122/set-id-from-backing-bean-in-jsf – Mahendran Ayyarsamy Kandiar Dec 20 '15 at 18:13
  • @Mahendran: It will work with c:forEach: http://stackoverflow.com/q/3342984 It will only not work with ui:repeat: http://stackoverflow.com/q/18358604 – BalusC Dec 21 '15 at 07:22
  • Hello BalusC, Need your help. Can you please. – Namit Khandelwal Dec 21 '15 at 14:28
  • Hello BalusC, Need your help. Can you please. When I click on next, It say some of the values are not assigned. and marks it with red. I am not able to know that I have not added any validation here. then why it is marking with red to some of the components from this. Add more row is working correctly with managedbean having application Scoped. But here I am not able to assign values to array at specific index using c:forEach index that is starting from 0 to size of the array -1. How to resolve this. Can any one help in this. – Namit Khandelwal Dec 21 '15 at 14:35

0 Answers0