-
1. Re: multiple component instances in one page
soudmaijer Feb 6, 2007 9:40 AM (in response to soudmaijer)I forgot to mention, when I remove the line:
<h:inputText value="#{helloworld.dumbUser.name}"/>
everything works fine. -
2. Re: multiple component instances in one page
sbublava Feb 6, 2007 9:44 AM (in response to soudmaijer)Well dumbUser is null, so the value you enter cannot be assigned to dumbUser.name.
Don't you see a NullPointerException in the log file? -
3. Re: multiple component instances in one page
pmuir Feb 6, 2007 9:45 AM (in response to soudmaijer)You've forgotten to create an instance of DumbUser in Helloworld
-
4. Re: multiple component instances in one page
fernando_jmt Feb 6, 2007 9:47 AM (in response to soudmaijer)
Because your attribute DumbUser is a plain class (not injected), you sould initialize your class manually,private DumbUser dumbUser = new DumbUser();
Try above, I think it will work. -
5. Re: multiple component instances in one page
soudmaijer Feb 6, 2007 9:47 AM (in response to soudmaijer)"sbublava" wrote:
Well dumbUser is null, so the value you enter cannot be assigned to dumbUser.name.
Don't you see a NullPointerException in the log file?
OMG, i`m an idiot, been working to long today I guess...
Indeed this was the problem, but no nullpointers in the log (strange).
Thnx :) -
6. Re: multiple component instances in one page
sbublava Feb 6, 2007 9:51 AM (in response to soudmaijer)"soudmaijer" wrote:
Indeed this was the problem, but no nullpointers in the log (strange).
Then it's probably a regular error message. Try adding:<h:messages />
-
7. Re: multiple component instances in one page
soudmaijer Feb 6, 2007 9:59 AM (in response to soudmaijer)Alright,
this works, but now to another problem. Lets say my simple object looks like this:@Name("dumbUser") public class DumbUser { private String name; public DumbUser() { } public String getName() { return name; } public void setName(String name) { this.name = name; } }
and my helloworld component looks like this:@Name("helloworld") public class Helloworld { @In("dumbUser") private DumbUser dumbUser; public String sayHello() { System.out.println("sayHello: "+ dumbUser.getName()); return "success"; } }
my jsf like this:<h:form> <div> <h:inputText value="#{dumbUser.name}"></h:inputText> <h:commandButton type="submit" value="sayHello!" action="#{helloworld.sayHello}"/> </div> </h:form>
This all works fine, but if I want to add another dumbUser to the Helloworld component, something like this:@Name("helloworld") public class Helloworld { @In("dumbUser") private DumbUser dumbUser1; @In("dumbUser") private DumbUser dumbUser2; public String sayHello() { System.out.println("sayHello: "+ dumbUser1.getName()); System.out.println("sayHello: "+ dumbUser2.getName()); return "success"; } }
Is this possible? How do I access them from the JSF? Something like this?<h:form> <div> <h:inputText value="#{dumbUser1.name}"></h:inputText> <h:inputText value="#{dumbUser2.name}"></h:inputText> <h:commandButton type="submit" value="sayHello!" action="#{helloworld.sayHello}"/> </div> </h:form>
This doesnt work... but i`ve tried many variations... is it possible? -
8. Re: multiple component instances in one page
sbublava Feb 6, 2007 10:12 AM (in response to soudmaijer)@Name("helloworld") public class Helloworld { @In("dumbUser") private DumbUser dumbUser1; @In("dumbUser") private DumbUser dumbUser2; }
I believe the second one should be @In("dumbUser2"). -
9. Re: multiple component instances in one page
fernando_jmt Feb 6, 2007 10:12 AM (in response to soudmaijer)You can try defining a new different role for the second DumbUser.
First you need to modify your dumbClass like this (adding a new role):@Name("dumbUser") @Role(name="dumbUser1") public class DumbUser { private String name; public DumbUser() { } public String getName() { return name; } public void setName(String name) { this.name = name; } }
Then your hello world component:@Name("helloworld") public class Helloworld { @In("dumbUser") private DumbUser dumbUser1; @In("dumbUser1") private DumbUser dumbUser2; public String sayHello() { System.out.println("sayHello: "+ dumbUser1.getName()); System.out.println("sayHello: "+ dumbUser2.getName()); return "success"; } }
Then the JSF should looks like:<h:form> <div> <h:inputText value="#{dumbUser.name}"></h:inputText> <h:inputText value="#{dumbUser1.name}"></h:inputText> <h:commandButton type="submit" value="sayHello!" action="#{helloworld.sayHello}"/> </div> </h:form>
-
10. Re: multiple component instances in one page
soudmaijer Feb 6, 2007 10:36 AM (in response to soudmaijer)"sbublava" wrote:
@Name("helloworld") public class Helloworld { @In("dumbUser") private DumbUser dumbUser1; @In("dumbUser") private DumbUser dumbUser2; }
I believe the second one should be @In("dumbUser2").
Tried this, but that doesn`t work.... (thanks for the suggestion) -
11. Re: multiple component instances in one page
sbublava Feb 6, 2007 10:39 AM (in response to soudmaijer)Do you need exactly two DumbUser instances or many of them?
-
12. Re: multiple component instances in one page
soudmaijer Feb 6, 2007 10:45 AM (in response to soudmaijer)"fernando_jmt" wrote:
You can try defining a new different role for the second DumbUser.
Cool, this works!
So it means, that if you want to have multiple occurences of an component in one page, you can`t do this without modifying the component (This surprises me a bit).
Thnx all for the responses. -
13. Re: multiple component instances in one page
soudmaijer Feb 6, 2007 10:47 AM (in response to soudmaijer)"sbublava" wrote:
Do you need exactly two DumbUser instances or many of them?
I was just testing around a bit. If I need multiple instances I would probably store it in a collection.
But in this particular case I was trying to let seam inject two instances of an component for me. -
14. Re: multiple component instances in one page
norman.richards Feb 6, 2007 2:35 PM (in response to soudmaijer)You can also declare the second named instance in XML. It has to be declared somewhere.