現在ログインしているユーザー(組織)にカテゴリとサブカテゴリを追加しようとしています。ユーザー (組織) にカテゴリを追加できますが、サブカテゴリを追加できません。
協会:
Organization hasMany = [follows: SubCategory]
Category hasMany = [ subCategories: SubCategory ]
SubCategory belongsTo = [ category: Category]
カテゴリとサブカテゴリの構造:
Main Category
Sub Category
Sub Category
Sub Category
Main Category
Sub Category
Sub Category
Sub Category
Main Category
Sub Category
Sub Category
Sub Category
注: メイン カテゴリを選択すると、このカテゴリに関連するサブカテゴリのリストが表示されるので、それらのサブカテゴリを選択して組織に追加します。
Organization.groovy
class Organization extends Party{
String orgName
Person contact
String orgSize
boolean isVendor = false
static hasMany = [follows: SubCategory]
static constraints = {
orgName blank: false
orgSize blank: false
}
}
Category.groovy
class Category {
String name
String description
static constraints = {
subCategories nullable:true
}
static hasMany = [ subCategories: SubCategory ]
}
SubCategory.groovy
class SubCategory {
String name
static hasMany = [requirements: Enquiry]
static belongsTo = [ category: Category]
static constraints = {
requirements nullable:true
}
}
OrganizationController.groovy
class OrganizationController {
def saltSource
def userCache
def springSecurityService
def mailService
def messageSource
def organizationService
def subscriberService
static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
def index() {
redirect(action: "list", params: params)
}
def list() {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
[organizationInstanceList: Organization.list(params), organizationInstanceTotal: Organization.count()]
}
def profile() {
Subscriber loggedinSubscriber = subscriberService.getLoggedinSubscriber()
Party organization = loggedinSubscriber?.customer?.party
Party person = organization?.contact
[orgInstance: organization, personInstance: person]
}
def update() {
def orgInstance = organizationService.getOrganization(params.id)
orgInstance.properties = params
orgInstance?.contact?.properties = params
println params
try {
organizationService.updateOrganization(orgInstance)
}
catch ( CustomValidationException e){
flash.message = e.sMessage
}
catch (ServiceException s ) {
flash.message = s.message
}
render(view: "_org", model: [orgInstance: orgInstance])
}
def follow() {
Subscriber loggedinSubscriber = subscriberService.getLoggedinSubscriber()
Party organization = loggedinSubscriber?.customer?.party
def subparams = params.subcategories
println subparams
def marketInstance = Category.get(params.abc)
def subMarket = getsubCategories(params.subcategories)
def follower = new Follower()
follower.followedBy = organization
follower.category = marketInstance
follower.subCategory = subMarket
follower.save(failOnError: true);
flash.msg = "Okay. This market is now on your watchlist."
redirect (action: "profile")
}
}
上記のコントローラーのフォローアクションは、組織(ユーザー)にカテゴリとサブカテゴリを追加する責任があります。次のコードで試しました
def subMarket = getsubCategories(params.subcategories) follower.subCategory = subMarket
フォローアクションではあるが取得中
No signature of method: com.vproc.member.OrganizationController.getsubCategories() is applicable for argument types: ([Ljava.lang.String;) values: [[2, 1, 3]] error.
subCategory.gsp
<g:form controller="organization" params="[temp : marketInstance?.id]" action="follow" method="post">
<g:hiddenField name="id" name= "abc" value="${marketInstance?.id}" />
<g:hiddenField name="id" value="${subcategory?.id}" />
<div style="margin-left:200px">
<input type="button" class="button-inner" id="check1" value="Check All" />
<input type="hidden" id="isChkd" value="true" />
<g:each var="subcategory" in="${subCategroyInstanceList}">
<div>
<g:checkBox class="cb1-element" name="subcategories" value="${subcategory.id}"/>
<label for="subcategories"> ${subcategory.name}</label>
</div>
</g:each>
<button class="btn btn-inverse">Submit</button>
</div>
</g:form>
問題: 選択したサブカテゴリを取得し、フォロー アクションを使用してそれらを組織に追加する方法。