我是Java和struts的新手,我正在一个项目中,我需要从一个自定义标记中设置属性的值,该标记检索Java属性的值。
.
├── db.sqlite3
├── some_industry
├── locale
│ ├── en_us
│ │ └── LC_MESSAGES
│ │ └── django.po
│ └── de
│ └── LC_MESSAGES
│ └── django.po
├── machine_request
│ ├── __init__.py
│ ├── admin.py
│ ├── locale
│ │ ├── en_us
│ │ │ └── LC_MESSAGES
│ │ │ └── django.po
│ │ └── de
│ │ └── LC_MESSAGES
│ │ └── django.po
│ ├── migrations
│ ├── static
│ │ └── machine_request
│ ├── templates
│ ├── urls.py
├── manage.py
└── users
├── __init__.py
├── admin.py
├── locale
│ ├── en_us
│ └── de
└── views.py
此属性是根据上下文在Java类中设置的。这段代码在我对应的java类中:
...
<cust:urlGeneration porlet="<cust:write property="tgtPortlet"/>">
<a href="<% wsp.write(out) %>"/>the link</a>
<cust:urlGeneration/>
...
但是它不起作用,portlet属性设置不正确(标记字符串未解释)。
我希望使用if(isMyFirstUseCase)
screenbean.setTgtPortlet = "portlet.myFirstValue";
else
screenbean.setTgtPortlet = "portlet.mySecondValue";
或porlet
来设置portlet.myFirstValue
属性,但是我无法动态地对其进行设置...
我需要逃避某些事情吗?还是根本不可能?否则有人有建议或替代解决方案吗?
如有需要,我可以提供任何其他信息。
谢谢
答案 0 :(得分:1)
您不能以这种方式嵌套标签;这将需要递归标记处理。
这在XML中是相同的-您不能将标签用作另一个标签的属性值。
应使用普通的JSP EL设置属性。
答案 1 :(得分:0)
如果它可以帮助任何人,我发现了使用JSLT的解决方法:
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
我使用“写”自定义标记(业务需求)使用Java类属性的值设置一个中间变量:
<c:set var="varTgtValue"><cust:write property="tgtValue"/></c:set>
然后只需使用$ {myVar}使用此新变量来设置我的JSP标记的属性:
<cust:urlGeneration porlet="${varTgtValue}">
<a href="<% wsp.write(out) %>"/>the link</a>
<cust:urlGeneration/>