0

I need to send values from dialog to bean and insert these vales into the db. I can open the dialog but not able to send any parameter. My bean is

@Named(value = "service12")
@Dependent
public class Service {
private Teachers selectedTeacher;
public Service() {
}

public Teachers getSelectedTeacher() {
    return selectedTeacher;
}

public void setSelectedTeacher(Teachers selectedTeacher) {
    this.selectedTeacher = selectedTeacher;
}
public void getDialog(){
    PrimeFaces current = PrimeFaces.current();
    current.executeScript("PF('teacherDialog').show();");       
    
}   
public void test(){
    Map<String, Object> requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
    requestMap.put("teacher", selectedTeacher);
    System.out.println(selectedTeacher.getFirstName());
}

} and the xhtml page:

<h:body>
    <h:form id="teacherForm">
        <p:growl id="msgs" showDetail="true"/>
        <p:dataTable value="#{service.teacherList}" var = "teacherVar" editable="true" style="margin-bottom:20px" id ="t1" resizableColumns="true"
                     rows="10" paginator="true">
        </p:dataTable>
        <p:commandButton value="Add new row" styleClass="ui-priority-primary" 
                         action="#{service12.getDialog}" />
    </h:form>
    <p:dialog id="dlgT" widgetVar="teacherDialog">
        <h:form>
            <p:panelGrid columns="2" >
                <p:outputLabel value="First Name" />
                <p:inputText id="tfn" value="#{service12.selectedTeacher.firstName}" />
                <p:outputLabel value="Last Name" />
                <p:inputText value="#{service12.selectedTeacher.lastName}" />
                <p:outputLabel value="Account" />
                <p:inputText value="#{service12.selectedTeacher.accountNo}" />
            </p:panelGrid>
            <p:commandButton value="Save" action="#{service12.test()}" oncomplete="PF('teacherDialog').hide();" process="@this">
                
            </p:commandButton>
            
        </h:form>            
    </p:dialog>
</h:body>

Can you tell me how to get the values from map?

Thank you.

Apostolos
  • 10,033
  • 5
  • 24
  • 39
coco
  • 134
  • 5
  • I changed the dpendent scope to SessionScoped and I get the same null at the map the Teachers class is as following:public class Teachers { private int id; private String firstName; private String lastName; private String accountNo; with getters and setters – coco Aug 07 '20 at 07:45
  • So it works if you remove the dialog tags and use it's content inline? I doubt it does but trying this is a step in creating a [mcve] and doing root cause analysis. I 100% sure your question is not dialog related. Then narrow things down more... The `oncomplete` on the `commandButton` is already gone since you removed the dialog. Then remove the `process` does it work then? All steps in root cause analysis – Kukeltje Aug 07 '20 at 08:05
  • Hi Kukeltje, I deleted the answer that which I wanted to be an edit of the original post – coco Aug 07 '20 at 08:21
  • When I chose "Add new row" button it is opening the dialog with the elements defined. I am choosing Save button from the dialog after filling the input text and it prints nothing. – coco Aug 07 '20 at 08:26
  • If you still closed my question, can you tell me why if I am creating the fields in the service bean, then I can access them? btw I thought on this forum can be some guys like me new on different technologies who can have question. Maybe you know the answer to my original posting, it is not normal to close a topic until the user can have a better understanding of the issue – coco Aug 07 '20 at 11:15
  • Look at the top of your question. There is a link to a duplicate. All info is in there. And yes, it is normal to 'close questions' for different reasons. Having a duplicate (existing question) is one of them. And there are sufficient hints in my first comment for you to find the part in the duplicate that is applicable for you. So effectively we 'answered' your question by referring you to a duplicate – Kukeltje Aug 07 '20 at 11:21
  • yeah, sorry for the people that are new and have different questions. on other technologies I saw that moderators are giving straight answers. – coco Aug 07 '20 at 11:28
  • No problem, see #9 in the duplicate – Kukeltje Aug 07 '20 at 11:40
  • Uhhh I now read your question... We DID answer it, and if moderators answer questions that have clear duplicates, they should not be moderators. Most likely there are just normal people answering questions directly instead of pointing to duplicates and prevent fragmentation. The reason for that is that if people want the reputation points for answers, they will not point to duplicates since the stackoverflow system is broken in that regard. Pointing to duplicates shuld give you reputation points as well... Good luck – Kukeltje Aug 10 '20 at 07:31

0 Answers0