我有另一个大问题。我有组件,区域和表单刷新区域。当我将组件放入循环内时,它只显示最后一个区域。我为每个区域生成了唯一的ID。在页面源代码中,我可以看到每个区域都有正确的ID,但在提交时它不会返回。无论如何都要通过id返回区域?
这是我的代码:
<details>
<summary>Comments</summary><br />
<t:zone t:id="commentZone" id="prop:zoneId">
<t:commentlist materijalID="materijalID"></t:commentlist><br />
</t:zone>
<t:form t:id="komentar" t:context="materijalID" t:zone="prop:zoneId">
<t:textarea t:value="comment" rows="6" cols="40"></t:textarea><br />
<input type="submit" value="Add comment"/>
</t:form>
</details>
public class Comments
{
@Parameter(required=true)
@Property
private int materijalID;
@SessionState
@Property
private User user;
@Inject
private Session session;
@Property
private String comment;
@InjectComponent
private Zone commentZone;
@CommitAfter
public Object onSuccessFromKomentar(int materijalID)
{
Komentar k = new Komentar();
Date d = new Date();
Materijal m = (Materijal)session
.createCriteria(Materijal.class)
.add(Restrictions.eq("materijalID", materijalID))
.list()
.get(0);
k.setMaterijal(m);
k.setKorisnikID(this.user.getID());
k.setDatumUnosa(d);
k.setDatumModifikacije(d);
k.setKomentar(this.comment);
session.save(k);
this.comment = "";
return this.commentZone.getBody();
}
public String getZoneId()
{
return "Zone_" + this.materijalID;
}
}
提前致谢
答案 0 :(得分:1)
您是否尝试在t:defer="false"
中设置Submit
?
Henning回答了类似的问题here
答案 1 :(得分:0)
问题很可能是你传入CommentList的materijalID与作为@Parameter传入的相同。这意味着您的封装组件将为您设置此值。在循环的情况下,这很可能始终是渲染阶段之后的最后一个。
解决方案在于解决这个问题。有点像:
<details>
<summary>Comments</summary><br />
<t:zone t:id="commentZone" id="prop:zoneId">
<t:commentlist materijalID="prop:passThroughMaterijalID"></t:commentlist>
<br />
</t:zone>
<t:form t:id="komentar" t:context="materijalID" t:zone="prop:zoneId">
<t:textarea t:value="comment" rows="6" cols="40"></t:textarea><br />
<input type="submit" value="Add comment"/>
</t:form>
</details>
public class Comments
{
@Parameter(required=true)
@Property
private int materijalID;
@Property
private int passThroughMaterijalID;
@SessionState
@Property
private User user;
@Inject
private Session session;
@Property
private String comment;
@InjectComponent
private Zone commentZone;
@SetupRender
private void setup() {
this.passThroughMaterijalID = materijalID;
}
@CommitAfter
public Object onSuccessFromKomentar(int materijalID)
{
this.passThroughMaterijalID = materijalID;
Komentar k = new Komentar();
Date d = new Date();
Materijal m = (Materijal)session
.createCriteria(Materijal.class)
.add(Restrictions.eq("materijalID", materijalID))
.list()
.get(0);
k.setMaterijal(m);
k.setKorisnikID(this.user.getID());
k.setDatumUnosa(d);
k.setDatumModifikacije(d);
k.setKomentar(this.comment);
session.save(k);
this.comment = "";
return this.commentZone.getBody();
}
public String getZoneId()
{
return "Zone_" + this.materijalID;
}
}