Skip to content

Commit c676d8b

Browse files
author
Shashi Bhushan
committed
SLICE-128 changes in SliceLookUpTag - backward compatible
1 parent 391e3d0 commit c676d8b

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

slice-core-api/src/main/java/com/cognifide/slice/api/tag/SliceLookupTag.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,40 @@ public class SliceLookupTag extends SimpleTagSupport {
3333

3434
private String appName; // auto-detected when null
3535

36-
private String type;
36+
private String name;
37+
38+
private Class<?> type;
3739

3840
private void clean() {
3941
type = null;
4042
var = null;
4143
appName = null;
44+
name = null;
4245
}
4346

4447
@Override
4548
public void doTag() throws JspException {
4649
try {
47-
if (StringUtils.isBlank(var) || (type == null)) {
50+
if (StringUtils.isBlank(var) || (type == null && StringUtils.isEmpty(name))) {
4851
throw new JspTagException("Var and Type must be set " + appName);
4952
}
5053

5154
final PageContext pageContext = (PageContext) getJspContext();
52-
final Object model = SliceTagUtils.getFromCurrentPath(pageContext, type, appName);
55+
final Object model = StringUtils.isEmpty(name) ? SliceTagUtils.getFromCurrentPath(pageContext, type, appName) : SliceTagUtils.getFromCurrentPath(pageContext, name, appName);
5356
pageContext.setAttribute(var, model, PageContext.PAGE_SCOPE);
5457
} catch (ClassNotFoundException cause) {
55-
throw new JspTagException("Could not get class for " + type);
58+
throw new JspTagException("Could not get class for " + name + cause.getMessage());
5659
} finally {
5760
clean();
5861
}
5962
}
6063

61-
public void setType(String type) {
62-
this.type = type;
64+
public void setType(Object type) {
65+
if(type instanceof Class){
66+
this.type = (Class)type;
67+
}else if(type instanceof String){
68+
this.name = (String)type;
69+
}
6370
}
6471

6572
public void setVar(String var) {

0 commit comments

Comments
 (0)