小编Gar*_*vis的帖子

Grails验证列表对象

我试图获取grails来验证对象列表的内容,如果我首先显示代码可能会更容易:

class Item {
  Contact recipient = new Contact()
  List extraRecipients = [] 

  static hasMany = [
          extraRecipients:Contact
  ]

  static constraints = {}

  static embedded = ['recipient']
}

class Contact {
  String name
  String email

  static constraints = {
    name(blank:false)
    email(email:true, blank:false)
  }
}    
Run Code Online (Sandbox Code Playgroud)

基本上我所拥有的是一个必需的联系人('收件人'),这很好用:

def i = new Item()
// will be false
assert !i.validate() 
// will contain a error for 'recipient.name' and 'recipient.email'
i.errors 
Run Code Online (Sandbox Code Playgroud)

我还要做的是验证Contact'extraRecipients'中的任何附加对象,以便:

def i = new Item()
i.recipient = new Contact(name:'a name',email:'email@example.com')

// …
Run Code Online (Sandbox Code Playgroud)

grails grails-orm grails-validation

4
推荐指数
1
解决办法
6224
查看次数

如何在ActionScript 3中创建数组的浅表副本

var a:Array = ["a","b","c"];

var b:Array;

/* insert code here to copy 'a' and assign it to 'b'*/
Run Code Online (Sandbox Code Playgroud)

apache-flex flex3 actionscript-3

4
推荐指数
2
解决办法
8568
查看次数

Spring + hibernate懒惰抓取

我有org.hibernate.LazyInitializationException的问题:懒得初始化一个角色集合.

如何使用gwt + spring + hibernate实现延迟抓取?

这是我的appContext:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="   http://www.springframework.org/schema/beans    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-3.0.xsd   http://www.springframework.org/schema/tx   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd   http://www.springframework.org/schema/aop    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory">
            <ref local="sessionFactory"/>
        </property>
    </bean>
    <context:annotation-config/>
    <context:component-scan base-package="com.yeah.server.*"/>
    <aop:aspectj-autoproxy/>
    <!--Mysql database connection info-->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://192.168.1.4:3306/YeaH"/>
        <property name="username" value="root"/>
        <property name="password" value=""/>
    </bean>
    <!-- Hibernate -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingResources">
            <list>
                <value>com/yeah/shared/model/User.hbm.xml</value>
                <value>com/yeah/shared/model/Comment.hbm.xml</value>
                <value>com/yeah/shared/model/Album.hbm.xml</value>
                <value>com/yeah/shared/model/Picture.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop …
Run Code Online (Sandbox Code Playgroud)

gwt spring hibernate lazy-evaluation

4
推荐指数
1
解决办法
1935
查看次数

如何在Perl中没有中间变量的情况下提取拆分数组的元素?

给定字符串Wibble eq wobble myhost.example.com我希望能够提取最后一个元素.

我目前的努力是:

my @parts = split( /\s+/, "Wibble eq wobble myhost.example.com");
my $host = $parts[-1];
print "$host\n";
Run Code Online (Sandbox Code Playgroud)

如何在中间@parts阵列中执行此操作?

perl

2
推荐指数
1
解决办法
243
查看次数

ActionListener问题

我的actionListener有问题.在我点击按钮之前,似乎actionListener会自动运行?在单击按钮之前,控制台中出现"这不应出现在控制台中的控制台之前"....这很奇怪.

.... 
button1.addActionListener(this); 
button2.addActionListener(this);
....
public void actionPerformed(ActionEvent e) {

   System.out.println("This should not appear in the console before button click");

   if (e.getSource()==button1)
      System.out.println ("answer1");

   else if (e.getSource()==button2)
      System.out.println ("answer2");
   .....
}
Run Code Online (Sandbox Code Playgroud)

java swing

1
推荐指数
1
解决办法
564
查看次数

Java继承问题

我有类似于这个设置:

public class Base {
    public String getApple() {return "base apple"};
}

public class Extended extends Base{
    public String getApple() {return "extended apple"};
}
Run Code Online (Sandbox Code Playgroud)

代码中的其他地方我有这个:

{
    Base b = info.getForm();

    if (b instanceof Extended){
        b = (Extended) b;
    }

    System.out.println(b.getApple()); // returns "base apple" even when if clause is true why??

}
Run Code Online (Sandbox Code Playgroud)

我该如何做到这一点?

java inheritance

1
推荐指数
1
解决办法
1132
查看次数

重置CSS背景图片

我正在尝试使用以下JQUERY创建一个手风琴类型菜单:

function initMenu() {
    $('#menu ul').hide();
        $('#menu li a').click(
            function() {
                $(this).next().slideToggle('normal');
                $(this).css("background", "url(customnav_selected.png) top right");
            }
        );
}
$(document).ready(function() {initMenu();});
Run Code Online (Sandbox Code Playgroud)

这是有用的,当我点击它扩展的菜单链接和菜单标题背景更改.

但是,当我再次单击它以折叠菜单时,我希望它能够更改回来.

有人可以帮忙吗?

css jquery

1
推荐指数
1
解决办法
3396
查看次数

如何在android中释放内存

我需要释放下面的指针,如何释放画布,油漆和矩阵的内存?

 Canvas pcanvas = new Canvas();

 Paint mPaint = new Paint(); 

 Matrix matrix = new Matrix(); 
Run Code Online (Sandbox Code Playgroud)

提前致谢.

android memory-leaks memory-management out-of-memory

0
推荐指数
1
解决办法
1万
查看次数