Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
99b11d0d
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
99b11d0d
编写于
6月 05, 2012
作者:
K
Kohsuke Kawaguchi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added UI sample fo contextual form field validation
上级
17317bb4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
184 addition
and
0 deletion
+184
-0
ui-samples-plugin/src/main/java/jenkins/plugins/ui_samples/FormFieldValidationWithContext.java
...ns/plugins/ui_samples/FormFieldValidationWithContext.java
+127
-0
ui-samples-plugin/src/main/resources/jenkins/plugins/ui_samples/FormFieldValidationWithContext/City/config.groovy
...samples/FormFieldValidationWithContext/City/config.groovy
+7
-0
ui-samples-plugin/src/main/resources/jenkins/plugins/ui_samples/FormFieldValidationWithContext/State/config.groovy
...amples/FormFieldValidationWithContext/State/config.groovy
+19
-0
ui-samples-plugin/src/main/resources/jenkins/plugins/ui_samples/FormFieldValidationWithContext/index.groovy
...ns/ui_samples/FormFieldValidationWithContext/index.groovy
+22
-0
ui-samples-plugin/src/main/resources/jenkins/plugins/ui_samples/FormFieldValidationWithContext/index.properties
...i_samples/FormFieldValidationWithContext/index.properties
+9
-0
未找到文件。
ui-samples-plugin/src/main/java/jenkins/plugins/ui_samples/FormFieldValidationWithContext.java
0 → 100644
浏览文件 @
99b11d0d
package
jenkins.plugins.ui_samples
;
import
hudson.Extension
;
import
hudson.RelativePath
;
import
hudson.model.AbstractDescribableImpl
;
import
hudson.model.Descriptor
;
import
hudson.util.FormValidation
;
import
org.kohsuke.stapler.DataBoundConstructor
;
import
org.kohsuke.stapler.QueryParameter
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
/**
* How to access values of the nearby input fields when you do form field validation.
*
* @author Kohsuke Kawaguchi
*/
@Extension
public
class
FormFieldValidationWithContext
extends
UISample
{
private
List
<
State
>
states
=
new
ArrayList
<
State
>(
Arrays
.
asList
(
new
State
(
"California"
,
new
City
(
"Sacramento"
),
Arrays
.
asList
(
new
City
(
"San Francisco"
),
new
City
(
"Los Angeles"
))),
new
State
(
"New York"
,
new
City
(
"New York"
),
Arrays
.
asList
(
new
City
(
"Albany"
),
new
City
(
"Ithaca"
)))
));
public
FormFieldValidationWithContext
()
{
}
@DataBoundConstructor
public
FormFieldValidationWithContext
(
List
<
State
>
states
)
{
this
.
states
=
states
;
}
@Override
public
String
getDescription
()
{
return
"How to access values of the nearby input fields when you do form field validation"
;
}
public
List
<
State
>
getStates
()
{
return
states
;
}
@Override
public
List
<
SourceFile
>
getSourceFiles
()
{
List
<
SourceFile
>
r
=
super
.
getSourceFiles
();
r
.
add
(
new
SourceFile
(
"City/config.groovy"
));
r
.
add
(
new
SourceFile
(
"State/config.groovy"
));
return
r
;
}
public
static
class
State
extends
AbstractDescribableImpl
<
State
>
{
/*
I'm lazy and just exposing fields as opposed to getter/setter.
Jenkins doesn't care and works correctly either way.
*/
public
String
name
;
public
City
capital
;
public
List
<
City
>
cities
;
@DataBoundConstructor
public
State
(
String
name
,
City
capital
,
List
<
City
>
cities
)
{
this
.
name
=
name
;
this
.
capital
=
capital
;
this
.
cities
=
cities
;
}
@Extension
public
static
class
DescriptorImpl
extends
Descriptor
<
State
>
{
@Override
public
String
getDisplayName
()
{
return
""
;
}
public
FormValidation
doCheckName
(
@QueryParameter
String
value
,
@RelativePath
(
"capital"
)
@QueryParameter
String
name
)
{
/*
@RelativePath("capital") @QueryParameter
... is short for
@RelativePath("capital") @QueryParameter("name")
... and thus can be thought of "capital/name"
so this matches the current city name entered as the capital of this state
*/
return
FormValidation
.
ok
(
"Are you sure "
+
name
+
" is a capital of "
+
value
+
"?"
);
}
}
}
public
static
class
City
extends
AbstractDescribableImpl
<
City
>
{
public
String
name
;
@DataBoundConstructor
public
City
(
String
name
)
{
this
.
name
=
name
;
}
@Extension
public
static
class
DescriptorImpl
extends
Descriptor
<
City
>
{
@Override
public
String
getDisplayName
()
{
return
""
;
}
public
FormValidation
doCheckName
(
@QueryParameter
String
value
,
@RelativePath
(
".."
)
@QueryParameter
String
name
)
{
/*
@RelativePath("..") @QueryParameter
... is short for
@RelativePath("..") @QueryParameter("name")
... and thus can be thought of "../name"
in the UI, fields for city is wrapped inside those of state, so "../name" binds
to the name field in the state.
*/
if
(
name
==
null
||
value
==
null
||
value
.
contains
(
name
))
return
FormValidation
.
ok
();
return
FormValidation
.
warning
(
"City name doesn't contain "
+
name
);
}
}
}
@Extension
public
static
class
DescriptorImpl
extends
UISampleDescriptor
{
}
}
ui-samples-plugin/src/main/resources/jenkins/plugins/ui_samples/FormFieldValidationWithContext/City/config.groovy
0 → 100644
浏览文件 @
99b11d0d
package
jenkins.plugins.ui_samples.FormFieldValidationWithContext.City
;
def
f
=
namespace
(
lib
.
FormTagLib
)
f
.
entry
(
title:
"City Name"
,
field:
"name"
)
{
f
.
textbox
()
}
ui-samples-plugin/src/main/resources/jenkins/plugins/ui_samples/FormFieldValidationWithContext/State/config.groovy
0 → 100644
浏览文件 @
99b11d0d
package
jenkins.plugins.ui_samples.FormFieldValidationWithContext.State
;
def
f
=
namespace
(
lib
.
FormTagLib
)
f
.
entry
(
title:
"State Name"
,
field:
"name"
)
{
f
.
textbox
()
}
f
.
nested
{
table
{
f
.
section
(
title:
"Capital city"
)
{
f
.
property
(
field:
"capital"
)
}
f
.
entry
(
title:
"Other cities"
)
{
f
.
repeatableProperty
(
field:
"cities"
)
}
}
}
ui-samples-plugin/src/main/resources/jenkins/plugins/ui_samples/FormFieldValidationWithContext/index.groovy
0 → 100644
浏览文件 @
99b11d0d
package
jenkins.plugins.ui_samples.FormFieldValidationWithContext
;
import
lib.JenkinsTagLib
import
lib.FormTagLib
def
f
=
namespace
(
FormTagLib
.
class
)
t
=
namespace
(
JenkinsTagLib
.
class
)
namespace
(
"/lib/samples"
).
sample
(
title:
_
(
"Context-sensitive form validation"
))
{
p
{
raw
(
_
(
"blurb.context"
))
raw
(
_
(
"blurb.otheruse"
))
raw
(
_
(
"blurb.contrived"
))
}
f
.
form
{
f
.
entry
(
title:
"States"
)
{
f
.
repeatableProperty
(
field:
"states"
)
}
}
}
ui-samples-plugin/src/main/resources/jenkins/plugins/ui_samples/FormFieldValidationWithContext/index.properties
0 → 100644
浏览文件 @
99b11d0d
blurb.context
=
\
Form field validation can access values of the nearby input controls, which is useful for performing
\
complex context sensitive form validation.
blurb.otheruse
=
\
The same technique can be also used for auto-completion, populating combobox/listbox, and so on.
blurb.contrived
=
\
The example below is bit contrived, but all the input elements are named 'name' (for city name and state name),
\
and we use <code>@RelativePath</code> so that the validation of the state name refers to the capital name,
\
and the validation of the city name refers to the state name.
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录