将值从jsp传递给Action for java.util.Set [英] Passing value from jsp to Action for java.util.Set

查看:96
本文介绍了将值从jsp传递给Action for java.util.Set的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为从JSP登录的Set个元素设置值.

I want to set values for Set elements of login from JSP .

JSP页面:

  <form action="Registered" method="post"> 
        <div class="form-group">
            <label>Company Name</label>
            <s:textfield name="name" value="%{name}" id="name"/>
        </div>
        <div class="form-group">
            <label>Address</label>
            <s:textarea name="address" value="%{address}" id="address"/>
        </div>
        <div class="form-group">
            <label>User Name</label>
            <s:textfield name="logins[0].userName" value="%{logins[0].userName}" id="userName"/>
        </div>
        <div class="form-group">
            <label>User Id</label>
            <s:textfield name="logins[0].userId" value="%{logins[0].userId}" id="userId"/>
        </div>
        <div class="form-group">
            <label>Mail Id</label>
            <s:textfield name="logins[0].userMailid" value="%{logins[0].userMailid}" id="userMailid"/>
        </div>

Pojo课程

public class Client  implements java.io.Serializable {
  private Set logins = new HashSet(0);
  //getter and setter
 }



 public class Login implements java.io.Serializable {

    private Long id;
    private Client client;
    private String userId;
    private String userName;
    private String userMailid;
 }

动作类

public String register() {
        Client cl = new Client();
        System.out.println(cl.getName() + " " + cl.getAddress());
  }

我想为客户端和登录名的操作类设置set in的值.

I want to set values of set in to my Action class for Client and Login.

如何执行此操作?

推荐答案

要将fildes绑定到Set,您应该在该属性上添加注释

To bind fildes to Set you should put annotations on this property

public class Client  implements java.io.Serializable {

  @Element(value = Login.class)
  @Key(value = Long.class)
  @KeyProperty(value = "id") 
  @CreateIfNull(value = true)
  private Set logins = new HashSet(0);
  //getter and setter

  //now you need a property for login id, it should be initialized before JSP is populated
  private Long loginId;
  //getter and setter
}

现在绑定到JSP的字段更改为

now binding to the fields of the JSP change to

<s:textfield name="logins(%{loginId}).userName" id="userName"/>

与绑定到集合的其他字段相同.

the same for other fields that are bound to a set.

如果您正在使用iterator标记对集合进行迭代,并且将Login的实例推入了值堆栈的顶部,则可以获取其id而不是使用loginId.

If you are using iterator tag to iterate through a set and you have an instance of Login pushed on top of the value stack then you can get its id instead of using loginId.

这篇关于将值从jsp传递给Action for java.util.Set的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆