floatingBox.jelly - sending data from form

40 views
Skip to first unread message

justine....@gmail.com

unread,
Dec 18, 2014, 8:54:03 AM12/18/14
to jenkin...@googlegroups.com
Hello,
I'm developing my first plugin that allows to add comment on project main page (specific comment for each job). So far I have class that implements Action and floatingbox.jelly with form - textbox and submit button. After adding the comment the form should dissapear and the comment should stay on this job's project main page. Then I want to add button to delete comment, but i still have some problems with doSave function. When I click Submit i get an error: HTTP ERROR 404 Problem accessing /job/jobA/jb/save. Reason: Not Found
There is my simplify class (I made everything public but it still no working):

public class HelloWorldBuilder implements Action {

private AbstractProject ap;
public String comment;
public boolean checkBool;

public HelloWorldBuilder(AbstractProject ap) {
    this.ap = ap;
}

public void doSave(StaplerRequest req, StaplerResponse resp)
        throws ServletException, IOException {
    String reason = (String) req.getSubmittedForm().get("comment");
    reason = this.comment;
    checkBool = true;
    resp.forwardToPreviousPage(req);
}

public String getIconFileName() {
    return null;
}

public String getDisplayName() {
    return "";
}

public String getUrlName() {
    return "";
}

@Extension
public static final class DescriptorImpl extends TransientProjectActionFactory {

    public DescriptorImpl() throws IOException {
    }

    @Override
    public Collection<? extends Action> createFor(AbstractProject target) {
        return Arrays.asList(new HelloWorldBuilder(target));
    }
  }

}


and floatingBox.jelly file:
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<h2>Plugin:</h2>
    <j:if test="${it.checkBool}">
        <h1>${it.comment}</h1>
    </j:if>
    <j:if test="${!it.checkBool}">
        <f:form method="post" action="jb/save" name="save">
        <f:entry title="${%Comment}" >
            <f:textbox name="site" value="${it.comment}" />
        </f:entry>
        <f:block>
            <f:submit value="${%Submit}" />
        </f:block>
    </f:form>      
    </j:if>
</j:jelly>


The class location is in jb\src\main\java\org\jenkinsci\tools\jb\HelloWorldBuilder.java
The jelly location: jb\src\main\resources\org\jenkinsci\tools\jb\HelloWorldBuilder\floatingBox.jelly

Please help me.

Robert Sandell

unread,
Dec 18, 2014, 9:00:16 AM12/18/14
to jenkin...@googlegroups.com
You need to return "jb" from getUrlName() otherwise you are telling the job that there is no specific relative URL to your action. 
Since your form post is pointing to "jb/save" I'm assuming that is the url-space you assume for your action.

/B

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/ebefa5b7-3340-4a34-9dc2-180e5b7d5596%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Robert Sandell
Software Engineer
CloudBees Inc.

justine....@gmail.com

unread,
Dec 18, 2014, 9:19:00 AM12/18/14
to jenkin...@googlegroups.com
Robert, thank you for your help. Now I don't have 404 but my code still doesnt't work. After pressing "submit" textbox is cleaned and thats all.

Robert Sandell

unread,
Dec 19, 2014, 7:14:35 AM12/19/14
to jenkin...@googlegroups.com
In the jelly, the name you set for the textbox is "site" not "comment" as you try to read in the doSave method.

On Thu, Dec 18, 2014 at 3:19 PM, <justine....@gmail.com> wrote:
Robert, thank you for your help. Now I don't have 404 but my code still doesnt't work. After pressing "submit" textbox is cleaned and thats all.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages