-3

I have been searching for similar issue but I could not find any. so here is the thing

I am trying to create a web application that deals with HR stuff, like employee requests (Resign, loan, vacation, etc..) I am using primeface and I have the following problem that I cant figure out.

The thing is I am trying to do is :

1- When user first creates the request and assigns the user and submit the form the next step is

2- the manager would sees the request and then change the "Person responsible for the request" to a new one using the drop menu in the datatable and I have been trying to solve this problem with no luck. Here is the dialog script

<h:form id='resignf'>
<p:dialog id='res' header="Resign Request" widgetVar="resign" minHeight="40">
        <p:outputLabel value="Employee name" /> 
        <p:inputText value="#{controller.resignName}" required="true" requiredMessage="This field is required" />

        <p:outputLabel value="Employee Number" /> 
        <p:inputText value="#{controller.resignEmployeNum}" required="true" />

        <p:inputText value="#{controller.resignNationalIDNum}" required="true"  />

        <p:inputText value="#{controller.resignNotes}" required="true"  />

        <p:outputLabel for="AssignUser" value="User" /> 

        <p:selectOneMenu id="AssignUser"  value="#{controller.assignUser}" style="width:150px" converter="UConverter">
            <f:selectItems value="#{controller.usersList}"  var="user" itemLabel="#{user.username}"/>
        </p:selectOneMenu >


        <p:commandButton action="#{controller.createResignRequest()}" onclick="PF('resign').hide();" update="@all"/>
    </p:dialog>

And the code is my controller.java file below to create the request in the table

/* Request to resign*/
private List<ResignationRequest> resignList;
private ResignationRequestController rController = new ResignationRequestController();

private String resignName;
private String resignEmployeNum;
private String resignNationalIDNum;
private String ResignNotes;
private int AutoAssignToIDNUM;

/* end of request to resign*/

    public void createResignRequest() {

    System.out.println("createResignRequest");
    ResignationRequest newResign = new ResignationRequest();

    newResign.setName(resignName);
    newResign.setEmployeeNum(resignEmployeNum);
    newResign.setNationalID(resignNationalIDNum);

    newResign.setNotes(ResignNotes);

    newResign.setUserID(AssignUser);

    rController.create(newResign);
    resignList = rController.findResignationRequestEntities(); //retrieves all the resigns from the database

}

Now all that is working perfectly, but when I try to change the old user with the new one here I get confused! so far what I have been thinking is I need to find the old user and then switch him, but I could not figure a way to do it using the select list. The script for for changing the "User responsible for the request" below

<p:dataTable id="resignTable1" cellSeparator="true" editMode="cell" editable="true"  var="resign" value="#{controller.resignList}" paginator="true"    rows="10" rowIndexVar="index1">
    <p:ajax id="aj" event="cellEdit" listener="#{controller.editUser(user)}" update="resignTable1"/>
    <p:column headerText="Employee number">
        <p:cellEditor>
            <f:facet name="output"> <h:outputText value="#{resign.employeeNum}" /></f:facet>
            <f:facet name="input"> <h:inputText value="#{resign.employeeNum}" /></f:facet>
        </p:cellEditor>
    </p:column>
    <p:column headerText="name">
        <p:cellEditor>
            <f:facet name="output"> <h:outputText value="#{resign.name}" /></f:facet>
            <f:facet name="input"> <h:inputText value="#{resign.name}" /></f:facet>
        </p:cellEditor>
    </p:column>
    <p:column headerText="Request Number">
        <p:cellEditor>
            <f:facet name="output"> <h:outputText value="#{resign.id}" /></f:facet>
            <f:facet name="input"> <h:inputText value="#{resign.id}" /></f:facet>

        </p:cellEditor>
    </p:column>
    <p:column headerText="User responsible for the request">
        <p:cellEditor>
            <f:facet name="output"> <h:outputText value="#{resign.userID}" /></f:facet>
            <f:facet name="input"> <h:inputText value="#{resign.userID}" /></f:facet>
        </p:cellEditor>
    </p:column>
    <p:column headerText="Comments">
        <p:cellEditor>
            <f:facet name="output"> <h:outputText value="#{resign.notes}" /></f:facet>
            <f:facet name="input"> <h:inputText value="#{resign.notes}" /></f:facet>
        </p:cellEditor>
    </p:column>
    <p:column headerText="Send the request to the next employee">
        <p:selectOneMenu id="AssignUser"  value="#{controller.assignUser}" style="width:150px" converter="UConverter" onchange="submit();">
            <f:selectItems value="#{controller.usersList}"  var="user" itemLabel="#{user.username}"   actionListener="#{controller.editRequestStep(resign)}"  >
            </f:selectItems>
        </p:selectOneMenu >

In my controller file

public void editRequestStep(ResignationRequest r) {

    System.out.println("Edit resign");

    try {
        System.out.println("Edit resign");
        rController.edit(r);

    } catch (Exception ex) {
        Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
    }

}

I tried to get as much as I could from the code but I have a lot of stuff that I am not sure if I should submit. I tried ajax

NOTE: I am using mySQL, apache tomcat in case if it matters.

Bilal Dekar
  • 3,200
  • 4
  • 28
  • 53
  • 2
    There obviously is not an identical question since it is to specific. Break down your problem into manageable parts. Can you get the right data from the client to the server? If not, MySQL is not involved, if you can, jsf/primefaces is not involved. jquery is as it stands totally not involved, nor is java-se. I removed these, but please improve your question by reading [ask] and [mcve] – Kukeltje Sep 05 '16 at 17:30
  • @Kukeltje Actually my problem isnt getting the data or not, I actually am using sql. The thing about primeface is that I need to change the UserID in my "ResignRequest table" using a drop down menu but I could not. thats all about it. – IllegalAccess Sep 05 '16 at 17:39
  • _"that's all about it"_, all about what? You will never ever get data directly from a dropdown (client-side) into a database table.JSF is responsible for getting the data from the client to the webserver, getting the data from the webserver into the database is different code. You post a dialog, so you can get it to work without a dialog? If not, remove it from the example. Can you get it to work without a datatable. If not, remove it from the example. – Kukeltje Sep 05 '16 at 18:06
  • Your question is **not** java-se related. You cannot reproduce this with code that contains just a main method and basic java j.l.s classes – Kukeltje Sep 05 '16 at 18:14
  • And why a 'submit()' in the 'onchange'? What does it do? Maybe reading http://stackoverflow.com/questions/3681123/how-to-send-form-input-values-and-invoke-a-method-in-jsf-bean helps. And an actionListener on a `selectItems`??? I think you should take a step back from development and read a good basic tutorial on JSF – Kukeltje Sep 05 '16 at 18:18
  • @Kukeltje So sir what is it related to? if I am asking to get a java code to edit my table using A dropmenu "client-side" input...? – IllegalAccess Sep 05 '16 at 18:20
  • No, there is no php involved, you develop in java, that much is clear. But the tags are not about what you **use** but where the problem is related to. Since you cannot create a [mcve] that only uses java-se, it is not java related. I removed java and now also mysql. – Kukeltje Sep 05 '16 at 19:21
  • Well, I kind took a look at your comment and found you were right, but I did not understand the "php" thing because I did not mentioned it. Other than that, you might be right, just cause I am new and I tried to explain as much as I could. Specially that the project is big and I do not know what I should include and what I shouldnt. anyways thanks for your help. – IllegalAccess Sep 05 '16 at 19:34
  • Sorry about the confusion about php, I used it to emphasize that it is clear from the code you posted and the frameworks you use that you use java and not php. But keep in mind the [ask] and especially the [mcve] link (see also www.stackoverflow.com/tags/jsf/info) on how to create good questions. It greatly increases your chance of getting a quick, to the point and correct answer. – Kukeltje Sep 05 '16 at 19:50

1 Answers1

0

Solved it.

public void editRequestStep(ResignationRequest r) {

    System.out.println("Edit resign " + EditAssignUser +"   this is userthig" + r.getName());

    try {
        System.out.println("Edit resign");
        r.setUserID(EditAssignUser);

    } catch (Exception ex) {
        Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
    }

}


<p:selectOneMenu id="AssignUser"  value="#{controller.editAssignUser}" style="width:150px" converter="UConverter"> 
                                <p:ajax listener="#{controller.editRequestStep(resign)}" update="@all"/>
                                <f:selectItems value="#{controller.usersList}"  var="user" itemLabel="#{user.username}" >



                                    </f:selectItems>

I did not notice that I used the variable assignUser 2 times, which actually missed me up. So what I did is I created new Users variable called "editAssignUser" then in my controller I just set the user look at the code below

    public void editRequestStep(ResignationRequest r) {

    System.out.println("Edit resign " + EditAssignUser +"   this is userthig" + r.getName());

    try {
        System.out.println("Edit resign");
        r.setUserID(EditAssignUser);

    } catch (Exception ex) {
        Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
    }

}