开发者

Form values from the create view don't get passed to the save view

This question is an extension of / is similar too the question I asked here. The specific issue I was having in that question was solved, but I am having another very similar issue.

The issue is that the "Cargo Destination" and "Cargo Source" values entered in the create view do not show up in the save view. For instance, when a user forgets to enter a necessary bit of information in the create view and presses the "Create" button, the values the user entered should show up in the save view. All fields except the "Cargo Destination" and "Cargo Scource" show up in the save view when this scenario occurs.

When I put a println statement in my save controller, I can see that the parameters in question did indeed make it to the save controller from the create view.

The two fields in question are chained to other fields and populated by an AJAX that goes to a closure in the Load controller. I believe this closure is where my problem is, in the render statement:

def getAccountUserCargoDestinations = {
    if(params.id == ""){
        render g.select(name: 'cargoDestination.id')
        return
    }
    def 开发者_运维问答user = Account.find("from Account as account where account.id=:id", [id:Long.valueOf(params.id)]).user
    def addresses = Address.find("from Address as addresses where addresses.user=:user and addresses.cargoDestination=true", [user:user])
    render g.select(optionKey: 'id', from: addresses,  name: 'cargoDestination.id')
}

If that is not where the problem is, then it is probably in the corresponding field of the create view itself:

<g:select name="cargoDestination.id" optionKey="id" value="${loadInstance?.cargoDestination?.id}" />

Two more things:

1.) Grails is not giving me any errors

2.) A cargoDestination and a cargoSource are both instances of the Address class which I made.

Any help would be appreciated.

UPDATE:

Continuing to look for a solution I noticed several interesting things. First I put the following code in my create view (which is rendered by the create closure in the Load controller, and re-rendered by the save closure in the Load controller IF the user leaves any fields blank):

  <g:if test="${loadInstance?.cargoDestination?.id != null}">
    ${loadInstance?.cargoDestination}
  </g:if>

By doing this I can see that the parameter is making it all the way to the create view when it is called by the save closure. I guess I could use <g:if> tags to get the desired results, but that just seems messy, and I doubt that is the "correct" way to solve this problem. I also wrapped my AJAX in a similartag to make sure it was not changing the field value when thesaveclosure rendered thecreateview, and I can confirm that the AJAX is indeed not changing the field value. Other than the AJAX, the only thing different about my problem fields is that I do not have afromattribute in their corresponding` tags (as can be seen by the code I posted originally in this question). I know the solution is something simple... What am I missing here?


The two fields in question are chained to other fields and populated by an AJAX that goes to a closure in the Load controller.

hm. Is the object saved in between? It reads as if

  • the data is sent to the save controller which does not save because there are missing fields
  • the save controller displays the save view and println's the field (which are available to the controller)
  • the view invokes the load controller which tries to retrieve two fields from an object which isn't saved yet. There is no connection to the intermediate request data of the save controller.

if it's not this problem, I guess you'll have to post more code in order to get your problem analyzed.

hm. just taken a look at your other question. I see no chance for the Ajax load controller to get the data since the save controller did not persist the data to the database.

Why don't you output these values directly through the save view?


Finally figured it out through process of elimination, but now that I see the solution it should have been very evident.

All I needed to do was add the from attribute to the affected <g:select> tags, like so:

<g:select from="${loadInstance?.cargoDestination}" name="cargoDestination.id" optionKey="id" value="${loadInstance?.cargoDestination?.id}" />

Works exactly as expected now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜