I am performing some model validation via a model validator attached to the model at class level. If I find an error I need to be able to attach that error to the relevant field in the view so that it can be shown clearly to the user.
However simply passing in memberNames to the ValidationResult doesn't do anything. Instead what I have found is that I need to re-validate in the controller in order to then populate the ModelState object.
Here is the code:
public class CompletedMilestoneInCorrectOrderAttribute : ValidationAttribute
{
private const string DefaultErrorMessage = "Milestones cannot be completed out of sequence";
public CompletedMilestoneInCorrectOrderAttribute()
: base(DefaultErrorMessage)
{
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
var model = (RevisionEditViewModel)validationContext.ObjectInstance;
var previousCompleted = true;
var loop = 0;
var members = new List<string>();
foreach (var rm in model.RevisionMilestones)
{
if (rm.Completed && !previousCompleted)
{
members.Add("revisionMilestones[" + loop + "].ExpectedCompletionDate");
members.Add("revisionMilestones[" + loop + "].Completed");
}
if (!rm.NotApplicable)
{
previousCompleted = rm.Completed;
}
loop++;
}
if (members.Any())
{
return new ValidationResult(DefaultErrorMessage, members);
}
return null;
}
}
And in the controller
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(RevisionEditViewModel model)
{
//without this code the error never gets attached to the correct field in the view
var validationContext = new ValidationContext(model, null, null);
var validationResults = new List<ValidationResult>();
Validator.TryValidateObject(model, validationContext, validationResults);
foreach (var validationResult in validationResults)
{
foreach (var memberName in validationResult.MemberNames)
{
ModelState.AddModelError(memberName, validationResult.ErrorMessage);
}
}
if (ModelState.IsValid)
{
*snip*
}
else
{
*snip*
}
}
Anyone know what is going on? How can I correct it so the messy code in the controller is no longer needed?
Cheers Mike
Related
I am getting an error on SendAll in a unittest
This works fine...
using (var service = HostContext.ResolveService<DeviceService>(authenticatedRequest))
{
service.Put(new AddConfig { ConfigName = key.KeyName, ConfigValue = key.Value, DeviceId = 0 });
}}
ServiceStack.WebServiceException: 'The operation 'AddConfig[]' does not exist for this service'
//DeviceConfig
/// <summary>
/// To insert new Config
/// </summary>
/// <returns> New row Id or -1 on error</returns>
public long Any(AddConfig request)
{
try
{
//convert request to model
var perm = request.ConvertTo<DeviceConfig>();
//log user
perm.AuditUserId = UserAuth.Id;
//insert data
var insert = Db.Insert(perm, selectIdentity:true);
//log inserted data
LogInfo(typeof(DeviceConfig), perm, LogAction.Insert);
return insert;
}
//on error log error and data
catch (Exception e)
{
Log.Error(e);
}
return -1;
}
[Route("/Config", "PUT")]
public class AddConfig : IReturn<long>
{
public int DeviceId { get; set; }
public string ConfigName { get; set; }
public string ConfigValue { get; set; }
}
public const string TestingUrl = "http://localhost:5123/";
public void DeviceX400Test(string deviceTemaplateFile)
{
//Resolve auto-wired service
WireUpService<DeviceService>();
var requests = new[]
{
new AddConfig { ConfigName = "Foo" },
new AddConfig { ConfigName = "Bar" },
new AddConfig { ConfigName = "Baz" },
};
var client = new JsonServiceClient(TestingUrl);
var deviceConfigs = client.SendAll(requests);
}
MY ServiceBase for Unit Testting that builds from my .netcore appsettings.Json file
public abstract class ServiceTestBase: IDisposable
{
//private readonly ServiceStackHost appHost;
public BasicRequest authenticatedRequest;
public const string TestingUrl = "http://localhost:5123/";
public SeflHostedAppHost apphost;
public ServiceTestBase()
{
var licenseKeyText = "********************************";
Licensing.RegisterLicense(licenseKeyText);
apphost = (SeflHostedAppHost) new SeflHostedAppHost()
.Init()
.Start(TestingUrl);
//regsiter a test user
apphost.Container.Register<IAuthSession>(c => new AuthUserSession { FirstName = "test", IsAuthenticated = true });
}
public void WireUpService<T>() where T : class
{
//var service = apphost.Container.Resolve<T>(); //Resolve auto-wired service
apphost.Container.AddTransient<T>();
authenticatedRequest = new BasicRequest
{
Items = {
[Keywords.Session] = new AuthUserSession { FirstName = "test" , UserAuthId="1", IsAuthenticated = true}
}
};
}
public virtual void Dispose()
{
apphost.Dispose();
}
}
//Create your ServiceStack AppHost with only the dependencies your tests need
/// <summary>
/// This class may need updates to match what is in the mvc.service apphost.cs
/// </summary>
public class SeflHostedAppHost : AppSelfHostBase
{
public IConfigurationRoot Configuration { get; set; }
public SeflHostedAppHost() : base("Customer REST Example", typeof(StartupService).Assembly) { }
public override void Configure(Container container)
{
var file = Path.GetFullPath(#"../../../../cbw.services");
var builder = new ConfigurationBuilder().SetBasePath(file).AddJsonFile("appsettings.json").AddJsonFile("appsettings.LocalSQLServer.json", optional: true);
Configuration = builder.Build();
var sqlString = Configuration["ConnectionString"];
RegisterServiceStack();
//container.Register<ServiceStack.Data.IDbConnectionFactory>(new OrmLiteConnectionFactory(sqlString,SqlServerDialect.Provider));
container.Register<IDbConnectionFactory>(new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));
container.RegisterAutoWired<DatabaseInitService>();
var service = container.Resolve<DatabaseInitService>();
container.Register<IAuthRepository>(c =>
new MyOrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>())
{
UseDistinctRoleTables = true,
});
container.Resolve<IAuthRepository>().InitSchema();
var authRepo = (OrmLiteAuthRepository)container.Resolve<IAuthRepository>();
service.ResetDatabase();
SessionService.ResetUsers(authRepo);
service.InitializeTablesAndData();
//Logging
LogManager.LogFactory = new SerilogFactory(new LoggerConfiguration()
.ReadFrom.Configuration(Configuration)
.Destructure.UsingAttributes()
.CreateLogger());
Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg));
Serilog.Debugging.SelfLog.Enable(Console.Error);
ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
//ILog Log = LogManager.GetLogger(typeof(StartupService));
log.InfoFormat("Applicaiton Starting {Date}", DateTime.Now);
}
public void RegisterServiceStack()
{
var licenseKeyText = "****************************";
Licensing.RegisterLicense(licenseKeyText);
}
}
My Xunit Test
public class DeviceTemplateTest : ServiceTestBase
{
//Post Data
//Device Sends State.XML
[Theory]
[InlineData("C:\\DeviceTemplate.txt")]
public void DeviceX400Test(string deviceTemaplateFile)
{
//Resolve auto-wired service
WireUpService<DeviceService>();
var parser = new FileIniDataParser();
IniData data = parser.ReadFile(deviceTemaplateFile);
List<AddConfig> batch = new List<AddConfig>();
//Iterate through all the sections
foreach (SectionData section in data.Sections)
{
Console.WriteLine("[" + section.SectionName + "]");
//Iterate through all the keys in the current section
//printing the values
foreach (KeyData key in section.Keys)
{
batch.Add(new AddConfig { ConfigName = key.KeyName, ConfigValue = key.Value, DeviceId = 0 });
// using (var service = HostContext.ResolveService<DeviceService>(authenticatedRequest))
//{
// service.Any(new AddConfig { ConfigName = key.KeyName, ConfigValue = key.Value, DeviceId = 0 });
//}
}
}
var client = new JsonServiceClient(TestingUrl);
var deviceConfigs = client.SendAll(batch.ToArray());
}
}
Firstly, you should never return value types in Services, your Request DTO says it returns a DeviceConfig Response Type DTO:
public class AddConfig : IReturn<DeviceConfig> { ... }
Which your Service should be returning instead.
I'm unclear how this can work or compile:
using (var service = HostContext.ResolveService<DeviceService>(authenticatedRequest))
{
service.SendAll(new AddConfig {
ConfigName = key.KeyName, ConfigValue = key.Value, DeviceId = 0
});
}
Since it's calling methods on the DeviceService Service class directly and there is no SendAll() method on the Service class (or in your example), were you using the Service Gateway instead?
I can't tell what the issue is from here without seeing the full source code and being able to repro the issue but it sounds like AddConfig is not recognized as a Service, is it appearing in the /metadata page? If not do you have it a class that inherits Service?
Otherwise if you can post a minimal repro on GitHub, I'll be able to identify the issue.
I want to list all of documents in my datas and using Findasync (csharpdriver 2.2.3) to find all but it never returns. Could you give me some advices.
Here is my codes
public class HomeController : Controller
{
readonly MyVietnamContext Context = new MyVietnamContext();
private List<UserModels> list = new List<UserModels>();
public ActionResult Index()
{
GetUsers().Wait();
return View(list);
}
public async Task GetUsers()
{
var filter = new BsonDocument();
var collection = Context.Collection();
var cursor = await collection.FindAsync(filter);
while (await cursor.MoveNextAsync())
{
var batch = cursor.Current;
list.AddRange(batch);
}
}
}
Change your code to
public async Task<ActionResult> Index()
{
await GetUsersAsync();
return View(list);
}
public async Task<Context.Collection> GetUsersAsync()
{
var filter = new BsonDocument();
var collection = Context.Collection();
var cursor = await collection.FindAsync(filter);
while (await cursor.MoveNextAsync())
{
var batch = cursor.Current;
list.AddRange(batch);
}
return list;
}
Have also a look at the Using Asynchronous Methods in ASP.NET MVC 4 page.
I getting error null reference exception while trying to pass data to view model
ViewModel
public class AccommodationApplicationViewModel
{
public AccommodationApplicationViewModel() { }
public PropertyRentingApplication _RentingApplicationModel { get; set; }
public PropertyRentingPrice _PropertyRentingPriceModel { get; set; }
}
Controller Method
[Authorize]
[HttpGet]
public ActionResult ApplyForAccommodation()
{
int _studentEntityID = 0;
//PropertyRentingApplication PropertyRentingApplicationModel = new PropertyRentingApplication();
AccommodationApplicationViewModel PropertyRentingApplicationModel = new AccommodationApplicationViewModel();
if (User.Identity.IsAuthenticated)
{
_studentEntityID = _studentProfileServices.GetStudentIDByIdentityUserID(User.Identity.GetUserId());
if (_studentEntityID != 0)
{
bool StudentCompletedProfile = _studentProfileServices.GetStudentDetailedProfileStatusByID(_studentEntityID);
if (StudentCompletedProfile)
{
PropertyRentingApplicationModel._RentingApplicationModel.StudentID = _studentEntityID;
PropertyRentingApplicationModel._RentingApplicationModel.DateOfApplication = DateTime.Now;
var s = "dd";
ViewBag.PropertyTypes = new SelectList(_propertyManagementServices.GetAllPropertyType(), "PropertyTypeID", "Title");
// ViewBag.PropertyRentingPrise = _propertyManagementServices.GetAllPropertyRentingPrice();
return PartialView("ApplyForAccommodation_partial", PropertyRentingApplicationModel);
}
else
{
return Json(new { Response = "Please Complete Your Profile Complete Before Making Request For Accommodation", MessageStatus ="IncompletedProfile"}, JsonRequestBehavior.AllowGet);
}
}
return Json(new { Response = "User Identification Fail!", MessageStatus = "IdentificationFail" }, JsonRequestBehavior.AllowGet);
}
return RedirectToAction("StudentVillageHousing", "Home");
}
}
You haven't initialized either _RentingApplicationModel nor _PropertyRentingPriceModel. The easiest solution is to simply initialize these properties in your constructor for AccommodationApplicationViewModel:
public AccommodationApplicationViewModel()
{
_RentingApplicationModel = new PropertyRentingApplication();
_PropertyRentingPriceModel = new PropertyRentingPrice();
}
Then, you should be fine.
I have a Place data_object in the service side which contains a navigation property Roads:
public class Place : EntityData
{
...
public List<Road> Roads { get; set; }
}
And now on the client side, I want to get a Place object using its id, but the navigation property Roads just won't load. Is there any parameter or attribute I can add to make it work?
My code for it:
var roadList = await App.MobileService.GetTable<Place>()
.LookupAsync(placeId);
Since loading navigation properties in EF requires a JOIN operation in the database (which is expensive), by default they are not loaded, as you noticed. If you want them to be loaded, you need to request that from the client, by sending the $expand=<propertyName> query string parameter.
There are two ways of implementing this: in the server and in the client. If you want to do that in the server, you can implement an action filter which will modify the client request and add that query string parameter. You can do that by using the filter below:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
class ExpandPropertyAttribute : ActionFilterAttribute
{
string propertyName;
public ExpandPropertyAttribute(string propertyName)
{
this.propertyName = propertyName;
}
public override void OnActionExecuting(HttpActionContext actionContext)
{
base.OnActionExecuting(actionContext);
var uriBuilder = new UriBuilder(actionContext.Request.RequestUri);
var queryParams = uriBuilder.Query.TrimStart('?').Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries).ToList();
int expandIndex = -1;
for (var i = 0; i < queryParams.Count; i++)
{
if (queryParams[i].StartsWith("$expand", StringComparison.Ordinal))
{
expandIndex = i;
break;
}
}
if (expandIndex < 0)
{
queryParams.Add("$expand=" + this.propertyName);
}
else
{
queryParams[expandIndex] = queryParams[expandIndex] + "," + propertyName;
}
uriBuilder.Query = string.Join("&", queryParams);
actionContext.Request.RequestUri = uriBuilder.Uri;
}
}
And then you can decorate your method with that attribute:
[ExpandProperty("Roads")]
public SingleItem<Place> GetPlace(string id) {
return base.Lookup(id);
}
Another way to implement this is to change the client-side code to send that header. Currently the overload of LookupAsync (and all other CRUD operations) that takes additional query string parameters cannot be used to add the $expand parameter (or any other $-* parameter), so you need to use a handler for that. For example, this is one such a handler:
class MyExpandPropertyHandler : DelegatingHandler
{
string tableName
string propertyName;
public MyExpandPropertyHandler(string tableName, string propertyName)
{
this.tableName = tableName;
this.propertyName = propertyName;
}
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request.Method.Method == HttpMethod.Get.Method &&
request.RequestUri.PathAndQuery.StartsWith("/tables/" + tableName, StringComparison.OrdinalIgnoreCase))
{
UriBuilder builder = new UriBuilder(request.RequestUri);
string query = builder.Query;
if (!query.Contains("$expand"))
{
if (string.IsNullOrEmpty(query))
{
query = "";
}
else
{
query = query + "&";
}
query = query + "$expand=" + propertyName;
builder.Query = query.TrimStart('?');
request.RequestUri = builder.Uri;
}
}
return await base.SendAsync(request, cancellationToken);
return result;
}
}
And you'd use the handler by creating a new instance of MobileServiceClient:
var expandedClient = new MobileServiceClient(
App.MobileService.ApplicationUrl,
App.MobileService.ApplicationKey,
new MyExpandPropertyHandler("Place", "Roads"));
var roadList = await App.MobileService.GetTable<Place>()
.LookupAsync(placeId);
I want to add repeatable properties to the Jenkins plugin I'm developing, and created a test plugin to make make sure I was using them correctly. My plugin seems to work fine, I can add as many properties as I want when I originally edit the config, and it saves and builds. However, when I try to edit the config a second time, the config screen shows the loading overlay endlessly. If I scroll down, I can see the properties I saved earlier are still there, but I can't edit anything.
My class looks like this:
public class RepeatableTest extends Builder {
private List<Prop> property = new ArrayList<Prop>();
#DataBoundConstructor
public RepeatableTest(List<Prop> property) {
this.property = property;
}
public List<Prop> getProperty() {
return property;
}
#Override
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException {
listener.getLogger().println(property.get(0).name);
listener.getLogger().println(property.size());
return true;
}
#Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl)super.getDescriptor();
}
public static class Prop extends AbstractDescribableImpl<Prop> {
public String name;
public String getName(){
return name;
}
#DataBoundConstructor
public Prop(String name) {
this.name = name;
}
#Extension
public static class DescriptorImpl extends Descriptor<Prop> {
#Override
public String getDisplayName() {
return "";
}
}
}
#Extension // This indicates to Jenkins that this is an implementation of an extension point.
public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
private String phpLoc;
public DescriptorImpl() {
load();
}
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
// Indicates that this builder can be used with all kinds of project types
return true;
}
public String getDisplayName() {
return "Repeatable Test";
}
#Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
phpLoc = formData.getString("phpLoc");
save();
return super.configure(req,formData);
}
public String getPhpLoc() {
return phpLoc;
}
}
}
My config.groovy looks like this:
package uitestplugin.uitest.RepeatableTest;
import lib.JenkinsTagLib
import lib.FormTagLib
def f = namespace(lib.FormTagLib)
t=namespace(JenkinsTagLib.class)
f.form{
f.entry(title:"Properties"){
f.repeatableProperty(field:"property")
}
}
and my prop/config.groovy looks like this:
package uitestplugin.uitest.RepeatableTest.Prop;
def f = namespace(lib.FormTagLib)
f.entry(title:"Name", field:"name") {
f.textbox()
}
The config.xml:
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders>
<uitestplugin.uitest.RepeatableTest plugin="ui-test#1.0-SNAPSHOT">
<property>
<uitestplugin.uitest.RepeatableTest_-Prop>
<name>Prop1</name>
</uitestplugin.uitest.RepeatableTest_-Prop>
<uitestplugin.uitest.RepeatableTest_-Prop>
<name>Prop2</name>
</uitestplugin.uitest.RepeatableTest_-Prop>
</property>
</uitestplugin.uitest.RepeatableTest>
</builders>
<publishers/>
<buildWrappers/>
</project>
Any ideas as to what could cause this? I based a lot of the code from the ui-samples plugin (https://wiki.jenkins-ci.org/display/JENKINS/UI+Samples+Plugin).
EDIT: The current status of this is, well, I still haven't figured it out. I've done more research and tried tons of different examples, but the farthest I ever get is what I described above. It almost seems like you can't use repeatable through groovy. Anyways, I have one more piece of information to add. Using the web developer toolbar for Firefox, I can see that there is a Javascript error on the page. The error is:
Timestamp: 10/3/2014 12:58:49 PM
Error: TypeError: prototypes is undefined
Source File: http://localhost:8080/adjuncts/e58fb488/lib/form/hetero-list/hetero-list.js
Line: 16
And the code this relates to is(I've marked line 16 with a comment at the end of the line):
// #include lib.form.dragdrop.dragdrop
// do the ones that extract innerHTML so that they can get their original HTML before
// other behavior rules change them (like YUI buttons.)
Behaviour.specify("DIV.hetero-list-container", 'hetero-list', -100, function(e) {
e=$(e);
if(isInsideRemovable(e)) return;
// components for the add button
var menu = document.createElement("SELECT");
var btns = findElementsBySelector(e,"INPUT.hetero-list-add"),
btn = btns[btns.length-1]; // In case nested content also uses hetero-list
YAHOO.util.Dom.insertAfter(menu,btn);
var prototypes = $(e.lastChild);
while(!prototypes.hasClassName("prototypes")) //LINE 16, ERROR IS HERE
prototypes = prototypes.previous();
var insertionPoint = prototypes.previous(); // this is where the new item is inserted.
// extract templates
var templates = []; var i=0;
$(prototypes).childElements().each(function (n) {
var name = n.getAttribute("name");
var tooltip = n.getAttribute("tooltip");
var descriptorId = n.getAttribute("descriptorId");
menu.options[i] = new Option(n.getAttribute("title"),""+i);
templates.push({html:n.innerHTML, name:name, tooltip:tooltip,descriptorId:descriptorId});
i++;
});
Element.remove(prototypes);
var withDragDrop = initContainerDD(e);
var menuAlign = (btn.getAttribute("menualign")||"tl-bl");
var menuButton = new YAHOO.widget.Button(btn, { type: "menu", menu: menu, menualignment: menuAlign.split("-") });
$(menuButton._button).addClassName(btn.className); // copy class names
$(menuButton._button).setAttribute("suffix",btn.getAttribute("suffix"));
menuButton.getMenu().clickEvent.subscribe(function(type,args,value) {
var item = args[1];
if (item.cfg.getProperty("disabled")) return;
var t = templates[parseInt(item.value)];
var nc = document.createElement("div");
nc.className = "repeated-chunk";
nc.setAttribute("name",t.name);
nc.setAttribute("descriptorId",t.descriptorId);
nc.innerHTML = t.html;
$(nc).setOpacity(0);
var scroll = document.body.scrollTop;
renderOnDemand(findElementsBySelector(nc,"TR.config-page")[0],function() {
function findInsertionPoint() {
// given the element to be inserted 'prospect',
// and the array of existing items 'current',
// and preferred ordering function, return the position in the array
// the prospect should be inserted.
// (for example 0 if it should be the first item)
function findBestPosition(prospect,current,order) {
function desirability(pos) {
var count=0;
for (var i=0; i<current.length; i++) {
if ((i<pos) == (order(current[i])<=order(prospect)))
count++;
}
return count;
}
var bestScore = -1;
var bestPos = 0;
for (var i=0; i<=current.length; i++) {
var d = desirability(i);
if (bestScore<=d) {// prefer to insert them toward the end
bestScore = d;
bestPos = i;
}
}
return bestPos;
}
var current = e.childElements().findAll(function(e) {return e.match("DIV.repeated-chunk")});
function o(did) {
if (Object.isElement(did))
did = did.getAttribute("descriptorId");
for (var i=0; i<templates.length; i++)
if (templates[i].descriptorId==did)
return i;
return 0; // can't happen
}
var bestPos = findBestPosition(t.descriptorId, current, o);
if (bestPos<current.length)
return current[bestPos];
else
return insertionPoint;
}
(e.hasClassName("honor-order") ? findInsertionPoint() : insertionPoint).insert({before:nc});
if(withDragDrop) prepareDD(nc);
new YAHOO.util.Anim(nc, {
opacity: { to:1 }
}, 0.2, YAHOO.util.Easing.easeIn).animate();
Behaviour.applySubtree(nc,true);
ensureVisible(nc);
layoutUpdateCallback.call();
},true);
});
menuButton.getMenu().renderEvent.subscribe(function() {
// hook up tooltip for menu items
var items = menuButton.getMenu().getItems();
for(i=0; i<items.length; i++) {
var t = templates[i].tooltip;
if(t!=null)
applyTooltip(items[i].element,t);
}
});
if (e.hasClassName("one-each")) {
// does this container already has a ocnfigured instance of the specified descriptor ID?
function has(id) {
return Prototype.Selector.find(e.childElements(),"DIV.repeated-chunk[descriptorId=\""+id+"\"]")!=null;
}
menuButton.getMenu().showEvent.subscribe(function() {
var items = menuButton.getMenu().getItems();
for(i=0; i<items.length; i++) {
items[i].cfg.setProperty("disabled",has(templates[i].descriptorId));
}
});
}
});
Behaviour.specify("DIV.dd-handle", 'hetero-list', -100, function(e) {
e=$(e);
e.on("mouseover",function() {
$(this).up(".repeated-chunk").addClassName("hover");
});
e.on("mouseout",function() {
$(this).up(".repeated-chunk").removeClassName("hover");
});
});
I hope this is enough information to solve the problem. Any suggestions (even if they aren't complete answers) are really appreciated.
While not an exact answer, I did find a way to get this working. For some reason, putting the repeatableProperty in an advanced block stopped the javascript error from happening, so everything loaded fine.
So, my config.groovy for RepeatableTest looked like this:
package uitestplugin.uitest.RepeatableTest;
f = namespace(lib.FormTagLib)
f.advanced{
f.entry(title:"Properties"){
f.repeatableProperty(field:"property", minimum:"1"){
}
}
}
My config.groovy for Prop1 looked like this:
package uitestplugin.uitest.Prop1;
def f = namespace(lib.FormTagLib)
f.entry(title:"Name",field:"name") {
f.textbox()
}
f.entry {
div(align:"left") {
input(type:"button",value:"Delete",class:"repeatable-delete")
}
}
My prop 1 looked like this:
public class Prop1 extends AbstractDescribableImpl<Prop1> {
private final String name;
public String getName(){
return name;
}
#DataBoundConstructor
public Prop1( String name) {
this.name = name;
}
#Extension
public static class DescriptorImpl extends Descriptor<Prop1> {
#Override
public String getDisplayName() {
return "";
}
}
}
And my RepeatableTest.java looked like this:
public class RepeatableTest extends Builder {
private final List<Prop1> property;
// Fields in config.jelly must match the parameter names in the "DataBoundConstructor"
#DataBoundConstructor
public RepeatableTest(List<Prop1> property) {
this.property = property;
}
public List<Prop1> getProperty() {
return property;
}
#Override
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException {
//Doesn't matter
}
#Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl)super.getDescriptor();
}
#Extension // This indicates to Jenkins that this is an implementation of an extension point.
public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
private String phpLoc;
public DescriptorImpl() {
load();
}
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
// Indicates that this builder can be used with all kinds of project types
return true;
}
public String getDisplayName() {
return "Repeatable Test";
}
#Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
phpLoc = formData.getString("phpLoc");
save();
return super.configure(req,formData);
}
public String getPhpLoc() {
return phpLoc;
}
}
}