0

I really need help with Spring MVC(no webflows), concept of passing data to front end

asked 2011-04-23 10:02:06 +0800

blacksensei gravatar image blacksensei
234 2

Hello Experts,

I really need you help to get through this.I'm using zkspring with spring MVC , routing with `@RequestMapping` and ZKResourceViewResolver, are all working fine. a have a controller which consumes a webservice which returns a list of objects then. here is a snippet

 @RequestMapping("/accounts/personal/list")
    public String list(Model model) {

        try { // Call Web Service Operation

            ArrayOfIAccount result = port.getPersonalAccounts(null, 0, 20);

//            List<IAccount> accounts = result.getIAccount();
            model.addAttribute("result", result);
            model.addAttribute("myvar", "joseph");
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }

        return "accountslist";
    }

the accountslist.zul looks like this

<label id="lblTest" value="${myvar}" />
        <div>
            <listbox model="${c:l('result.getIAccount()')}" id="lstAccount" multiple="true">
                <listhead>
                    <listheader label="Account Name" />
                    <listheader label="Account Type" />
                    <listheader label="Mobile Phone" />
                </listhead>
<!-- 
here are the getters for the account object
         re.getAccountName();
         re.getMobilePhone();
         re.getAccountType();
-->
                <listitem forEach="${c:l('result.getIAccount()')}">
                    <listcell label="${each.accountName}" />
                    <listcell label="${each.accountType}" />
                    <listcell label="${each.mobilePhone}" />
                </listitem>
            </listbox>
        </div>

with this, the listbox is empty, and there is no error.
What is weird is that the lable of id lblTest is showing the joseph that i set in the controller with the name "myvar" and that without the prefix c.
i removed then the prefix part and had `${result.getIAccount}` but i got this error

rg.zkoss.xel.XelException: Unable to find a value for "getIAccount" in object of class com.myblablabla


So i thought there wasn't data returned, and i did the same code but then using the GenericForwardComposer with the `@` and it worked.
so i'm really confused that's the confusing i expressed in this thread here which is still ignored till today.

So really help me get out of here. thanks for reading and for helping out :-)

delete flag offensive retag edit

13 Replies

Sort by ยป oldest newest

answered 2011-04-23 11:27:51 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

did you try to change this:

<listitem forEach="${c:l('result.getIAccount()')}">

to this:

<listitem forEach="${result.iAccount}">

Seems to me the c:l retrieves a label...from the doc:
Returns the label of the given key defined in the internationalization labels.

Your "myvar" experiment wasn't wrapped by c:l():

<label id="lblTest" value="${myvar}" />

link publish delete flag offensive edit

answered 2011-04-23 11:38:34 +0800

blacksensei gravatar image blacksensei
234 2

hello caclark

thank you so much for replying .

yes "myvar" wasn't wrapped with the c:l() but yet it's worked with the
${result.iAccount} it gives this error "failed; nested exception is org.zkoss.xel.XelException: Unable to find a value for "iAccount" in object of class com.my.bla.bla.class" :(

thanks

link publish delete flag offensive edit

answered 2011-04-23 14:14:00 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-04-23 14:14:43 +0800

the same as Cary mentioned is in you listbox model too.

<listbox model="${c:l('result.getIAccount()')}"

link publish delete flag offensive edit

answered 2011-04-23 14:46:40 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

Just double checking here, but does your com.my.bla.bla.class have a getIAccount() method on it? Under the hood, EL and databinding are just calling getters...

link publish delete flag offensive edit

answered 2011-04-23 17:28:35 +0800

blacksensei gravatar image blacksensei
234 2

@Cary yes there is a getIAccount() which returns a list of IAccount objects, what i used with the GenericForwardComposer
@TerryTornado, i'm afraid i didn't get what you meant.

Thanks for replying

link publish delete flag offensive edit

answered 2011-04-23 18:29:03 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

He was saying that just as I pointed out for the listitem, the same problem exists for the listbox:

<listbox model="${c:l('result.getIAccount()')}" id="lstAccount" multiple="true">
...
<listitem forEach="${c:l('result.getIAccount()')}">

I failed to notice that. And it leads me to ask: How can you do that? It doesn't make sense to have that on both the listbox and listitem. Seems to be mixing metaphors...

I'd take the model attribute off the listbox and see what happens. I'm not a big user of rendering phase collections, so this is a bit of a guess.

link publish delete flag offensive edit

answered 2011-04-24 06:05:22 +0800

blacksensei gravatar image blacksensei
234 2

Hello all !!

thanks for replying to this thread. i think i got it working.

first of all @cary made me notice the double assignment.

  <window self="@{define(content)}" id="pAccountWin">
        <div>
            <listbox id="lstAccount" multiple="true">
                <listhead>
                    ........
                </listhead>
                <listitem forEach="${result}">
                    <listcell label="${each.accountName}" />
                      ....
                 </listitem>
            </listbox>


but this time instead of passing the result straight from the ws call i return the list itself as in

//changed this 
            model.addAttribute("result", result);
// to this 
            model.addAttribute("result", result.getIAccount());


Now a question to experienced guys who use zk on a daily basis,
Question 1 : with this(Spring MVC) an ajax call would mean creating the jquery method to call the backend?
Question 2: i'm really tempted to use Spring MVC for navigation perpose only and at the same time use GenericForwardComposer to ease up things.
So the big question is: is it a good thing to do? if not can you point me to the right direction.

thanks for reading and helping out.Special thanks to Cary :)

link publish delete flag offensive edit

answered 2011-04-24 08:50:25 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

YW, but Stephan was the first one to notice the double assignment.

As for mixing ZK GFC's and Spring MVC Controllers...personally, I wouldn't do it. I've used Spring MVC in the past and it's all well and good, but I think you'll end up banging your head on the wall trying to keep things working like you want.

link publish delete flag offensive edit

answered 2011-04-24 10:50:42 +0800

blacksensei gravatar image blacksensei
234 2

Hello !!

Special thanks to Stephan (terrytornado ?) too. now what's the way forward? what do you suggest? when you used Spring MVC how to you manage behaviors, and event handling in the serer side,
since the zk prefered way is to handle business logic/event handling in the server side. can you point me to any resources?

thanks for everything.

link publish delete flag offensive edit

answered 2011-04-24 13:16:15 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

I don't know spring mvc, but in my case why not use zk controller when using zk as frontend. Because all zk gui components have java component on the server side too. So i find it's absolute normal to use the same framework for both gui comps and the controlling of them.

In my case and most of the other zk users spring manage the call and the lifetime of the zk controllers.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-04-23 10:02:06 +0800

Seen: 390 times

Last updated: Apr 25 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More