Receiving input from text field

I am writing a plugin that extends from BaseController, and I am using the ShowPermissionsController class from the sample plugin as a guide for what I want to do. So currently I have edited viewPermissions.jsp to include some base forms like two text fields and a button. Now I am a little confused at how I would recieve input from the text fields? So this is the part of the code that will create the two text box forms and the button form:

<h4>Enter project name you wish to copy</h4>

<form>

<input type="text" id='projectName' size="60" tabindex = "1" onblur="setPolicy()"/> </form>

<h4>Enter The new URL you would like this project to point to</h4>

<form>

<input type="text" id='url' size="60" tabindex = "1" onblur="setPolicy()"/> </form>

<form>

<input tabindex = "3" id="search" type="submit" value="Copy Project"/></form>

How do I get access to the information that was entered into the two text fields from within Java? Is there a better example I can look at other than the sample plugin that does some sort of Text Input?

I have already looked at HelloUserController pretty extensively too. I am somewhat wanting the opposite of what that is doing. I undertand putting parameters into the hashmap and displaying them in the .jsp file. That is the way to get information out of teamcity, now how to I get the information in? I hope this is a better explanation of what I want.

Thanks

Chris

7 comments
Comment actions Permalink

First of all all inputs must be included into one form tag if you want them to be passed to the server side simultaneously, also you need to provide name attribute for your text fields:

<form action='<your controller url>'>

<input type="text" id='projectName' name='projectName' size="60" tabindex = "1" onblur="setPolicy()"/>

<h4>Enter The new URL you would like this project to point to</h4>

<input type="text" id='url' name='url' size="60" tabindex = "1" onblur="setPolicy()"/>

<input type="submit" name="submitButton" value="Some text"/>

</form>

You need to provide action attribute to the form which points to the path where your controller is registered (WebControllerManager.registerController()).

You also need to have an action on your form which causes it to be submitted (I added submit button)

Then in your controller in the method doHandle you will need to examine request parameters (request.getParameter(name)). Your text fields values can be accessed by:

String name = request.getParameter("projectName");

String url = request.getParameter("url");

Hope this helps.

0
Comment actions Permalink

Thanks Pavel,

This is very helpful, and I have it working now! I have one last question though, how do you get the submit button to be on the Administration page? I have been able to sucessfully move it to the My Settings & Tools page by changing the page id to point to MY_TOOLS_SECTION and the url to point to "/profile.html" but I can't seem to get this to work with the Adminstration page. I have tried changing the url to "/admin/admin.html" and I have tried every page id that seemed relavent, but no luck. Any suggestions? Thanks again Pavel for the other code.

0
Comment actions Permalink

There is no page place for the administration area, however there are two special places: PAGE_HEADER and PAGE_FOOTER. You can plug to them and activate only if administration area is shown. Is it what you are looking for?

0
Comment actions Permalink

Sorry I should have mentioned that I could put it on the admin page with the FOOTER tag but I was hoping to not have the button stuck on the bottom. I was thinking there might have been a special place like there is on the My Settings & Tools page that I missed.

0
Comment actions Permalink

Well as I told there is no such place at the moment. You can write JavaScript which will move the content of your plugin page to the desired place. For example if you want to show your form at the top of the page the following script can help:

<div id="your_div_id">
your form placed here
</div>

<script type="text/javascript">
$('container').insertBefore($('your_div_id'), $('container').firstChild);
</script>

0
Comment actions Permalink

Nice I will certainly look into this. Thanks again Pavel for the quick responses.

0
Comment actions Permalink

I know its been years since this post has been updated but I hope I get a reply. I don't quite understand what you mean by the action attribute. Also how do I put name and url into HashMap? This is my code so far.

SUser user = SessionUser.getUser(httpServletRequest);
String requirement = request.getParameter(httpServletRequest);
Map<String, Object> params = new HashMap<String, Object>();
params.put("userName", user.getDescriptiveName());
params.put("messages", myBuildListener.getMessages());
params.put("requirement", requirement.???());

0

Please sign in to leave a comment.